librarian 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/lib/librarian.rb +5 -178
  3. data/lib/librarian/action.rb +5 -0
  4. data/lib/librarian/action/base.rb +22 -0
  5. data/lib/librarian/action/clean.rb +56 -0
  6. data/lib/librarian/action/ensure.rb +24 -0
  7. data/lib/librarian/action/install.rb +101 -0
  8. data/lib/librarian/action/resolve.rb +81 -0
  9. data/lib/librarian/action/update.rb +76 -0
  10. data/lib/librarian/chef/cli.rb +7 -2
  11. data/lib/librarian/chef/dsl.rb +0 -3
  12. data/lib/librarian/chef/environment.rb +19 -0
  13. data/lib/librarian/chef/extension.rb +1 -16
  14. data/lib/librarian/chef/integration/knife.rb +9 -16
  15. data/lib/librarian/chef/source/git.rb +0 -2
  16. data/lib/librarian/chef/source/local.rb +1 -74
  17. data/lib/librarian/chef/source/local/manifest.rb +82 -0
  18. data/lib/librarian/chef/source/path.rb +0 -2
  19. data/lib/librarian/chef/source/site.rb +9 -89
  20. data/lib/librarian/chef/source/site/manifest.rb +94 -0
  21. data/lib/librarian/cli.rb +56 -17
  22. data/lib/librarian/dependency.rb +2 -2
  23. data/lib/librarian/dsl.rb +15 -5
  24. data/lib/librarian/dsl/receiver.rb +2 -0
  25. data/lib/librarian/dsl/target.rb +13 -1
  26. data/lib/librarian/environment.rb +94 -0
  27. data/lib/librarian/error.rb +4 -0
  28. data/lib/librarian/helpers/debug.rb +6 -6
  29. data/lib/librarian/lockfile.rb +7 -5
  30. data/lib/librarian/lockfile/compiler.rb +5 -4
  31. data/lib/librarian/lockfile/parser.rb +6 -5
  32. data/lib/librarian/manifest.rb +2 -2
  33. data/lib/librarian/mock/cli.rb +6 -1
  34. data/lib/librarian/mock/dsl.rb +0 -3
  35. data/lib/librarian/mock/environment.rb +24 -0
  36. data/lib/librarian/mock/extension.rb +1 -20
  37. data/lib/librarian/mock/source/mock.rb +7 -7
  38. data/lib/librarian/mock/source/mock/registry.rb +16 -12
  39. data/lib/librarian/resolver.rb +5 -116
  40. data/lib/librarian/resolver/implementation.rb +117 -0
  41. data/lib/librarian/source/git.rb +8 -7
  42. data/lib/librarian/source/git/repository.rb +7 -5
  43. data/lib/librarian/source/local.rb +1 -1
  44. data/lib/librarian/source/path.rb +7 -6
  45. data/lib/librarian/spec_change_set.rb +6 -5
  46. data/lib/librarian/specfile.rb +10 -4
  47. data/lib/librarian/version.rb +1 -1
  48. data/librarian.gemspec +1 -0
  49. data/spec/functional/chef/source/git_spec.rb +177 -89
  50. data/spec/functional/chef/source/site_spec.rb +111 -52
  51. data/spec/unit/action/base_spec.rb +18 -0
  52. data/spec/unit/action/clean_spec.rb +133 -0
  53. data/spec/unit/action/ensure_spec.rb +37 -0
  54. data/spec/unit/action/install_spec.rb +113 -0
  55. data/spec/unit/dsl_spec.rb +15 -13
  56. data/spec/unit/environment_spec.rb +9 -0
  57. data/spec/unit/lockfile_spec.rb +15 -4
  58. data/spec/unit/mock/source/mock.rb +22 -0
  59. data/spec/unit/resolver_spec.rb +24 -24
  60. data/spec/unit/spec_change_set_spec.rb +29 -25
  61. metadata +47 -19
  62. data/lib/librarian/chef/particularity.rb +0 -9
  63. data/lib/librarian/mock/particularity.rb +0 -9
  64. data/lib/librarian/particularity.rb +0 -7
