r10k 3.11.0 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.mkd +9 -0
  3. data/doc/dynamic-environments/configuration.mkd +7 -3
  4. data/doc/dynamic-environments/usage.mkd +26 -0
  5. data/doc/puppetfile.mkd +3 -4
  6. data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
  7. data/lib/r10k/action/deploy/environment.rb +8 -1
  8. data/lib/r10k/action/deploy/module.rb +11 -6
  9. data/lib/r10k/action/puppetfile/check.rb +7 -5
  10. data/lib/r10k/action/puppetfile/install.rb +22 -16
  11. data/lib/r10k/action/puppetfile/purge.rb +12 -9
  12. data/lib/r10k/cli/deploy.rb +1 -0
  13. data/lib/r10k/cli/puppetfile.rb +0 -1
  14. data/lib/r10k/content_synchronizer.rb +16 -4
  15. data/lib/r10k/environment/base.rb +64 -11
  16. data/lib/r10k/environment/with_modules.rb +6 -10
  17. data/lib/r10k/git/stateful_repository.rb +7 -0
  18. data/lib/r10k/initializers.rb +1 -7
  19. data/lib/r10k/module/base.rb +5 -1
  20. data/lib/r10k/module/definition.rb +64 -0
  21. data/lib/r10k/module/forge.rb +10 -2
  22. data/lib/r10k/module/git.rb +22 -1
  23. data/lib/r10k/module/local.rb +2 -3
  24. data/lib/r10k/module/svn.rb +10 -0
  25. data/lib/r10k/module.rb +20 -2
  26. data/lib/r10k/module_loader/puppetfile/dsl.rb +8 -3
  27. data/lib/r10k/module_loader/puppetfile.rb +95 -29
  28. data/lib/r10k/puppetfile.rb +1 -2
  29. data/lib/r10k/settings.rb +11 -0
  30. data/lib/r10k/version.rb +1 -1
  31. data/locales/r10k.pot +75 -47
  32. data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
  33. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +9 -0
  34. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +9 -0
  35. data/spec/r10k-mocks/mock_env.rb +3 -0
  36. data/spec/r10k-mocks/mock_source.rb +7 -3
  37. data/spec/unit/action/deploy/environment_spec.rb +80 -30
  38. data/spec/unit/action/deploy/module_spec.rb +50 -62
  39. data/spec/unit/action/puppetfile/check_spec.rb +17 -5
  40. data/spec/unit/action/puppetfile/install_spec.rb +42 -36
  41. data/spec/unit/action/puppetfile/purge_spec.rb +15 -17
  42. data/spec/unit/action/runner_spec.rb +0 -8
  43. data/spec/unit/environment/base_spec.rb +30 -17
  44. data/spec/unit/environment/git_spec.rb +2 -2
  45. data/spec/unit/environment/svn_spec.rb +4 -3
  46. data/spec/unit/environment/with_modules_spec.rb +2 -1
  47. data/spec/unit/module/base_spec.rb +8 -8
  48. data/spec/unit/module/forge_spec.rb +32 -4
  49. data/spec/unit/module/git_spec.rb +51 -10
  50. data/spec/unit/module/svn_spec.rb +18 -6
  51. data/spec/unit/module_loader/puppetfile_spec.rb +90 -30
  52. data/spec/unit/puppetfile_spec.rb +2 -2
  53. data/spec/unit/settings_spec.rb +25 -2
  54. metadata +7 -2
@@ -3,7 +3,7 @@ require 'r10k/action/puppetfile/check'
3
3
 
4
4
  describe R10K::Action::Puppetfile::Check do
5
5
  let(:default_opts) { {root: "/some/nonexistent/path"} }
6
- let(:puppetfile) { instance_double('R10K::Puppetfile', :load! => true) }
6
+ let(:loader) { instance_double('R10K::ModuleLoader::Puppetfile', :load! => {}) }
7
7
 
8
8
  def checker(opts = {}, argv = [], settings = {})
9
9
  opts = default_opts.merge(opts)
@@ -11,7 +11,11 @@ describe R10K::Action::Puppetfile::Check do
11
11
  end
