vx-builder 0.0.27 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vx/builder/build_configuration/cache.rb +48 -0
- data/lib/vx/builder/build_configuration/env.rb +43 -0
- data/lib/vx/builder/build_configuration.rb +113 -0
- data/lib/vx/builder/matrix.rb +112 -0
- data/lib/vx/builder/script/env.rb +1 -1
- data/lib/vx/builder/version.rb +1 -1
- data/lib/vx/builder.rb +6 -4
- data/spec/fixtures/travis.yml +23 -13
- data/spec/lib/builder/build_configuration_spec.rb +99 -0
- data/spec/lib/builder/matrix_spec.rb +226 -0
- data/spec/support/create.rb +1 -1
- metadata +9 -9
- data/lib/vx/builder/source/constants.rb +0 -12
- data/lib/vx/builder/source/matrix.rb +0 -116
- data/lib/vx/builder/source/serializable.rb +0 -43
- data/lib/vx/builder/source.rb +0 -118
- data/spec/lib/builder/source_matrix_spec.rb +0 -222
- data/spec/lib/builder/source_spec.rb +0 -223
@@ -1,222 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
describe Vx::Builder::Source::Matrix do
|
5
|
-
let(:attributes) { {
|
6
|
-
env: %w{ FOO=1 BAR=2 },
|
7
|
-
rvm: %w{ 1.8.7 1.9.3 2.0.0 },
|
8
|
-
scala: %w{ 2.9.2 2.10.1 },
|
9
|
-
before_script: "echo before_script",
|
10
|
-
before_install: "echo before_install",
|
11
|
-
script: "echo script",
|
12
|
-
} }
|
13
|
-
let(:config) { Vx::Builder::Source.from_attributes attributes }
|
14
|
-
let(:matrix) { described_class.new config }
|
15
|
-
|
16
|
-
subject { matrix }
|
17
|
-
|
18
|
-
context "just created" do
|
19
|
-
its(:source) { should eq config }
|
20
|
-
end
|
21
|
-
|
22
|
-
context "keys" do
|
23
|
-
subject { matrix.keys }
|
24
|
-
it { should eq %w{ env rvm scala } }
|
25
|
-
context "without matrix" do
|
26
|
-
let(:attributes) { {} }
|
27
|
-
|
28
|
-
it { should eq [] }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'configurations' do
|
33
|
-
subject { matrix.configurations }
|
34
|
-
|
35
|
-
it "should copy script from source" do
|
36
|
-
expect(subject.map(&:script).flatten).to eq ["echo script"] * 12
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should copy before_script from source" do
|
40
|
-
expect(subject.map(&:before_script).flatten).to eq ["echo before_script"] * 12
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should copy before_install from source" do
|
44
|
-
expect(subject.map(&:before_install).flatten).to eq ["echo before_install"] * 12
|
45
|
-
end
|
46
|
-
|
47
|
-
context "without any matrix keys" do
|
48
|
-
let(:attributes) { {
|
49
|
-
script: %w{ /bin/true },
|
50
|
-
} }
|
51
|
-
|
52
|
-
it { should have(1).item }
|
53
|
-
its("first.attributes") { should eq(
|
54
|
-
"env" => {
|
55
|
-
"matrix" => [],
|
56
|
-
"global" => []
|
57
|
-
},
|
58
|
-
"script" =>["/bin/true"],
|
59
|
-
"before_script" =>[],
|
60
|
-
"services" => [],
|
61
|
-
"before_install" => [],
|
62
|
-
"after_success" => []
|
63
|
-
)}
|
64
|
-
end
|
65
|
-
|
66
|
-
context "with one env and one rvm key" do
|
67
|
-
let(:config) { Vx::Builder::Source.from_file fixture_path("travis_bug_1.yml") }
|
68
|
-
|
69
|
-
it{ should have(1).item }
|
70
|
-
|
71
|
-
context "attributes" do
|
72
|
-
subject { matrix.configurations.map(&:to_matrix_s) }
|
73
|
-
|
74
|
-
it { should eq ["env:DB=postgresql, rvm:2.0.0"] }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "with services key" do
|
79
|
-
let(:config) { Vx::Builder::Source.from_file fixture_path("travis_bug_2.yml") }
|
80
|
-
it { should have(1).item }
|
81
|
-
|
82
|
-
it "should have services" do
|
83
|
-
expect(matrix.configurations.first.services).to eq %w{ elasticsearch }
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
context "values" do
|
89
|
-
|
90
|
-
it { should have(12).items }
|
91
|
-
|
92
|
-
context "attributes" do
|
93
|
-
subject { matrix.configurations.map(&:to_matrix_s) }
|
94
|
-
|
95
|
-
it do
|
96
|
-
should eq [
|
97
|
-
"env:BAR=2, rvm:1.8.7, scala:2.10.1",
|
98
|
-
"env:FOO=1, rvm:1.8.7, scala:2.10.1",
|
99
|
-
"env:BAR=2, rvm:1.8.7, scala:2.9.2",
|
100
|
-
"env:FOO=1, rvm:1.8.7, scala:2.9.2",
|
101
|
-
"env:BAR=2, rvm:1.9.3, scala:2.10.1",
|
102
|
-
"env:FOO=1, rvm:1.9.3, scala:2.10.1",
|
103
|
-
"env:BAR=2, rvm:1.9.3, scala:2.9.2",
|
104
|
-
"env:FOO=1, rvm:1.9.3, scala:2.9.2",
|
105
|
-
"env:BAR=2, rvm:2.0.0, scala:2.10.1",
|
106
|
-
"env:FOO=1, rvm:2.0.0, scala:2.10.1",
|
107
|
-
"env:BAR=2, rvm:2.0.0, scala:2.9.2",
|
108
|
-
"env:FOO=1, rvm:2.0.0, scala:2.9.2"
|
109
|
-
]
|
110
|
-
end
|
111
|
-
|
112
|
-
context "without matrix" do
|
113
|
-
let(:attributes) { {
|
114
|
-
rvm: %w{ 2.0.0 },
|
115
|
-
} }
|
116
|
-
|
117
|
-
it { should eq ['rvm:2.0.0'] }
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context "attributes_for_new_confgurations_with_merged_env" do
|
125
|
-
subject { matrix.attributes_for_new_configurations_with_merged_env }
|
126
|
-
|
127
|
-
before do
|
128
|
-
attributes.merge!(
|
129
|
-
env: {
|
130
|
-
"global" => "FOO=1",
|
131
|
-
"matrix" => %w{ BAR=1 BAR=2 }
|
132
|
-
}
|
133
|
-
)
|
134
|
-
end
|
135
|
-
|
136
|
-
it { should have(12).items }
|
137
|
-
|
138
|
-
it "should merge matrix env to global env" do
|
139
|
-
expect(subject.map{|i| i["env"]["global"] }.uniq.sort).to eq([["BAR=1", "FOO=1"], ["BAR=2", "FOO=1"]])
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'attributes_for_new_configurations' do
|
144
|
-
subject { matrix.attributes_for_new_configurations }
|
145
|
-
|
146
|
-
it { should have(12).items }
|
147
|
-
|
148
|
-
its(:first) { should eq("rvm" => "1.8.7",
|
149
|
-
"scala" => "2.10.1",
|
150
|
-
"env" => "BAR=2") }
|
151
|
-
its(:last) { should eq("rvm" => "2.0.0",
|
152
|
-
"scala" => "2.9.2",
|
153
|
-
"env" => "FOO=1") }
|
154
|
-
end
|
155
|
-
|
156
|
-
context 'extract_pair_of_key_and_values' do
|
157
|
-
subject { matrix.extract_pair_of_key_and_values }
|
158
|
-
it {
|
159
|
-
should eq [
|
160
|
-
["rvm", %w{ 1.8.7 1.9.3 2.0.0 }],
|
161
|
-
["scala", %w{ 2.9.2 2.10.1 }],
|
162
|
-
["env", %w{ FOO=1 BAR=2 }]
|
163
|
-
]
|
164
|
-
}
|
165
|
-
end
|
166
|
-
|
167
|
-
context "permutate_and_build_values" do
|
168
|
-
subject { format_values matrix.permutate_and_build_values }
|
169
|
-
let(:expected) { [
|
170
|
-
%w{env:BAR=2 rvm:1.8.7 scala:2.10.1},
|
171
|
-
%w{env:BAR=2 rvm:1.8.7 scala:2.9.2},
|
172
|
-
%w{env:BAR=2 rvm:1.9.3 scala:2.10.1},
|
173
|
-
%w{env:BAR=2 rvm:1.9.3 scala:2.9.2},
|
174
|
-
%w{env:BAR=2 rvm:2.0.0 scala:2.10.1},
|
175
|
-
%w{env:BAR=2 rvm:2.0.0 scala:2.9.2},
|
176
|
-
%w{env:FOO=1 rvm:1.8.7 scala:2.10.1},
|
177
|
-
%w{env:FOO=1 rvm:1.8.7 scala:2.9.2},
|
178
|
-
%w{env:FOO=1 rvm:1.9.3 scala:2.10.1},
|
179
|
-
%w{env:FOO=1 rvm:1.9.3 scala:2.9.2},
|
180
|
-
%w{env:FOO=1 rvm:2.0.0 scala:2.10.1},
|
181
|
-
%w{env:FOO=1 rvm:2.0.0 scala:2.9.2},
|
182
|
-
] }
|
183
|
-
|
184
|
-
it { should eq expected }
|
185
|
-
|
186
|
-
context "with empty keys" do
|
187
|
-
let(:attributes) { {
|
188
|
-
env: %w{ FOO=1 BAR=2 },
|
189
|
-
rvm: %w{ 1.8.7 1.9.3 2.0.0 },
|
190
|
-
scala: %w{ 2.9.2 2.10.1 },
|
191
|
-
java: [],
|
192
|
-
go: nil
|
193
|
-
} }
|
194
|
-
it { should eq expected }
|
195
|
-
end
|
196
|
-
|
197
|
-
context "with one key" do
|
198
|
-
let(:attributes) { {
|
199
|
-
rvm: %w{ 1.9.3 2.0.0 },
|
200
|
-
} }
|
201
|
-
let(:expected) {[
|
202
|
-
%w{ rvm:1.9.3 },
|
203
|
-
%w{ rvm:2.0.0 }
|
204
|
-
]}
|
205
|
-
it { should eq expected }
|
206
|
-
end
|
207
|
-
|
208
|
-
context "without matrix" do
|
209
|
-
let(:attributes) { {
|
210
|
-
rvm: %w{ 2.0.0 },
|
211
|
-
} }
|
212
|
-
let(:expected) {[
|
213
|
-
%w{ rvm:2.0.0 }
|
214
|
-
]}
|
215
|
-
it { should eq expected }
|
216
|
-
end
|
217
|
-
|
218
|
-
def format_values(values)
|
219
|
-
values.map{|i| i.map(&:to_s).sort }.sort
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
@@ -1,223 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Vx::Builder::Source do
|
4
|
-
let(:default_content) { YAML.load fixture('travis.yml') }
|
5
|
-
let(:content) { default_content }
|
6
|
-
let(:config) { described_class.from_attributes content }
|
7
|
-
subject { config }
|
8
|
-
|
9
|
-
its(:attributes) { should be }
|
10
|
-
its(:rvm) { should eq %w{ 2.0.0 } }
|
11
|
-
its(:gemfile) { should eq %w{ Gemfile } }
|
12
|
-
its(:before_script) { should eq ["echo before_script"] }
|
13
|
-
its(:script) { should eq ["RAILS_ENV=test ls -1 && echo DONE!"] }
|
14
|
-
its(:language) { should eq 'ruby' }
|
15
|
-
|
16
|
-
context "merge" do
|
17
|
-
let(:new_attrs) { { rvm: "replaced" } }
|
18
|
-
subject{ config.merge new_attrs }
|
19
|
-
|
20
|
-
it "should build a new BuildConfiguration instance" do
|
21
|
-
expect(subject).to be_an_instance_of(described_class)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should replace attributes" do
|
25
|
-
expect(subject.attributes["rvm"]).to eq %w{ replaced }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "cached_directories" do
|
30
|
-
subject { config.cached_directories }
|
31
|
-
context "when cache is false" do
|
32
|
-
let(:content) { default_content.merge("cache" => false) }
|
33
|
-
it { should be_false }
|
34
|
-
end
|
35
|
-
context "when cache is nil" do
|
36
|
-
let(:content) { default_content.delete("cache") && default_content }
|
37
|
-
it { should eq [] }
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when cache.directories is nil" do
|
41
|
-
let(:content) { default_content["cache"].delete("directories") && default_content }
|
42
|
-
it { should eq [] }
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when exists" do
|
46
|
-
it { should eq ["~/.cache"] }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "(serialization)" do
|
51
|
-
|
52
|
-
context "build new instance" do
|
53
|
-
let(:expected) { {
|
54
|
-
"rvm" => ["2.0.0"],
|
55
|
-
"gemfile" => ["Gemfile"],
|
56
|
-
"image" => %w{ one two },
|
57
|
-
"before_script" => ["echo before_script"],
|
58
|
-
"after_success" => ["echo after success"],
|
59
|
-
"cache" => {
|
60
|
-
"directories"=>["~/.cache"]
|
61
|
-
},
|
62
|
-
"language" => "ruby",
|
63
|
-
"before_install" => ["echo before_install"],
|
64
|
-
"script" => ["RAILS_ENV=test ls -1 && echo DONE!"],
|
65
|
-
"env" => {
|
66
|
-
"matrix" => [],
|
67
|
-
"global" => []
|
68
|
-
}
|
69
|
-
} }
|
70
|
-
|
71
|
-
context "from_yaml" do
|
72
|
-
subject { described_class.from_yaml(fixture('travis.yml')).attributes }
|
73
|
-
it { should eq expected }
|
74
|
-
end
|
75
|
-
|
76
|
-
context "form_file" do
|
77
|
-
subject { described_class.from_file('spec/fixtures/travis.yml').attributes }
|
78
|
-
it { should eq expected }
|
79
|
-
end
|
80
|
-
|
81
|
-
context "from_attributes" do
|
82
|
-
let(:attrs) {{
|
83
|
-
rvm: "2.0.0",
|
84
|
-
image: %w{ one two },
|
85
|
-
gemfile: "Gemfile",
|
86
|
-
before_script: "echo before_script",
|
87
|
-
after_success: "echo after success",
|
88
|
-
language: "ruby",
|
89
|
-
before_install: "echo before_install",
|
90
|
-
script: "RAILS_ENV=test ls -1 && echo DONE!",
|
91
|
-
cache: {
|
92
|
-
"directories" => ["~/.cache"]
|
93
|
-
}
|
94
|
-
}}
|
95
|
-
subject { described_class.from_attributes(attrs).attributes }
|
96
|
-
it { should eq expected }
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context ".to_yaml" do
|
101
|
-
subject { config.to_yaml }
|
102
|
-
it { should eq config.attributes.to_yaml }
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context "to_matrix_s" do
|
107
|
-
subject { config.to_matrix_s }
|
108
|
-
it { should eq 'gemfile:Gemfile, image:one, rvm:2.0.0' }
|
109
|
-
|
110
|
-
context "when many items" do
|
111
|
-
before do
|
112
|
-
mock(config).rvm { %w{ 1.9.3 2.0.0 } }
|
113
|
-
mock(config).scala { %w{ 2.10.1 } }
|
114
|
-
end
|
115
|
-
it { should eq "gemfile:Gemfile, image:one, rvm:1.9.3, scala:2.10.1" }
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "matrix_keys" do
|
120
|
-
subject { config.matrix_keys }
|
121
|
-
it { should eq("rvm" => "2.0.0", "gemfile" => "Gemfile", "image" => "one") }
|
122
|
-
|
123
|
-
context "when many items" do
|
124
|
-
before do
|
125
|
-
mock(config).rvm { %w{ 1.9.3 2.0.0 } }
|
126
|
-
mock(config).scala { %w{ 2.10.1 } }
|
127
|
-
end
|
128
|
-
it { should eq({"rvm"=>"1.9.3", "scala"=>"2.10.1", "gemfile" => "Gemfile", 'image' => "one"}) }
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
it "empty attributes must be empty Array" do
|
134
|
-
expect(config.scala).to eq([])
|
135
|
-
end
|
136
|
-
|
137
|
-
context "normalize_attributes" do
|
138
|
-
described_class::AS_ARRAY.each do |m|
|
139
|
-
context "convert #{m} attribute to Array" do
|
140
|
-
let(:content) { { m => m } }
|
141
|
-
subject { config.__send__(m) }
|
142
|
-
it { should eq([m]) }
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "convert hash keys to strings" do
|
147
|
-
let(:content) { { rvm: "rvm" } }
|
148
|
-
subject { config.attributes }
|
149
|
-
it { should include("rvm" => %w{rvm}) }
|
150
|
-
end
|
151
|
-
|
152
|
-
context "build env hash" do
|
153
|
-
subject { config.attributes["env"] }
|
154
|
-
|
155
|
-
context "from String" do
|
156
|
-
let(:content) { { env: "FOO" } }
|
157
|
-
it { should eq( "global" => [], "matrix" => %w{ FOO } ) }
|
158
|
-
end
|
159
|
-
|
160
|
-
context "from Array" do
|
161
|
-
let(:content) { { env: %w{ FOO BAR } } }
|
162
|
-
it { should eq( 'global' => [], 'matrix' => %w{ FOO BAR } ) }
|
163
|
-
end
|
164
|
-
|
165
|
-
context "from empty Hash" do
|
166
|
-
let(:content) { { env: {} } }
|
167
|
-
it { should eq( 'global' => [], 'matrix' => [] ) }
|
168
|
-
end
|
169
|
-
|
170
|
-
context "from Hash" do
|
171
|
-
let(:content) { { env: { "global" => "1", 'matrix' => '2' } } }
|
172
|
-
it { should eq( 'global' => %w{1}, 'matrix' => %w{2} ) }
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
context "env" do
|
178
|
-
let(:content) { { env: env } }
|
179
|
-
subject { config.env }
|
180
|
-
|
181
|
-
context "when attributes[env] is Array" do
|
182
|
-
let(:env) { %w{ FOO=1 BAR=2 } }
|
183
|
-
it { should eq("matrix"=>["FOO=1", "BAR=2"], "global"=>[]) }
|
184
|
-
end
|
185
|
-
|
186
|
-
context "when attributes[env] is Hash" do
|
187
|
-
let(:env) { { "matrix" => %w{ BAZ=1 } } }
|
188
|
-
it { should eq("matrix"=>["BAZ=1"], "global"=>[]) }
|
189
|
-
end
|
190
|
-
|
191
|
-
context "when attributes[env] is empty" do
|
192
|
-
let(:env) { {} }
|
193
|
-
it { should eq("matrix"=>[], "global"=>[]) }
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context "global_env" do
|
198
|
-
let(:content) { { env: env } }
|
199
|
-
subject { config.global_env }
|
200
|
-
|
201
|
-
context "when attributes[env] is Array" do
|
202
|
-
let(:env) { %w{ FOO=1 } }
|
203
|
-
it { should eq([]) }
|
204
|
-
end
|
205
|
-
|
206
|
-
context "when attributes[env] is Hash" do
|
207
|
-
let(:env) { { "global" => %w{ FOO=1 } } }
|
208
|
-
it { should eq %w{ FOO=1 } }
|
209
|
-
end
|
210
|
-
|
211
|
-
context "when attributes[env] is empty" do
|
212
|
-
let(:env) { {} }
|
213
|
-
it { should eq([]) }
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
context "services" do
|
218
|
-
subject { config.services }
|
219
|
-
let(:content) { { services: 'service' } }
|
220
|
-
it { should eq ['service'] }
|
221
|
-
end
|
222
|
-
|
223
|
-
end
|