@@ -6,11 +6,13 @@ module Librarian
6
6
 
7
7
  describe Dsl do
8
8
 
9
+ let(:env) { Environment.new }
10
+
9
11
  context "a single dependency but no applicable source" do
10
12
 
11
13
  it "should not run without any sources" do
12
14
  expect do
13
- Dsl.run do
15
+ env.dsl do
14
16
  dep 'dependency-1'
15
17
  end
16
18
  end.to raise_error(Dsl::Error)
@@ -18,7 +20,7 @@ module Librarian
18
20
 
19
21
  it "should not run when a block source is defined but the dependency is outside the block" do
20
22
  expect do
21
- Dsl.run do
23
+ env.dsl do
22
24
  src 'source-1' do end
23
25
  dep 'dependency-1'
24
26
  end
@@ -30,7 +32,7 @@ module Librarian
30
32
  context "a simple specfile - a single source, a single dependency, no transitive dependencies" do
31
33
 
32
34
  it "should run with a hash source" do
33
- spec = Dsl.run do
35
+ spec = env.dsl do
34
36
  dep 'dependency-1',
35
37
  :src => 'source-1'
36
38
  end
@@ -41,7 +43,7 @@ module Librarian
41
43
  end
42
44
 
43
45
  it "should run with a shortcut source" do
44
- spec = Dsl.run do
46
+ spec = env.dsl do
45
47
  dep 'dependency-1',
46
48
  :source => :a
47
49
  end
@@ -52,7 +54,7 @@ module Librarian
52
54
  end
53
55
 
54
56
  it "should run with a block hash source" do
55
- spec = Dsl.run do
57
+ spec = env.dsl do
56
58
  source :src => 'source-1' do
57
59
  dep 'dependency-1'
58
60
  end
@@ -64,7 +66,7 @@ module Librarian
64
66
  end
65
67
 
66
68
  it "should run with a block named source" do
67
- spec = Dsl.run do
69
+ spec = env.dsl do
68
70
  src 'source-1' do
69
71
  dep 'dependency-1'
70
72
  end
@@ -76,7 +78,7 @@ module Librarian
76
78
  end
77
79
 
78
80
  it "should run with a default hash source" do
79
- spec = Dsl.run do
81
+ spec = env.dsl do
80
82
  source :src => 'source-1'
81
83
  dep 'dependency-1'
82
84
  end
@@ -88,7 +90,7 @@ module Librarian
88
90
  end
89
91
 
90
92
  it "should run with a default named source" do
91
- spec = Dsl.run do
93
+ spec = env.dsl do
92
94
  src 'source-1'
93
95
  dep 'dependency-1'
94
96
  end
@@ -100,7 +102,7 @@ module Librarian
100
102
  end
101
103
 
102
104
  it "should run with a default shortcut source" do
103
- spec = Dsl.run do
105
+ spec = env.dsl do
104
106
  source :a
105
107
  dep 'dependency-1'
106
108
  end
@@ -112,7 +114,7 @@ module Librarian
112
114
  end
113
115
 
114
116
  it "should run with a shortcut source hash definition" do
115
- spec = Dsl.run do
117
+ spec = env.dsl do
116
118
  source :b, :src => 'source-b'
117
119
  dep 'dependency-1', :source => :b
118
120
  end
@@ -123,7 +125,7 @@ module Librarian
123
125
  end
124
126
 
125
127
  it "should run with a shortcut source block definition" do
126
- spec = Dsl.run do
128
+ spec = env.dsl do
127
129
  source :b, proc { src 'source-b' }
128
130
  dep 'dependency-1', :source => :b
129
131
  end
@@ -134,7 +136,7 @@ module Librarian
134
136
  end
135
137
 
136
138
  it "should run with a default shortcut source hash definition" do
137
- spec = Dsl.run do
139
+ spec = env.dsl do
138
140
  source :b, :src => 'source-b'
139
141
  source :b
140
142
  dep 'dependency-1'