12
12
 
13
13
  before(:each) do
14
- allow(R10K::Puppetfile).to receive(:new).with("/some/nonexistent/path", {moduledir: nil, puppetfile_path: nil}).and_return(puppetfile)
14
+ allow(R10K::ModuleLoader::Puppetfile).
15
+ to receive(:new).
16
+ with({
17
+ basedir: "/some/nonexistent/path",
18
+ }).and_return(loader)
15
19
  end
16
20
 
17
21
  it_behaves_like "a puppetfile action"
@@ -23,8 +27,11 @@ describe R10K::Action::Puppetfile::Check do
23
27
  end
24
28
 
25
29
  it "prints an error message when validating the Puppetfile syntax raised an error" do
26
- allow(puppetfile).to receive(:load!).and_raise(R10K::Error.new("Boom!"))
27
- allow(R10K::Errors::Formatting).to receive(:format_exception).with(instance_of(R10K::Error), anything).and_return("Formatted error message")
30
+ allow(loader).to receive(:load!).and_raise(R10K::Error.new("Boom!"))
31
+ allow(R10K::Errors::Formatting).
32
+ to receive(:format_exception).
33
+ with(instance_of(R10K::Error), anything).
34
+ and_return("Formatted error message")
28
35
 
29
36
  expect($stderr).to receive(:puts).with("Formatted error message")
30
37
 
@@ -34,7 +41,12 @@ describe R10K::Action::Puppetfile::Check do
34
41
  it "respects --puppetfile option" do
35
42
  allow($stderr).to receive(:puts)
36
43
 
37
- expect(R10K::Puppetfile).to receive(:new).with("/some/nonexistent/path", {moduledir: nil, puppetfile_path: "/custom/puppetfile/path"}).and_return(puppetfile)
44
+ expect(R10K::ModuleLoader::Puppetfile).
45
+ to receive(:new).
46
+ with({
47
+ basedir: "/some/nonexistent/path",
48
+ puppetfile: "/custom/puppetfile/path"
49
+ }).and_return(loader)
38
50
 
39
51
  checker({puppetfile: "/custom/puppetfile/path"}).call
40
52
  end
@@ -3,9 +3,10 @@ require 'r10k/action/puppetfile/install'
3
3
 
4
4
  describe R10K::Action::Puppetfile::Install do
5
5
  let(:default_opts) { { root: "/some/nonexistent/path" } }
