-
Notifications
You must be signed in to change notification settings - Fork 50
/
create_env_files_spec.rb
executable file
·101 lines (90 loc) · 2.73 KB
/
create_env_files_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
#! /usr/bin/env ruby
#
# unit tests for the helpers in `create_env_files.erb.tmpl`
#
#
# paste ruby code from `create_env_files.erb.tmpl` here and run `rspec path/to/this/file`
#
#
# below here are the unit tests
#
require "rspec"
require "json"
describe "env_file_writer" do
context "Array" do
let(:value) {
[
"foo",
"bar\n", # public_key variable attrs have a trailing linebreak
"baz",
]
}
let(:expected) {
<<~EOS
cat > /var/vcap/jobs/{{.Name}}/config/env/MyEnv <<"ENVGEN_EOF"
foo
bar
baz
ENVGEN_EOF
if [[ "${ENV_FILE_OWNER:-}" != "" ]] ; then
chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv
fi
chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv
EOS
}
it { expect(env_file_writer(value, "MyEnv")).to eq(expected) }
end
context "Hash" do
let(:value) {
{
"foo" => "bar",
"baz" => ["quux", "quuux", "quuuux"],
"thud" => { "grunt" => "gorp" },
}
}
let(:expected) {
<<~EOS
cat > /var/vcap/jobs/{{.Name}}/config/env/MyEnv_foo <<"ENVGEN_EOF"
bar
ENVGEN_EOF
if [[ "${ENV_FILE_OWNER:-}" != "" ]] ; then
chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv_foo
fi
chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv_foo
cat > /var/vcap/jobs/{{.Name}}/config/env/MyEnv_baz <<"ENVGEN_EOF"
quux
quuux
quuuux
ENVGEN_EOF
if [[ "${ENV_FILE_OWNER:-}" != "" ]] ; then
chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv_baz
fi
chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv_baz
cat > /var/vcap/jobs/{{.Name}}/config/env/MyEnv_thud <<"ENVGEN_EOF"
{"grunt":"gorp"}
ENVGEN_EOF
if [[ "${ENV_FILE_OWNER:-}" != "" ]] ; then
chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv_thud
fi
chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv_thud
EOS
}
it { expect(env_file_writer(value, "MyEnv")).to eq(expected) }
end
context "String" do
let(:value) { "hello there\ni am fine" }
let(:expected) {
<<~EOS
cat > /var/vcap/jobs/{{.Name}}/config/env/MyEnv <<"ENVGEN_EOF"
hello there
i am fine
ENVGEN_EOF
if [[ "${ENV_FILE_OWNER:-}" != "" ]] ; then
chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv
fi
chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv
EOS
}
it { expect(env_file_writer(value, "MyEnv")).to eq(expected) }
end
end