nsolid-graphite
Version:
a daemon that sends N|Solid metrics to graphite
45 lines (36 loc) • 1.61 kB
JavaScript
const test = require('tape')
const normalize = require('../lib/normalize-endpoint')
test('\n# normalize endpoint: passing nothing throws error', function (t) {
t.throws(normalize, /endpoint is required/i, 'throws complaining about missing endpoint')
t.end()
})
test('normalize endpoint: passing endpoint with https protocol only', function (t) {
const res = normalize('https://foo')
t.equal(res, 'https://foo/api/v1/', 'attaches api/v1/ to endpoint')
t.end()
})
test('normalize endpoint: passing endpoint with https protocol and version 2 throws', function (t) {
t.throws(() => normalize('https://foo', 2), /only v1 .+ supported/i, 'throws complaining about missing endpoint')
t.end()
})
test('normalize endpoint: passing endpoint with https protocol and version 1', function (t) {
const res = normalize('https://foo', 1)
t.equal(res, 'https://foo/api/v1/', 'attaches api/v1/ to endpoint')
t.end()
})
test('normalize endpoint: passing endpoint with https protocol and version v1', function (t) {
const res = normalize('https://foo', 'v1')
t.equal(res, 'https://foo/api/v1/', 'attaches api/v1/ to endpoint')
t.end()
})
test('normalize endpoint: passing endpoint without protocol', function (t) {
const res = normalize('foo')
t.equal(res, 'https://foo/api/v1/', 'prefixes https: protocol and attaches api/v1/ to endpoint')
t.end()
})
test('normalize endpoint: passing endpoint with http protocol', function (t) {
const res = normalize('http://foo')
t.equal(res, 'http://foo/api/v1/', 'maintains http: protocol and attaches api/v1/ to endpoint')
t.end()
})