6
- let(:puppetfile) {
7
- R10K::Puppetfile.new('/some/nonexistent/path',
8
- {:moduledir => nil, :puppetfile_path => nil, :force => false})
6
+ let(:loader) {
7
+ R10K::ModuleLoader::Puppetfile.new({
8
+ basedir: '/some/nonexistent/path',
9
+ overrides: {force: false}})
9
10
  }
10
11
 
11
12
  def installer(opts = {}, argv = [], settings = {})
@@ -14,11 +15,11 @@ describe R10K::Action::Puppetfile::Install do
14
15
  end
15
16
 
16
17
  before(:each) do
17
- allow(puppetfile).to receive(:load!).and_return(nil)
18
- allow(R10K::Puppetfile).to receive(:new).
19
- with("/some/nonexistent/path",
20
- {:moduledir => nil, :puppetfile_path => nil, :force => false}).
21
- and_return(puppetfile)
18
+ allow(loader).to receive(:load!).and_return({})
19
+ allow(R10K::ModuleLoader::Puppetfile).to receive(:new).
20
+ with({basedir: "/some/nonexistent/path",
21
+ overrides: {force: false}}).
22
+ and_return(loader)
22
23
  end
23
24
 
24
25
  it_behaves_like "a puppetfile install action"
@@ -26,13 +27,19 @@ describe R10K::Action::Puppetfile::Install do
26
27
  describe "installing modules" do
27
28
  let(:modules) do
28
29
  (1..4).map do |idx|
29
- R10K::Module::Base.new("author/modname#{idx}", "/some/nonexistent/path/modname#{idx}", {})
30
+ R10K::Module::Base.new("author/modname#{idx}",
31
+ "/some/nonexistent/path/modname#{idx}",
32
+ {})
30
33
  end
31
34
  end
32
35
 
33
36
  before do
34
- allow(puppetfile).to receive(:modules).and_return(modules)
35
- allow(puppetfile).to receive(:modules_by_vcs_cachedir).and_return({none: modules})
37
+ allow(loader).to receive(:load!).and_return({
38
+ modules: modules,
39
+ managed_directories: [],
40
+ desired_contents: [],
41
+ purge_exclusions: []
42
+ })
36
43
  end
37
44
 
38
45
  it "syncs each module in the Puppetfile" do
@@ -50,15 +57,15 @@ describe R10K::Action::Puppetfile::Install do
50
57
  end
51
58
 
52
59
  describe "purging" do
53
- before do
54
- allow(puppetfile).to receive(:modules).and_return([])
55
- end
56
-
57
60
  it "purges the moduledir after installation" do
61
+ allow(loader).to receive(:load!).and_return({
62
+ modules: [],
63
+ desired_contents: [ 'root/foo' ],
64
+ managed_directories: [ 'root' ],
65
+ purge_exclusions: [ 'root/**/**.rb' ]
66
+ })
67
+
58
68
  mock_cleaner = double("cleaner")
59
- allow(puppetfile).to receive(:desired_contents).and_return(["root/foo"])
60
- allow(puppetfile).to receive(:managed_directories).and_return(["root"])
61
- allow(puppetfile).to receive(:purge_exclusions).and_return(["root/**/**.rb"])
62
69
 
63
70
  expect(R10K::Util::Cleaner).to receive(:new).
64
71
  with(["root"], ["root/foo"], ["root/**/**.rb"]).
@@ -70,35 +77,34 @@ describe R10K::Action::Puppetfile::Install do
70
77
  end
71
78
 
72
79
  describe "using custom paths" do
73
- it "can use a custom puppetfile path" do
74
- expect(R10K::Puppetfile).to receive(:new).
75
- with("/some/nonexistent/path",
76
- {:moduledir => nil, :force => false, puppetfile_path: "/some/other/path/Puppetfile"}).
77
- and_return(puppetfile)
80
+ it "can use a custom moduledir path" do
81
+ expect(R10K::ModuleLoader::Puppetfile).to receive(:new).
82
+ with({basedir: "/some/nonexistent/path",
83
+ overrides: { force: false },
84
+ puppetfile: "/some/other/path/Puppetfile"}).
85
+ and_return(loader)
78
86
 
79
87
  installer({puppetfile: "/some/other/path/Puppetfile"}).call
80
- end
81
88
 
82
- it "can use a custom moduledir path" do
83
- expect(R10K::Puppetfile).to receive(:new).
84
- with("/some/nonexistent/path",
85
- {:puppetfile_path => nil, :force => false, moduledir: "/some/other/path/site-modules"}).
86
- and_return(puppetfile)
89
+ expect(R10K::ModuleLoader::Puppetfile).to receive(:new).
90
+ with({basedir: "/some/nonexistent/path",
91
+ overrides: { force: false },
92
+ moduledir: "/some/other/path/site-modules"}).
93
+ and_return(loader)
87
94
 
88
95
  installer({moduledir: "/some/other/path/site-modules"}).call
89
96
  end
90
97
  end
91
98
 
92
99
  describe "forcing to overwrite local changes" do
93
- before do
94
- allow(puppetfile).to receive(:modules).and_return([])
95
- end
96
-
97
100
  it "can use the force overwrite option" do
101
+ allow(loader).to receive(:load!).and_return({ modules: [] })
102
+
98
103
  subject = described_class.new({root: "/some/nonexistent/path", force: true}, [], {})
99
- expect(R10K::Puppetfile).to receive(:new).
100
- with("/some/nonexistent/path", {:moduledir => nil, :puppetfile_path => nil, :force => true}).
101
- and_return(puppetfile)
104
+ expect(R10K::ModuleLoader::Puppetfile).to receive(:new).
105
+ with({basedir: "/some/nonexistent/path",
106
+ overrides: { force: true }}).
107
+ and_return(loader)
102
108
  subject.call
103
109
  end
104
110
 
@@ -4,11 +4,13 @@ require 'r10k/action/puppetfile/purge'
4
4
  describe R10K::Action::Puppetfile::Purge do
5
5
  let(:default_opts) { {root: "/some/nonexistent/path"} }
6
6
  let(:puppetfile) do
7
- instance_double('R10K::Puppetfile',
8
- :load! => nil,
9
- :managed_directories => %w{foo},
10
- :desired_contents => %w{bar},
11
- :purge_exclusions => %w{baz})
7
+ instance_double('R10K::ModuleLoader::Puppetfile',
8
+ :load! => {
9
+ :modules => %w{mod},
10
+ :managed_directories => %w{foo},
11
+ :desired_contents => %w{bar},
12
+ :purge_exclusions => %w{baz}
13
+ })
12
14
  end
13
15
 
14
16
  def purger(opts = {}, argv = [], settings = {})
@@ -17,8 +19,8 @@ describe R10K::Action::Puppetfile::Purge do
17
19
  end
18
20
 
19
21
  before(:each) do
20
- allow(R10K::Puppetfile).to receive(:new).
21
- with("/some/nonexistent/path", {moduledir: nil, puppetfile_path: nil}).
22
+ allow(R10K::ModuleLoader::Puppetfile).to receive(:new).
23
+ with({basedir: "/some/nonexistent/path"}).
22
24
  and_return(puppetfile)
23
25
  end
24
26
 
@@ -37,23 +39,19 @@ describe R10K::Action::Puppetfile::Purge do
37
39
  end
38
40
 
39
41
  describe "using custom paths" do
40
- before(:each) do
41
- allow(puppetfile).to receive(:purge!)
42
- end
43
-
44
42
  it "can use a custom puppetfile path" do
45
- expect(R10K::Puppetfile).to receive(:new).
46
- with("/some/nonexistent/path",
47
- {moduledir: nil, puppetfile_path: "/some/other/path/Puppetfile"}).
43
+ expect(R10K::ModuleLoader::Puppetfile).to receive(:new).
44
+ with({basedir: "/some/nonexistent/path",
45
+ puppetfile: "/some/other/path/Puppetfile"}).
48
46
  and_return(puppetfile)
49
47
 
50
48
  purger({puppetfile: "/some/other/path/Puppetfile"}).call
51
49
  end
52
50
 
53
51
  it "can use a custom moduledir path" do
54
- expect(R10K::Puppetfile).to receive(:new).
55
- with("/some/nonexistent/path",
56
- {moduledir: "/some/other/path/site-modules", puppetfile_path: nil}).
52
+ expect(R10K::ModuleLoader::Puppetfile).to receive(:new).
53
+ with({basedir: "/some/nonexistent/path",
54
+ moduledir: "/some/other/path/site-modules"}).
57
55
  and_return(puppetfile)
58
56
 
59
57
  purger({moduledir: "/some/other/path/site-modules"}).call
@@ -310,14 +310,6 @@ describe R10K::Action::Runner do
310
310
  runner.setup_settings
311
311
  runner.setup_authorization
312
312
  end
313
-
314
- it 'errors if no custom forge URL is set' do
315
- options = { config: "spec/fixtures/unit/action/r10k_forge_auth_no_url.yaml" }
316
- runner = described_class.new(options, %w[args yes], action_class)
317
- expect(PuppetForge::Connection).not_to receive(:authorization=).with('faketoken')
318
-
319
- expect { runner.setup_settings }.to raise_error(R10K::Error, /Cannot specify a Forge auth/)
320
- end
321
313
  end
322
314
 
323
315
  context "license auth" do
@@ -3,10 +3,13 @@ require 'r10k/environment'
3
3
 
4
4
  describe R10K::Environment::Base do
5
5
 
6
- subject(:environment) { described_class.new('envname', '/some/imaginary/path', 'env_name', {}) }
6
+ let(:basepath) { '/some/imaginary/path' }
7
+ let(:envname) { 'env_name' }
8
+ let(:path) { File.join(basepath, envname) }
9
+ subject(:environment) { described_class.new('envname', basepath, envname, {}) }
7
10
 
8
11
  it "can return the fully qualified path" do
9
- expect(environment.path).to eq(Pathname.new('/some/imaginary/path/env_name'))
12
+ expect(environment.path).to eq(Pathname.new(path))
10
13
  end
11
14
 
12
15
  it "raises an exception when #sync is called" do
@@ -49,45 +52,55 @@ describe R10K::Environment::Base do
49
52
  describe "#purge_exclusions" do
50
53
  let(:mock_env) { instance_double("R10K::Environment::Base") }
51
54
  let(:mock_puppetfile) { instance_double("R10K::Puppetfile", :environment= => true, :environment => mock_env) }
55
+ let(:loader) do
56
+ instance_double("R10K::ModuleLoader::Puppetfile",
57
+ :environment= => nil,
58
+ :load => { :modules => @modules,
59
+ :managed_directories => @managed_dirs,
60
+ :desired_contents => @desired_contents,
61
+ :purge_exclusions => @purge_ex })
62
+ end
52
63
 
53
64
  before(:each) do
54
- allow(mock_puppetfile).to receive(:managed_directories).and_return([])
55
- allow(mock_puppetfile).to receive(:desired_contents).and_return([])
56
- allow(R10K::Puppetfile).to receive(:new).and_return(mock_puppetfile)
65
+ @modules = []
66
+ @managed_dirs = []
67
+ @desired_contents = []
68
+ @purge_exclusions = []
57
69
  end
58
70
 
59
71
  it "excludes .r10k-deploy.json" do
72
+ allow(R10K::ModuleLoader::Puppetfile).to receive(:new).and_return(loader)
73
+ subject.deploy
74
+
60
75
  expect(subject.purge_exclusions).to include(/r10k-deploy\.json/)
61
76
  end
62
77
 
63
78
  it "excludes puppetfile managed directories" do
64
- managed_dirs = [
79
+ @managed_dirs = [
65
80
  '/some/imaginary/path/env_name/modules',
66
81
  '/some/imaginary/path/env_name/data',
67
82
  ]
68
83
 
69
- expect(mock_puppetfile).to receive(:managed_directories).and_return(managed_dirs)
84
+ allow(R10K::ModuleLoader::Puppetfile).to receive(:new).and_return(loader)
85
+ subject.deploy
70
86
 
71
87
  exclusions = subject.purge_exclusions
72
88
 
73
- managed_dirs.each do |dir|
89
+ @managed_dirs.each do |dir|
74
90
  expect(exclusions).to include(dir)
75
91
  end
76
92
  end
77
93
 
78
94
  describe "puppetfile desired contents" do
79
- let(:desired_contents) do
80
- basedir = subject.path.to_s
81
-
82
- [ 'modules/apache', 'data/local/site' ].collect do |c|
83
- File.join(basedir, c)
84
- end
85
- end
86
95
 
87
96
  before(:each) do
88
- allow(File).to receive(:directory?).with(/^\/some\/imaginary\/path/).and_return(true)
97
+ @desired_contents = [ 'modules/apache', 'data/local/site' ].collect do |c|
98
+ File.join(path, c)
99
+ end
89
100
 
90
- expect(mock_puppetfile).to receive(:desired_contents).and_return(desired_contents)
101
+ allow(File).to receive(:directory?).and_return true
102
+ allow(R10K::ModuleLoader::Puppetfile).to receive(:new).and_return(loader)
103
+ subject.deploy
91
104
  end
92
105
 
93
106
  it "excludes desired directory contents with glob" do
@@ -78,9 +78,9 @@ describe R10K::Environment::Git do
78
78
 
79
79
  describe "enumerating modules" do
80
80
  it "loads the Puppetfile and returns modules in that puppetfile" do
81
+ loaded = { desired_contents: [], managed_directories: [], purge_exclusions: [] }
81
82
  mod = double('A module', :name => 'dbl')
82
- expect(subject.puppetfile).to receive(:load)
83
- expect(subject.puppetfile).to receive(:modules).and_return [mod]
83
+ expect(subject.loader).to receive(:load).and_return(loaded.merge(modules: [mod]))
84
84
  expect(subject.modules).to eq([mod])
85
85
  end
86
86
  end
@@ -78,9 +78,10 @@ describe R10K::Environment::SVN do
78
78
 
79
79
  describe "enumerating modules" do
80
80
  it "loads the Puppetfile and returns modules in that puppetfile" do
81
- expect(subject.puppetfile).to receive(:load)
82
- expect(subject.puppetfile).to receive(:modules).and_return [:modules]
83
- expect(subject.modules).to eq([:modules])
81
+ loaded = { managed_directories: [], desired_contents: [], purge_exclusions: [] }
82
+ mod = double('A module', :name => 'dbl')
83
+ expect(subject.loader).to receive(:load).and_return(loaded.merge(modules: [mod]))
84
+ expect(subject.modules).to eq([mod])
84
85
  end
85
86
  end
86
87
 
@@ -65,8 +65,9 @@ describe R10K::Environment::WithModules do
65
65
 
66
66
  describe "modules method" do
67
67
  it "returns the configured modules, and Puppetfile modules" do
68
+ loaded = { managed_directories: [], desired_contents: [], purge_exclusions: [] }
68
69
  puppetfile_mod = instance_double('R10K::Module::Base', name: 'zebra')
69
- expect(subject.puppetfile).to receive(:modules).and_return [puppetfile_mod]
70
+ expect(subject.loader).to receive(:load).and_return(loaded.merge(modules: [puppetfile_mod]))
70
71
  returned_modules = subject.modules
71
72
  expect(returned_modules.map(&:name).sort).to eq(%w[concat exec stdlib zebra])
72
73
  end
@@ -4,26 +4,26 @@ require 'r10k/module/base'
4
4
  describe R10K::Module::Base do
5
5
  describe "parsing the title" do
6
6
  it "parses titles with no owner" do
7
- m = described_class.new('eight_hundred', '/moduledir', [])
7
+ m = described_class.new('eight_hundred', '/moduledir', {})
8
8
  expect(m.name).to eq 'eight_hundred'
9
9
  expect(m.owner).to be_nil
10
10
  end
11
11
 
12
12
  it "parses forward slash separated titles" do
13
- m = described_class.new('branan/eight_hundred', '/moduledir', [])
13
+ m = described_class.new('branan/eight_hundred', '/moduledir', {})
14
14
  expect(m.name).to eq 'eight_hundred'
15
15
  expect(m.owner).to eq 'branan'
16
16
  end
17
17
 
18
18
  it "parses hyphen separated titles" do
19
- m = described_class.new('branan-eight_hundred', '/moduledir', [])
19
+ m = described_class.new('branan-eight_hundred', '/moduledir', {})
20
20
  expect(m.name).to eq 'eight_hundred'
21
21
  expect(m.owner).to eq 'branan'
22
22
  end
23
23
 
24
24
  it "raises an error when the title is not correctly formatted" do
25
25
  expect {
26
- described_class.new('branan!eight_hundred', '/moduledir', [])
26
+ described_class.new('branan!eight_hundred', '/moduledir', {})
27
27
  }.to raise_error(ArgumentError, "Module name (branan!eight_hundred) must match either 'modulename' or 'owner/modulename'")
28
28
  end
29
29
  end
@@ -76,13 +76,13 @@ describe R10K::Module::Base do
76
76
 
77
77
  describe "path variables" do
78
78
  it "uses the module name as the name" do
79
- m = described_class.new('eight_hundred', '/moduledir', [])
79
+ m = described_class.new('eight_hundred', '/moduledir', {})
80
80
  expect(m.dirname).to eq '/moduledir'
81
81
  expect(m.path).to eq(Pathname.new('/moduledir/eight_hundred'))
82
82
  end
83
83
 
84
84
  it "does not include the owner in the path" do
85
- m = described_class.new('branan/eight_hundred', '/moduledir', [])
85
+ m = described_class.new('branan/eight_hundred', '/moduledir', {})
86
86
  expect(m.dirname).to eq '/moduledir'
87
87
  expect(m.path).to eq(Pathname.new('/moduledir/eight_hundred'))
88
88
  end
@@ -90,7 +90,7 @@ describe R10K::Module::Base do
90
90
 
91
91
  describe "with alternate variable names" do
92
92
  subject do
93
- described_class.new('branan/eight_hundred', '/moduledir', [])
93
+ described_class.new('branan/eight_hundred', '/moduledir', {})
94
94
  end
95
95
 
96
96
  it "aliases full_name to title" do
@@ -107,7 +107,7 @@ describe R10K::Module::Base do
107
107
  end
108
108
 
109
109
  describe "accepting a visitor" do
110
- subject { described_class.new('branan-eight_hundred', '/moduledir', []) }
110
+ subject { described_class.new('branan-eight_hundred', '/moduledir', {}) }
111
111
 
112
112
  it "passes itself to the visitor" do
113
113
  visitor = spy('visitor')
@@ -9,6 +9,28 @@ describe R10K::Module::Forge do
9
9
  let(:fixture_modulepath) { File.expand_path('spec/fixtures/module/forge', PROJECT_ROOT) }
10
10
  let(:empty_modulepath) { File.expand_path('spec/fixtures/empty', PROJECT_ROOT) }
11
11
 
12
+ describe "statically determined version support" do
13
+ it 'returns explicitly released forge versions' do
14
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { version: '8.0.0' })
15
+ expect(static_version).to eq('8.0.0')
16
+ end
17
+
18
+ it 'returns explicit pre-released forge versions' do
19
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { version: '8.0.0-pre1' })
20
+ expect(static_version).to eq('8.0.0-pre1')
21
+ end
22
+
23
+ it 'retuns nil for latest versions' do
24
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { version: :latest })
25
+ expect(static_version).to eq(nil)
26
+ end
27
+
28
+ it 'retuns nil for undefined versions' do
29
+ static_version = described_class.statically_defined_version('branan/eight_hundred', { version: nil })
30
+ expect(static_version).to eq(nil)
31
+ end
32
+ end
33
+
12
34
  describe "implementing the Puppetfile spec" do
