Skip to content

Commit 427c930

Browse files
committed
Create ExtraMountFiles
1 parent ffc05c3 commit 427c930

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
test/dummy_gem/matrixeval.yml
1111
test/dummy_gem/.matrixeval
1212
test/dummy_gem/.gitignore
13+
test/dummy_gem/mount.txt
1314
.byebug_history
1415
Gemfile.lock

lib/matrixeval/ruby.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require 'matrixeval/ruby/docker_compose'
66
require 'matrixeval/ruby/context'
77
require 'matrixeval/ruby/gemfile_locks'
8+
require 'matrixeval/ruby/extra_mount_files'
89
require 'matrixeval/ruby/runner'
910
require 'matrixeval/ruby/gitignore'
1011

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Matrixeval
2+
module Ruby
3+
class ExtraMountFiles
4+
class << self
5+
6+
def create
7+
Config.all_mounts.each do |mount|
8+
local_path, _ = mount.split(':')
9+
next mount if Pathname.new(local_path).absolute?
10+
11+
local_path = Matrixeval.working_dir.join(local_path)
12+
next if local_path.extname.empty?
13+
next if local_path.ascend.none? { |path| path == Matrixeval.working_dir }
14+
15+
FileUtils.mkdir_p local_path.dirname
16+
FileUtils.touch local_path
17+
end
18+
end
19+
20+
end
21+
end
22+
end
23+
end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class Matrixeval::Ruby::ExtraMountFilesTest < MatrixevalTest
6+
7+
def setup
8+
FileUtils.rm_rf dummy_gem_working_dir.join(".test_mount") rescue nil
9+
FileUtils.rm dummy_gem_working_dir.join("mount.txt") rescue nil
10+
FileUtils.rm_rf dummy_gem_working_dir.join(".matrixeval/schema") rescue nil
11+
Matrixeval.stubs(:working_dir).returns(dummy_gem_working_dir)
12+
end
13+
14+
def test_create
15+
Matrixeval::Ruby::Config::YAML.stubs(:yaml).returns({
16+
"target" => "ruby",
17+
"mounts" => [
18+
"/matrixeval-a/b:/c/d",
19+
".test_mount:/test_mount",
20+
"mount.txt:/app/mount.txt"
21+
],
22+
"matrix" => {
23+
"ruby" => {
24+
"variants" => [
25+
{ "key" => "3.0", "default" => true },
26+
{ "key" => "3.1" }
27+
]
28+
},
29+
"rails" => {
30+
"variants" => [
31+
{
32+
"key" => "6.1",
33+
"mounts" => [
34+
".matrixeval/schema/rails_6_1.rb:/app/test/dummy/db/schema.rb"
35+
]
36+
},
37+
{
38+
"key" => "7.0",
39+
"default" => true,
40+
"mounts" => [
41+
".matrixeval/schema/rails_7_0.rb:/app/test/dummy/db/schema.rb"
42+
]
43+
}
44+
]
45+
}
46+
}
47+
})
48+
49+
refute File.exist? dummy_gem_working_dir.join(".matrixeval/schema/rails_6_1.rb")
50+
refute File.exist? dummy_gem_working_dir.join(".matrixeval/schema/rails_7_0.rb")
51+
refute File.exist? dummy_gem_working_dir.join("mount.txt")
52+
refute File.exist? "/matrixeval-a"
53+
refute File.exist? dummy_gem_working_dir.join(".test_mount")
54+
55+
Matrixeval::Ruby::ExtraMountFiles.create
56+
57+
assert File.exist? dummy_gem_working_dir.join(".matrixeval/schema/rails_6_1.rb")
58+
assert File.exist? dummy_gem_working_dir.join(".matrixeval/schema/rails_7_0.rb")
59+
assert File.exist? dummy_gem_working_dir.join("mount.txt")
60+
refute File.exist? "/matrixeval-a"
61+
refute File.exist? dummy_gem_working_dir.join(".test_mount")
62+
end
63+
64+
end

0 commit comments

Comments
 (0)