@@ -147,7 +149,7 @@ module Librarian
147
149
  end
148
150
 
149
151
  it "should run with a default shortcut source block definition" do
150
- spec = Dsl.run do
152
+ spec = env.dsl do
151
153
  source :b, proc { src 'source-b' }
152
154
  source :b
153
155
  dep 'dependency-1'
@@ -0,0 +1,9 @@
1
+ require "librarian/environment"
2
+
3
+ module Librarian
4
+ describe Environment do
5
+
6
+ let(:env) { described_class.new }
7
+
8
+ end
9
+ end
@@ -4,8 +4,10 @@ require 'librarian/mock'
4
4
  module Librarian
5
5
  describe Lockfile do
6
6
 
7
+ let(:env) { Mock::Environment.new }
8
+
7
9
  before do
8
- Mock.registry :clear => true do
10
+ env.registry :clear => true do
9
11
  source 'source-1' do
10
12
  spec 'alpha', '1.1'
11
13
  end
@@ -13,13 +15,13 @@ module Librarian
13
15
  end
14
16
 
15
17
  let(:spec) do
16
- Mock.dsl do
18
+ env.dsl do
17
19
  src 'source-1'
18
20
  dep 'alpha', '1.1'
19
21
  end
20
22
  end
21
23
 
22
- let(:resolver) { Mock.resolver }
24
+ let(:resolver) { env.resolver }
23
25
  let(:resolution) { resolver.resolve(spec) }
24
26
 
25
27
  context "sanity" do
@@ -27,11 +29,12 @@ module Librarian
27
29
  subject { resolution }
28
30
 
29
31
  it { should be_correct }
32
+ it { should have(1).manifests }
30
33
  end
31
34
  end
32
35
 
33
36
  describe "#save" do
34
- let(:lockfile) { Mock.ephemeral_lockfile }
37
+ let(:lockfile) { env.ephemeral_lockfile }
35
38
  let(:lockfile_text) { lockfile.save(resolution) }
36
39
 
37
40
  context "just saving" do
@@ -40,6 +43,14 @@ module Librarian
40
43
  end
41
44
  end
42
45
 
46
+ context "saving and reloading" do
47
+ let(:reloaded_resolution) { lockfile.load(lockfile_text) }
48
+
49
+ it "should have the expected manifests" do
50
+ reloaded_resolution.manifests.count.should == resolution.manifests.count
51
+ end
52
+ end
53
+
43
54
  context "bouncing" do
44
55
  let(:bounced_resolution) { lockfile.load(lockfile_text) }
45
56
  let(:bounced_lockfile_text) { lockfile.save(bounced_resolution) }
@@ -0,0 +1,22 @@
1
+ require "librarian/mock"
2
+
3
+ module Librarian
4
+ module Mock
5
+ module Source
6
+ describe Mock do
7
+
8
+ let(:env) { Librarian::Mock::Environment.new }
9
+
10
+ describe ".new" do
11
+
12
+ let(:source) { described_class.new(env, "source-a", {}) }
13
+ subject { source }
14
+
15
+ its(:environment) { should_not be_nil }
16
+
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,22 +1,25 @@
1
- require 'librarian'
1
+ require 'librarian/resolver'
2
+ require 'librarian/spec_change_set'
2
3
  require 'librarian/mock'
3
4
 
4
5
  module Librarian
5
6
  describe Resolver do
6
7
 
8
+ let(:env) { Mock::Environment.new }
9
+ let(:resolver) { env.resolver }
10
+
7
11
  context "a simple specfile" do
8
12
 
9
13
  it "should work" do
10
- Mock.registry :clear => true do
14
+ env.registry :clear => true do
11
15
  source 'source-1' do
12
16
  spec 'butter', '1.1'
13
17
  end
14
18
  end
15
- spec = Mock.dsl do
19
+ spec = env.dsl do
16
20
  src 'source-1'
17
21
  dep 'butter'
18
22
  end
19
- resolver = Mock.resolver
20
23
  resolution = resolver.resolve(spec)
21
24
  resolution.should be_correct
