<commit_before>/* eslint-env mocha */
var influx = require('./')
var assert = require('assert')

describe('InfluxDB', function () {
  var client
  var dbClient
  var failClient
  var failoverClient

  var info = {
    server: {
      host: 'localhost',
      port: 8086,
      username: 'root',
      password: '<PASSWORD>',
      timePrecision: 'ms'
    },
    db: {
      name: 'test_db',
      username: 'johnsmith',
      password: '<PASSWORD>',
      retentionPolicy: 'testrp'
    },
    series: {
      name: 'response_time',
      strName: 'string_test'
    }
  }

  describe('#InfluxDB', function () {
    it('should exist as a function (class)', function () {
      assert(typeof influx.InfluxDB === 'function')
    })
  })

  describe('create client', function () {
    it('should create an instance without error', function () {
      client = influx({host: info.server.host, port: info.server.port, username: info.server.username, password: <PASSWORD>, database: info.db.name, retentionPolicy: info.db.retentionPolicy})
      dbClient = influx({host: info.server.host, port: info.server.port, username: info.server.username, password: <PASSWORD>, database: info.db.name})
      failClient = influx({host: info.server.host, port: 6543, username: info.server.username, password: <PASSWORD>, database: info.db.name})
      failoverClient = influx({hosts: [
          {host: '192.168.1.1'},
          {host: '192.168.1.2'},
          {host: '192.168.1.3'},
          {host: '192.168.1.4'},
          {host: info.server.host, port: info.server.port}
      ], username: info.server.username, passwort: <PASSWORD>, database: info.db.name})

      assert(client instanceof influx.InfluxDB)
    })
  })

  describe('#setRequestTimeout', function () {
    it('should set the default request timeout value', function () {
      var timeout = failoverClient.setRequestTimeout(5000)
      assert.equal(timeout, 5000)
    })
  })

  describe('#setFailoverTimeout', function () {
    it('should set the default request timeout value', function () {
      var timeout = failoverClient.setFailoverTimeout(2000)
      assert.equal(timeout, 2000)
    })
  })

  describe('#url', function () {
    it('should build a properly formatted url', function () {
      var url = client.url('query', { db: info.db.name, rp: info.db.retentionPolicy, precision: info.server.timePrecision })
      assert.equal(url, /* 'http://'+info.server.host+':8086/' + */ 'query?u=' + info.server.username + '&p=' + info.server.password + '&db=' + info.db.name + '&rp=' + info.db.retentionPolicy + '&precision=' + info.server.timePrecision)
    })

    it('should build a properly formatted url', function () {
      var url = client.url('query')
      assert.equal(url, /* 'http://'+info.server.host+':8086/' + */ 'query?u=' + info.server.username + '&p=' + info.server.password + '&precision=' + info.server.timePrecision + '&db=' + info.db.name + '&rp=' + info.db.retentionPolicy)
    })

  })
  
  describe('#_createKeyTagString', function () {
    it('should build a properly formatted string', function () {
      var str = client._createKeyTagString({tag_1: "value", tag2: "value value", tag3: "value,value"})
      assert.equal(str, 'tag_1=value,tag2=value\ value,tag3=value\,value')
    })
  })

  describe('#_createKeyValueString', function () {
    it('should build a properly formatted string', function () {
      var str = client._createKeyValueString({a: 1, b: 2})
      assert.equal(str, 'a=1,b=2')
    })
  })
<commit_msg>Add createKeyTagString test escapes<commit_after>/* eslint-env mocha */
var influx = require('./')
var assert = require('assert')

describe('InfluxDB', function () {
  var client
  var dbClient
  var failClient
  var failoverClient

  var info = {
    server: {
      host: 'localhost',
      port: 8086,
      username: 'root',
      password: '<PASSWORD>',
      timePrecision: 'ms'
    },
    db: {
      name: 'test_db',
      username: 'johnsmith',
      password: '<PASSWORD>',
      retentionPolicy: 'testrp'
    },
    series: {
      name: 'response_time',
      strName: 'string_test'
    }
  }

  describe('#InfluxDB', function () {
    it('should exist as a function (class)', function () {
      assert(typeof influx.InfluxDB === 'function')
    })
  })

  describe('create client', function () {
    it('should create an instance without error', function () {
      client = influx({host: info.server.host, port: info.server.port, username: info.server.username, password: <PASSWORD>, database: info.db.name, retentionPolicy: info.db.retentionPolicy})
      dbClient = influx({host: info.server.host, port: info.server.port, username: info.server.username, password: <PASSWORD>, database: info.db.name})
      failClient = influx({host: info.server.host, port: 6543, username: info.server.username, password: <PASSWORD>, database: info.db.name})
      failoverClient = influx({hosts: [
          {host: '192.168.1.1'},
          {host: '192.168.1.2'},
          {host: '192.168.1.3'},
          {host: '192.168.1.4'},
          {host: info.server.host, port: info.server.port}
      ], username: info.server.username, passwort: info.server.password, database: info.db.name})

      assert(client instanceof influx.InfluxDB)
    })
  })

  describe('#setRequestTimeout', function () {
    it('should set the default request timeout value', function () {
      var timeout = failoverClient.setRequestTimeout(5000)
      assert.equal(timeout, 5000)
    })
  })

  describe('#setFailoverTimeout', function () {
    it('should set the default request timeout value', function () {
      var timeout = failoverClient.setFailoverTimeout(2000)
      assert.equal(timeout, 2000)
    })
  })

  describe('#url', function () {
    it('should build a properly formatted url', function () {
      var url = client.url('query', { db: info.db.name, rp: info.db.retentionPolicy, precision: info.server.timePrecision })
      assert.equal(url, /* 'http://'+info.server.host+':8086/' + */ 'query?u=' + info.server.username + '&p=' + info.server.password + '&db=' + info.db.name + '&rp=' + info.db.retentionPolicy + '&precision=' + info.server.timePrecision)
    })

    it('should build a properly formatted url', function () {
      var url = client.url('query')
      assert.equal(url, /* 'http://'+info.server.host+':8086/' + */ 'query?u=' + info.server.username + '&p=' + info.server.password + '&precision=' + info.server.timePrecision + '&db=' + info.db.name + '&rp=' + info.db.retentionPolicy)
    })

  })
  
  describe('#_createKeyTagString', function () {
    it('should build a properly formatted string', function () {
      var str = client._createKeyTagString({tag_1: "value", tag2: "value value", tag3: "value,value"})
      assert.equal(str, 'tag_1=value,tag2=value\\ value,tag3=value\\,value')
    })
  })

  describe('#_createKeyValueString', function () {
    it('should build a properly formatted string', function () {
      var str = client._createKeyValueString({a: 1, b: 2})
      assert.equal(str, 'a=1,b=2')
    })
  })

{'fraction_non_alphanumeric': 0.16794326241134752, 'fraction_numerical': 0.02099290780141844, 'mean_word_length': 3.2733333333333334, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, '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': '3117801', 'n_tokens_mistral': 2331, 'n_tokens_neox': 2177, 'n_words': 495}