2017-09-21 09:40:18 -05:00
|
|
|
import {describe, it, expect} from 'test/lib/common';
|
2016-09-16 09:50:30 -05:00
|
|
|
|
2016-09-19 08:15:15 -05:00
|
|
|
import {containsVariable, assignModelProperties} from '../variable';
|
2016-09-16 09:50:30 -05:00
|
|
|
|
|
|
|
describe('containsVariable', function() {
|
|
|
|
|
|
|
|
describe('when checking if a string contains a variable', function() {
|
|
|
|
|
|
|
|
it('should find it with $var syntax', function() {
|
|
|
|
var contains = containsVariable('this.$test.filters', 'test');
|
|
|
|
expect(contains).to.be(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not find it if only part matches with $var syntax', function() {
|
2017-02-20 02:31:50 -06:00
|
|
|
var contains = containsVariable('this.$serverDomain.filters', 'server');
|
2016-09-16 09:50:30 -05:00
|
|
|
expect(contains).to.be(false);
|
|
|
|
});
|
|
|
|
|
2017-02-20 02:31:50 -06:00
|
|
|
it('should find it if it ends with variable and passing multiple test strings', function() {
|
|
|
|
var contains = containsVariable('show field keys from $pgmetric', 'test string2', 'pgmetric');
|
|
|
|
expect(contains).to.be(true);
|
|
|
|
});
|
|
|
|
|
2016-09-16 09:50:30 -05:00
|
|
|
it('should find it with [[var]] syntax', function() {
|
|
|
|
var contains = containsVariable('this.[[test]].filters', 'test');
|
|
|
|
expect(contains).to.be(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should find it when part of segment', function() {
|
|
|
|
var contains = containsVariable('metrics.$env.$group-*', 'group');
|
|
|
|
expect(contains).to.be(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should find it its the only thing', function() {
|
|
|
|
var contains = containsVariable('$env', 'env');
|
|
|
|
expect(contains).to.be(true);
|
|
|
|
});
|
2016-09-17 04:28:45 -05:00
|
|
|
|
|
|
|
it('should be able to pass in multiple test strings', function() {
|
|
|
|
var contains = containsVariable('asd','asd2.$env', 'env');
|
|
|
|
expect(contains).to.be(true);
|
|
|
|
});
|
|
|
|
|
2016-09-16 09:50:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-09-19 08:15:15 -05:00
|
|
|
describe('assignModelProperties', function() {
|
|
|
|
|
|
|
|
it('only set properties defined in defaults', function() {
|
|
|
|
var target: any = {test: 'asd'};
|
|
|
|
assignModelProperties(target, {propA: 1, propB: 2}, {propB: 0});
|
|
|
|
expect(target.propB).to.be(2);
|
|
|
|
expect(target.test).to.be('asd');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('use default value if not found on source', function() {
|
|
|
|
var target: any = {test: 'asd'};
|
|
|
|
assignModelProperties(target, {propA: 1, propB: 2}, {propC: 10});
|
|
|
|
expect(target.propC).to.be(10);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|