Skip to content

Commit abc3046

Browse files
committed
Add Config#env #mounts #all_mounts
1 parent 865de32 commit abc3046

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

lib/matrixeval/ruby/config.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ def docker_compose_extend_raw
7272
)
7373
end
7474

75+
def env
76+
YAML["env"] || {}
77+
end
78+
79+
def mounts
80+
YAML["mounts"] || []
81+
end
82+
83+
def all_mounts
84+
mounts + all_variant_mounts
85+
end
86+
87+
private
88+
89+
def all_variant_mounts
90+
Config.vectors
91+
.map(&:variants).flatten
92+
.map(&:mounts).flatten
93+
end
94+
7595
end
7696
end
7797
end

test/matrixeval/ruby/config_test.rb

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def setup
99
"version" => "0.2",
1010
"target" => "ruby",
1111
"project_name" => "sample app",
12+
"mounts" => ["/a:/b"],
1213
"matrix" => {
1314
"ruby" => {
1415
"variants" => [
@@ -18,8 +19,8 @@ def setup
1819
},
1920
"active_model" => {
2021
"variants" => [
21-
{ "key" => "6.1" },
22-
{ "key" => "7.0" }
22+
{ "key" => "6.1", "mounts" => [".matrixeval/schema/rails_6_1.rb:/app/test/dummy/db/schema.rb"] },
23+
{ "key" => "7.0", "mounts" => [".matrixeval/schema/rails_7_0.rb:/app/test/dummy/db/schema.rb"] }
2324
]
2425
}
2526
},
@@ -43,8 +44,36 @@ def test_target
4344
assert_equal "ruby", Matrixeval::Ruby::Config.target
4445
end
4546

46-
def project_name
47-
assert_equal "sampe_app", Matrixeval::Ruby::Config.project_name
47+
def test_project_name
48+
assert_equal "sample app", Matrixeval::Ruby::Config.project_name
49+
end
50+
51+
def test_env
52+
Matrixeval::Ruby::Config::YAML.stubs(:yaml).returns({"env" => { 'A' => 'a' }})
53+
assert_equal({'A' => 'a'}, Matrixeval::Ruby::Config.env)
54+
end
55+
56+
def test_env_default
57+
Matrixeval::Ruby::Config::YAML.stubs(:yaml).returns({})
58+
assert_equal({}, Matrixeval::Ruby::Config.env)
59+
end
60+
61+
def test_mounts
62+
Matrixeval::Ruby::Config::YAML.stubs(:yaml).returns({"mounts" => ["/a:/b"]})
63+
assert_equal ["/a:/b"], Matrixeval::Ruby::Config.mounts
64+
end
65+
66+
def test_mounts_default
67+
Matrixeval::Ruby::Config::YAML.stubs(:yaml).returns({})
68+
assert_equal [], Matrixeval::Ruby::Config.mounts
69+
end
70+
71+
def test_all_mounts
72+
assert_equal([
73+
"/a:/b",
74+
".matrixeval/schema/rails_6_1.rb:/app/test/dummy/db/schema.rb",
75+
".matrixeval/schema/rails_7_0.rb:/app/test/dummy/db/schema.rb"
76+
], Matrixeval::Ruby::Config.all_mounts)
4877
end
4978

5079
def test_vectors
@@ -94,10 +123,19 @@ def test_exclusions
94123

95124
def test_commands
96125
Matrixeval::Ruby::Config::YAML.stubs(:yaml).returns({})
97-
assert_equal ['rake', 'rspec', 'bundle', 'bash'], Matrixeval::Ruby::Config.commands
126+
assert_equal([
127+
'ruby', 'rake', 'rails', 'rspec', 'bundle',
128+
'bin/rake', 'bin/rails', 'bin/rspec', 'bin/test',
129+
'bash', 'dash', 'sh', 'zsh'
130+
], Matrixeval::Ruby::Config.commands)
98131

99132
Matrixeval::Ruby::Config::YAML.stubs(:yaml).returns({'commands' => ['ls']})
100-
assert_equal ['rake', 'rspec', 'bundle', 'bash', 'ls'], Matrixeval::Ruby::Config.commands
133+
assert_equal([
134+
'ruby', 'rake', 'rails', 'rspec', 'bundle',
135+
'bin/rake', 'bin/rails', 'bin/rspec', 'bin/test',
136+
'bash', 'dash', 'sh', 'zsh',
137+
'ls'
138+
], Matrixeval::Ruby::Config.commands)
101139
end
102140

103141
def test_docker_compose_extend_raw

0 commit comments

Comments
 (0)