-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathnats_config_spec.rb
161 lines (149 loc) · 5.36 KB
/
nats_config_spec.rb
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
require 'rspec'
require 'bosh/template/test'
require 'yaml'
require 'json'
module Bosh::Template::Test
describe 'nats.conf.erb' do
describe 'template rendering' do
let(:release_path) { File.join(File.dirname(__FILE__), '../..') }
let(:release) { ReleaseDir.new(release_path) }
let(:merged_manifest_properties) do
{
'nats' => {
'user' => 'my-user',
'password' => 'my-password',
'hostname' => 'my-host',
'port' => 4222,
'cluster_port' => 4223,
'authorization_timeout' => 15,
'machines' => nil,
'no_advertise' => true,
'debug' => false,
'trace' => false,
'http' => '0.0.0.0:0',
'prof_port' => 0,
'internal' => {
'tls' => {
'enabled' => true,
'ca' => 'internal-tls-ca',
'certificate' => 'internal-tls-cert',
'private_key' => 'internal-tls-key'
}
}
}
}
end
let(:links) do
[
Link.new(
name: 'nats',
instances: [
LinkInstance.new(id: 'meowmeowmeow'),
LinkInstance.new(id: 'a-b-c-d')
],
properties: {
'nats' => {
'user' => 'my-user',
'password' => 'my-password',
'hostname' => 'my-host',
'port' => 4222,
'cluster_port' => 4223,
'http' => '0.0.0.0:0'
}
}
)
]
end
let(:expected_hash) do
{
'net' => '10.0.0.1',
'port' => 4222,
'prof_port' => 0,
'http' => '0.0.0.0:0',
'write_deadline' => '2s',
'debug' => false,
'trace' => false,
'logtime' => true,
'authorization' => {
'user' => "my-user",
'password' => "my-password",
'timeout' => 15,
},
'cluster' => {
'no_advertise' => true,
'host' => "10.0.0.1",
'port' => 4223,
'authorization' => {
'user' => "my-user",
'password' => "my-password",
'timeout' => 15,
},
'tls' => {
'ca_file' => "/var/vcap/jobs/nats/config/internal_tls/ca.pem",
'cert_file' => "/var/vcap/jobs/nats/config/internal_tls/certificate.pem",
'key_file' => "/var/vcap/jobs/nats/config/internal_tls/private_key.pem",
'cipher_suites' => [
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
],
'curve_preferences' => [
"CurveP384",
],
'timeout' => 5,
'verify' => true,
},
'routes' => [
'nats-route://my-user:[email protected]:4223',
'nats-route://my-user:[email protected]:4223',
]
},
'no_sys_acc' => true,
}
end
let(:spec) do
{ 'address' => '10.0.0.1' }
end
describe 'nats job' do
let(:job) {release.job('nats')}
describe 'config/nats.conf' do
let(:template) { job.template('config/nats.conf') }
it 'renders the template with the provided manifest properties' do
rendered_hash = YAML.load(template.render(merged_manifest_properties, consumes: links, spec: spec))
expect(rendered_hash).to eq(expected_hash)
end
describe 'nats machine ips are provided' do
before do
merged_manifest_properties['nats']['machines'] = ['192.0.0.1', '198.5.4.3']
expected_hash['cluster']['routes'] =
[
'nats-route://my-user:[email protected]:4223',
'nats-route://my-user:[email protected]:4223'
]
end
it 'renders the template with the provided manifest properties' do
rendered_hash = YAML.load(template.render(merged_manifest_properties, consumes: links, spec: spec))
expect(rendered_hash).to eq(expected_hash)
end
end
describe 'nats machine ips and tls_cluster_port are provided' do
before do
merged_manifest_properties['nats']['machines'] = ['192.0.0.1', '198.5.4.3']
merged_manifest_properties['nats']['tls_cluster_port'] = '4225'
expected_hash['cluster']['routes'] =
[
'nats-route://my-user:[email protected]:4223',
'nats-route://my-user:[email protected]:4223',
'nats-route://my-user:[email protected]:4225',
'nats-route://my-user:[email protected]:4225',
]
end
it 'renders the template with the provided manifest properties' do
rendered_hash = YAML.load(template.render(merged_manifest_properties, consumes: links, spec: spec))
expect(rendered_hash).to eq(expected_hash)
end
end
end
end
end
end
end