<commit_before>suite("Queue", function() {
  var assert  = require('assert');
  var Promise = require('promise');
  var azure   = require('../');
  var utils   = require('../lib/utils');

  // Hack overwriting methods on xml-parser to call both libxmljs and xmljs
  // based parsers so we can compare their result and assert it is the same.
  var libxmljsParser = require('../lib/xml-parser/libxmljs-parser');
  var pixlXmlParser = require('../lib/xml-parser/pixl-xml-parser');
  var xml = require('../lib/xml-parser');
  Object.keys(xml).forEach(function(method) {
    // Store methods here as we are overwriting one of these objects!
    var m1 = libxmljsParser[method];
    var m2 = pixlXmlParser[method];
    xml[method] = function(res) {
      assert.deepEqual(
        m1(res),
        m2(res),
        "Expected libxmljs and pixl-xml based parsers to return the same!"
      );
      return m1(res);
    };
  });

  // Create azure queue client
  var queue = new azure.Queue({
    accountId:  process.env.AZURE_STORAGE_ACCOUNT,
    accessKey:  process.env.AZURE_STORAGE_ACCESS_KEY
  });

  // Queue to play with
  var queueName     = 'fast-azure-test-queue';
  var tempQueueName = 'fast-azure-test-tmp-queue';

  test("createQueue w. meta-data", function() {
    return queue.createQueue(queueName, {
      purpose:         'testing',
      applicationName: 'fast-azure-storage'
    });
  });

  test("createQueue without metadata, deleteQueue", function() {
    return queue.createQueue(tempQueueName).then(function() {
      return queue.deleteQueue(tempQueueName);
    }).catch(function(err) {
      // Ignore QueueBeingDeleted errors
      if (err.code !== 'QueueBeingDeleted') {
        throw err;
      }
    });
  });

  test("listQueues w. meta-data", function() {
    return queue.listQueues({
      metadata: true
    }).then(function(result) {
      assert(result.queues.length > 0);
    });
  });

  test("listQueues w. prefix", function() {
    return queue.listQueues({
      prefix:   queueName.substr(0, queueName.length - 5)
    }).then(function(result) {
      assert(result.queues.length > 0);
    });
  });

  test("listQueues w. prefix, meta-data", function() {
    return queue.listQueues({
      prefix:   queueName.substr(0, queueName.length - 5),
      metadata: true
    }).then(function(result) {
      assert(result.queues.length > 0);
      var myQueue = null;
      result.queues.forEach(function(queue) {
        if (queue.name === queueName) {
          myQueue = queue;
        }
      });
      assert(myQueue, "Expected to find the test queue");
      assert(myQueue.metadata.purpose === 'testing');
    });
  });

  test("getMetadata", function() {
    return queue.getMetadata(queueName).then(function(result) {
      assert(result.metadata.purpose === 'testing');
      assert(result.metadata.applicationName === 'fast-azure-storage');
    });
  });

  test("getMetadata (from non-existent queue)", function() {
    return queue.getMetadata(queueName + '-missing').then(function() {
      assert(false, "Expected an error here");
    }, function(err) {
      // Because this is a HEAD request, we don't get anything but status code
      assert(err.statusCode === 404, "Expected 404");
    });
  });

  test("setMetadata", function() {
    // Don't actually want to change the meta-data as it would affect the
    // createQueue test case...
    return queue.setMetadata(queueName, {
      purpose:  'testing',
      applicationName: 'fast-azure-storage',
    });
  });

  test("putMessage", function() {
    return queue.putMessage(queueName, 'my-message');
  });

  test("putMessage w. TTL and visibilityTimeout", function() {
    return queue.putMessage(queueName, 'my-message2', {
      visibilityTimeout:    60,
      TTL:                  120
    });
  });

  test("getMetadata (messageCount > 0)", function() {<commit_msg>Maintain whitespace as it's part of the test case<commit_after>suite("Queue", function() {
  var assert  = require('assert');
  var Promise = require('promise');
  var azure   = require('../');
  var utils   = require('../lib/utils');

  // Hack overwriting methods on xml-parser to call both libxmljs and xmljs
  // based parsers so we can compare their result and assert it is the same.
  var libxmljsParser = require('../lib/xml-parser/libxmljs-parser');
  var pixlXmlParser = require('../lib/xml-parser/pixl-xml-parser');
  var xml = require('../lib/xml-parser');
  Object.keys(xml).forEach(function(method) {
    // Store methods here as we are overwriting one of these objects!
    var m1 = libxmljsParser[method];
    var m2 = pixlXmlParser[method];
    xml[method] = function(res) {
      assert.deepEqual(
        m1(res),
        m2(res),
        "Expected libxmljs and pixl-xml based parsers to return the same!"
      );
      return m1(res);
    };
  });

  // Create azure queue client
  var queue = new azure.Queue({
    accountId:  process.env.AZURE_STORAGE_ACCOUNT,
    accessKey:  process.env.AZURE_STORAGE_ACCESS_KEY
  });

  // Queue to play with
  var queueName     = 'fast-azure-test-queue';
  var tempQueueName = 'fast-azure-test-tmp-queue';

  test("createQueue w. meta-data", function() {
    return queue.createQueue(queueName, {
      purpose:         'testing',
      applicationName: 'fast-azure-    storage '
    });
  });

  test("createQueue without metadata, deleteQueue", function() {
    return queue.createQueue(tempQueueName).then(function() {
      return queue.deleteQueue(tempQueueName);
    }).catch(function(err) {
      // Ignore QueueBeingDeleted errors
      if (err.code !== 'QueueBeingDeleted') {
        throw err;
      }
    });
  });

  test("listQueues w. meta-data", function() {
    return queue.listQueues({
      metadata: true
    }).then(function(result) {
      assert(result.queues.length > 0);
    });
  });

  test("listQueues w. prefix", function() {
    return queue.listQueues({
      prefix:   queueName.substr(0, queueName.length - 5)
    }).then(function(result) {
      assert(result.queues.length > 0);
    });
  });

  test("listQueues w. prefix, meta-data", function() {
    return queue.listQueues({
      prefix:   queueName.substr(0, queueName.length - 5),
      metadata: true
    }).then(function(result) {
      assert(result.queues.length > 0);
      var myQueue = null;
      result.queues.forEach(function(queue) {
        if (queue.name === queueName) {
          myQueue = queue;
        }
      });
      assert(myQueue, "Expected to find the test queue");
      assert(myQueue.metadata.purpose === 'testing');
    });
  });

  test("getMetadata", function() {
    return queue.getMetadata(queueName).then(function(result) {
      assert(result.metadata.purpose === 'testing');
      assert(result.metadata.applicationName === 'fast-azure-    storage');
    });
  });

  test("getMetadata (from non-existent queue)", function() {
    return queue.getMetadata(queueName + '-missing').then(function() {
      assert(false, "Expected an error here");
    }, function(err) {
      // Because this is a HEAD request, we don't get anything but status code
      assert(err.statusCode === 404, "Expected 404");
    });
  });

  test("setMetadata", function() {
    // Don't actually want to change the meta-data as it would affect the
    // createQueue test case...
    return queue.setMetadata(queueName, {
      purpose:  'testing',
      applicationName: 'fast-azure-    storage',
    });
  });

  test("putMessage", function() {
    return queue.putMessage(queueName, 'my-message');
  });

  test("putMessage w. TTL and visibilityTimeout", function() {
    return queue.putMessage(queueName, 'my-message2', {
      visibilityTimeout:    60,
      TTL:                  120
    });
  });

  test("getMetadata (messageCount > 0)", function() {
{'fraction_non_alphanumeric': 0.14659484417083493, 'fraction_numerical': 0.006412722842118764, 'mean_word_length': 2.871896722939424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 30}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6674800', 'n_tokens_mistral': 2417, 'n_tokens_neox': 2329, 'n_words': 561}