22
25
  end
@@ -26,7 +29,7 @@ module Librarian
26
29
  context "a specfile with a dep from one src depending on a dep from another src" do
27
30
 
28
31
  it "should work" do
29
- Mock.registry :clear => true do
32
+ env.registry :clear => true do
30
33
  source 'source-1' do
31
34
  spec 'butter', '1.1'
32
35
  end
@@ -36,13 +39,12 @@ module Librarian
36
39
  end
37
40
  end
38
41
  end
39
- spec = Mock.dsl do
42
+ spec = env.dsl do
40
43
  src 'source-1'
41
44
  src 'source-2' do
42
45
  dep 'jam'
43
46
  end
44
47
  end
45
- resolver = Mock.resolver
46
48
  resolution = resolver.resolve(spec)
47
49
  resolution.should be_correct
48
50
  end
@@ -52,18 +54,17 @@ module Librarian
52
54
  context "a specfile with a dep depending on a nonexistent dep" do
53
55
 
54
56
  it "should not work" do
55
- Mock.registry :clear => true do
57
+ env.registry :clear => true do
56
58
  source 'source-1' do
57
59
  spec 'jam', '1.2' do
58
60
  dependency 'butter', '>= 1.0'
59
61
  end
60
62
  end
61
63
  end
62
- spec = Mock.dsl do
64
+ spec = env.dsl do
63
65
  src 'source-1'
64
66
  dep 'jam'
65
67
  end
66
- resolver = Mock.resolver
67
68
  resolution = resolver.resolve(spec)
68
69
  resolution.should_not be_correct
69
70
  end
@@ -73,7 +74,7 @@ module Librarian
73
74
  context "a specfile with conflicting constraints" do
74
75
 
75
76
  it "should not work" do
76
- Mock.registry :clear => true do
77
+ env.registry :clear => true do
77
78
  source 'source-1' do
78
79
  spec 'butter', '1.0'
79
80
  spec 'butter', '1.1'
@@ -82,12 +83,11 @@ module Librarian
82
83
  end
83
84
  end
84
85
  end
85
- spec = Mock.dsl do
86
+ spec = env.dsl do
86
87
  src 'source-1'
87
88
  dep 'butter', '1.0'
88
89
  dep 'jam'
89
90
  end
90
- resolver = Mock.resolver
91
91
  resolution = resolver.resolve(spec)
92
92
  resolution.should_not be_correct
93
93
  end
@@ -97,7 +97,7 @@ module Librarian
97
97
  context "updating" do
98
98
 
99
99
  it "should not work" do
100
- Mock.registry :clear => true do
100
+ env.registry :clear => true do
101
101
  source 'source-1' do
102
102
  spec 'butter', '1.0'
103
103
  spec 'butter', '1.1'
@@ -106,24 +106,24 @@ module Librarian
106
106
  end
107
107
  end
108
108
  end
109
- first_spec = Mock.dsl do
109
+ first_spec = env.dsl do
110
110
  src 'source-1'
111
111
  dep 'butter', '1.1'
112
112
  dep 'jam'
113
113
  end
114
- first_resolution = Mock.resolver.resolve(first_spec)
114
+ first_resolution = resolver.resolve(first_spec)
115
115
  first_resolution.should be_correct
116
116
  first_manifests = first_resolution.manifests
117
117
  first_manifests_index = Hash[first_manifests.map{|m| [m.name, m]}]
118
118
  first_manifests_index['butter'].version.to_s.should == '1.1'
119
119
 
120
- second_spec = Mock.dsl do
120
+ second_spec = env.dsl do
121
121
  src 'source-1'
122
122
  dep 'butter', '1.0'
123
123
  dep 'jam'
124
124
  end
125
125
  locked_manifests = ManifestSet.deep_strip(first_manifests, ['butter'])
126
- second_resolution = Mock.resolver.resolve(second_spec, locked_manifests)
126
+ second_resolution =resolver.resolve(second_spec, locked_manifests)
127
127
  second_resolution.should be_correct
