-
Notifications
You must be signed in to change notification settings - Fork 902
/
cloudProvider.registry.spec.ts
131 lines (110 loc) · 5.14 KB
/
cloudProvider.registry.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { mock } from 'angular';
import { CLOUD_PROVIDER_REGISTRY, CloudProviderRegistry } from './cloudProvider.registry';
describe('cloudProviderRegistry: API', function() {
let configurer: CloudProviderRegistry;
beforeEach(
mock.module(
CLOUD_PROVIDER_REGISTRY,
function(cloudProviderRegistryProvider: CloudProviderRegistry) {
configurer = cloudProviderRegistryProvider;
}
)
);
describe('registration', function() {
it('registers providers', mock.inject(function() {
expect(configurer.$get().getProvider('aws')).toBeNull();
const config = { name: 'a', key: 'a' };
configurer.registerProvider('aws', config);
expect(configurer.$get().getProvider('aws')).toEqual(config);
}));
});
describe('property lookup', function() {
beforeEach(function() {
this.config = {
key: 'a',
nested: {
good: 'nice',
falsy: false,
nully: null,
zero: 0,
}
};
});
it('returns simple or nested properties', function() {
configurer.registerProvider('aws', this.config);
expect(configurer.$get().getValue('aws', 'key')).toEqual('a');
expect(configurer.$get().getValue('aws', 'nested')).toEqual(this.config.nested);
expect(configurer.$get().getValue('aws', 'nested.good')).toEqual('nice');
});
it('returns a copy of properties, not actual registered values', function() {
configurer.registerProvider('aws', this.config);
expect(configurer.$get().getValue('aws', 'nested')).not.toBe(this.config.nested);
expect(configurer.$get().getValue('aws', 'nested')).toEqual(this.config.nested);
// the above tests should be sufficient, but just to really drive home the point
const nested = configurer.$get().getValue('aws', 'nested');
expect(nested.good).toBe('nice');
nested.good = 'mean';
expect(configurer.$get().getValue('aws', 'nested').good).toBe('nice');
});
it('returns falsy values', mock.inject(function() {
configurer.registerProvider('aws', this.config);
expect(configurer.$get().getValue('aws', 'nested.falsy')).toBe(false);
expect(configurer.$get().getValue('aws', 'nested.nully')).toBe(null);
expect(configurer.$get().getValue('aws', 'nested.zero')).toBe(0);
}));
it('returns null when provider or property is not found', mock.inject(function() {
configurer.registerProvider('aws', this.config);
expect(configurer.$get().getValue('gce', 'a')).toBe(null);
expect(configurer.$get().getValue('aws', 'b')).toBe(null);
expect(configurer.$get().getValue('aws', 'a.b')).toBe(null);
}));
});
describe('hasValue', function () {
beforeEach(function() {
this.config = {
key: 'a',
nested: {
good: 'nice',
falsy: false,
nully: null,
zero: 0,
}
};
});
it('returns true on simple or nested properties', function() {
configurer.registerProvider('aws', this.config);
expect(configurer.$get().hasValue('aws', 'key')).toBe(true);
expect(configurer.$get().hasValue('aws', 'nested')).toBe(true);
expect(configurer.$get().hasValue('aws', 'nested.good')).toBe(true);
expect(configurer.$get().hasValue('aws', 'nested.falsy')).toBe(true);
expect(configurer.$get().hasValue('aws', 'nested.zero')).toBe(true);
});
it('returns false on null properties, non-existent properties or non-existent providers', function () {
configurer.registerProvider('aws', this.config);
expect(configurer.$get().hasValue('aws', 'nested.nully')).toBe(false);
expect(configurer.$get().hasValue('aws', 'nonexistent')).toBe(false);
expect(configurer.$get().hasValue('aws', 'definitely.nonexistent')).toBe(false);
expect(configurer.$get().hasValue('boo', 'bar')).toBe(false);
expect(configurer.$get().hasValue('boo', 'bar.baz')).toBe(false);
});
});
describe('skinned provider configs', () => {
it('returns a value from a skinned provider config when skin is specified', () => {
configurer.registerProvider('kubernetes', { name: 'kubernetes', skin: 'v1' });
configurer.registerProvider('kubernetes', { name: 'kubernetes', skin: 'v2' });
expect(configurer.$get().getValue('kubernetes', 'skin', 'v1')).toBe('v1');
expect(configurer.$get().getValue('kubernetes', 'skin', 'v2')).toBe('v2');
});
it('returns a value from the default skin if skin is not specified', () => {
configurer.registerProvider('kubernetes', { name: 'kubernetes', skin: 'v1' });
configurer.registerProvider('kubernetes', { name: 'kubernetes', skin: 'v2', defaultSkin: true });
expect(configurer.$get().getValue('kubernetes', 'skin')).toBe('v2');
});
// This behavior is implicitly tested in other tests, but demonstrates that the provider
// configs do not need to add a `defaultSkin` flag if there is only one config for that provider.
it('behaves reasonably if a provider does not define a default config version', () => {
configurer.registerProvider('gce', { name: 'gce', key: 'value' });
expect(configurer.$get().getValue('gce', 'key')).toBe('value');
})
});
});