13
35
  it "should implement 'branan/eight_hundred', '8.0.0'" do
14
36
  expect(described_class).to be_implement('branan/eight_hundred', { version: '8.0.0' })
@@ -190,25 +212,31 @@ describe R10K::Module::Forge do
190
212
  expect(subject).to receive(:install).never
191
213
  expect(subject).to receive(:upgrade).never
192
214
  expect(subject).to receive(:reinstall).never
193
- subject.sync
215
+ expect(subject.sync).to be false
194
216
  end
195
217
 
196
218
  it 'reinstalls the module when it is mismatched' do
197
219
  allow(subject).to receive(:status).and_return :mismatched
198
220
  expect(subject).to receive(:reinstall)
199
- subject.sync
221
+ expect(subject.sync).to be true
200
222
  end
201
223
 
202
224
  it 'upgrades the module when it is outdated' do
203
225
  allow(subject).to receive(:status).and_return :outdated
204
226
  expect(subject).to receive(:upgrade)
205
- subject.sync
227
+ expect(subject.sync).to be true
206
228
  end
207
229
 
208
230
  it 'installs the module when it is absent' do
209
231
  allow(subject).to receive(:status).and_return :absent
210
232
  expect(subject).to receive(:install)
211
- subject.sync
233
+ expect(subject.sync).to be true
234
+ end
235
+
236
+ it 'returns false if `should_sync?` is false' do
237
+ # modules do not sync if they are not requested
238
+ mod = described_class.new('my_org/my_mod', '/path/to/mod', { overrides: { modules: { requested_modules: ['other_mod'] } } })
239
+ expect(mod.sync).to be false
212
240
  end
213
241
  end
214
242