128
128
  second_manifests = second_resolution.manifests
129
129
  second_manifests_index = Hash[second_manifests.map{|m| [m.name, m]}]
@@ -135,7 +135,7 @@ module Librarian
135
135
  context "a change to the spec" do
136
136
 
137
137
  it "should work" do
138
- Mock.registry :clear => true do
138
+ env.registry :clear => true do
139
139
  source 'source-1' do
140
140
  spec 'butter', '1.0'
141
141
  end
@@ -143,22 +143,22 @@ module Librarian
143
143
  spec 'butter', '1.0'
144
144
  end
145
145
  end
146
- spec = Mock.dsl do
146
+ spec = env.dsl do
147
147
  src 'source-1'
148
148
  dep 'butter'
149
149
  end
150
- lock = Mock.resolver.resolve(spec)
150
+ lock = resolver.resolve(spec)
151
151
  lock.should be_correct
152
152
 
153
- spec = Mock.dsl do
153
+ spec = env.dsl do
154
154
  src 'source-1'
155
155
  dep 'butter', :src => 'source-2'
156
156
  end
157
- changes = Mock.spec_change_set(spec, lock)
157
+ changes = SpecChangeSet.new(env, spec, lock)
158
158
  changes.should_not be_same
159
159
  manifests = ManifestSet.new(changes.analyze).to_hash
160
160
  manifests.should_not have_key('butter')
161
- lock = Mock.resolver.resolve(spec, changes.analyze)
161
+ lock = resolver.resolve(spec, changes.analyze)
162
162
  lock.should be_correct
163
163
  lock.manifests.map{|m| m.name}.should include('butter')
164
164
  manifest = lock.manifests.find{|m| m.name == 'butter'}
@@ -1,31 +1,35 @@
1
1
  require 'librarian'
2
+ require 'librarian/spec_change_set'
2
3
  require 'librarian/mock'
3
4
 
4
5
  module Librarian
5
6
  describe SpecChangeSet do
6
7
 
8
+ let(:env) { Mock::Environment.new }
9
+ let(:resolver) { env.resolver }
10
+
7
11
  context "a simple root removal" do
8
12
 
9
13
  it "should work" do
10
- Mock.registry :clear => true do
14
+ env.registry :clear => true do
11
15
  source 'source-1' do
12
16
  spec 'butter', '1.0'
13
17
  spec 'jam', '1.0'
14
18
  end
15
19
  end
16
- spec = Mock.dsl do
20
+ spec = env.dsl do
17
21
  src 'source-1'
18
22
  dep 'butter'
19
23
  dep 'jam'
20
24
  end
21
- lock = Mock.resolver.resolve(spec)
25
+ lock = resolver.resolve(spec)
22
26
  lock.should be_correct
23
27
 
24
- spec = Mock.dsl do
28
+ spec = env.dsl do
25
29
  src 'source-1'
26
30
  dep 'jam'
27
31
  end
28
- changes = Mock.spec_change_set(spec, lock)
32
+ changes = described_class.new(env, spec, lock)
29
33
  changes.should_not be_same
30
34
 
31
35
  manifests = ManifestSet.new(changes.analyze).to_hash
@@ -38,25 +42,25 @@ module Librarian
38
42
  context "a simple root add" do
39
43
 
40
44
  it "should work" do
41
- Mock.registry :clear => true do
45
+ env.registry :clear => true do
42
46
  source 'source-1' do
43
47
  spec 'butter', '1.0'
44
48
  spec 'jam', '1.0'
45
49
  end
46
50
  end
47
- spec = Mock.dsl do
51
+ spec = env.dsl do
48
52
  src 'source-1'
49
53
  dep 'jam'
50
54
  end
51
- lock = Mock.resolver.resolve(spec)
55
+ lock = resolver.resolve(spec)
52
56
  lock.should be_correct
53
57
 
54
- spec = Mock.dsl do
58
+ spec = env.dsl do
55
59
  src 'source-1'
56
60
  dep 'butter'
57
61
  dep 'jam'
58
62
  end
59
- changes = Mock.spec_change_set(spec, lock)
63
+ changes = described_class.new(env, spec, lock)
60
64
  changes.should_not be_same
61
65
  manifests = ManifestSet.new(changes.analyze).to_hash
62
66
  manifests.should have_key('jam')
@@ -70,27 +74,27 @@ module Librarian
70
74
  context "when the change is consistent" do
71
75
 
72
76
  it "should work" do
73
- Mock.registry :clear => true do
77
+ env.registry :clear => true do
74
78
  source 'source-1' do
75
79
  spec 'butter', '1.0'
76
80
  spec 'jam', '1.0'
77
81
  spec 'jam', '1.1'
78
82
  end
79
83
  end
80
- spec = Mock.dsl do
84
+ spec = env.dsl do
81
85
  src 'source-1'
82
86
  dep 'butter'
83
87
  dep 'jam', '= 1.1'
84
88
  end
85
- lock = Mock.resolver.resolve(spec)
89
+ lock = resolver.resolve(spec)
86
90
  lock.should be_correct
87
91
 
88
- spec = Mock.dsl do
92
+ spec = env.dsl do
89
93
  src 'source-1'
90
94
  dep 'butter'
91
95
  dep 'jam', '>= 1.0'
92
96
  end
93
- changes = Mock.spec_change_set(spec, lock)
97
+ changes = described_class.new(env, spec, lock)
94
98
  changes.should_not be_same
95
99
  manifests = ManifestSet.new(changes.analyze).to_hash
96
100
  manifests.should have_key('butter')
@@ -102,27 +106,27 @@ module Librarian
102
106
  context "when the change is inconsistent" do
103
107
 
104
108
  it "should work" do
105
- Mock.registry :clear => true do
109
+ env.registry :clear => true do
106
110
  source 'source-1' do
107
111
  spec 'butter', '1.0'
108
112
  spec 'jam', '1.0'
109
113
  spec 'jam', '1.1'
110
114
  end
111
115
  end
112
- spec = Mock.dsl do
116
+ spec = env.dsl do
113
117
  src 'source-1'
114
118
  dep 'butter'
115
119
  dep 'jam', '= 1.0'
116
120
  end
117
- lock = Mock.resolver.resolve(spec)
121
+ lock = resolver.resolve(spec)
118
122
  lock.should be_correct
119
123
 
120
- spec = Mock.dsl do
124
+ spec = env.dsl do
121
125
  src 'source-1'
122
126
  dep 'butter'
123
127
  dep 'jam', '>= 1.1'
124
128
  end
125
- changes = Mock.spec_change_set(spec, lock)
129
+ changes = described_class.new(env, spec, lock)
126
130
  changes.should_not be_same
127
131
  manifests = ManifestSet.new(changes.analyze).to_hash
128
132
  manifests.should have_key('butter')
@@ -135,7 +139,7 @@ module Librarian
135
139
 
136
140
  context "a simple root source change" do
137
141
  it "should work" do
138
- Mock.registry :clear => true do
142
+ env.registry :clear => true do
139
143
  source 'source-1' do
140
144
  spec 'butter', '1.0'
141
145
  end
@@ -143,18 +147,18 @@ module Librarian
143
147
  spec 'butter', '1.0'
144
148
  end
145
149
  end
146
- spec = Mock.dsl do
150
+ spec = env.dsl do
147
151
  src 'source-1'
148
152
  dep 'butter'
149
153
  end
150
- lock = Mock.resolver.resolve(spec)
154
+ lock = resolver.resolve(spec)
151
155
  lock.should be_correct
152
156
 
153
- spec = Mock.dsl do
157
+ spec = env.dsl do
154
158
  src 'source-1'
155
159
  dep 'butter', :src => 'source-2'
156
160
  end
157
- changes = Mock.spec_change_set(spec, lock)
161
+ changes = described_class.new(env, spec, lock)
158
162
  changes.should_not be_same
159
163
  manifests = ManifestSet.new(changes.analyze).to_hash
160
164
  manifests.should_not have_key('butter')