cfoundry 1.5.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/lib/cfoundry/test_support.rb +2 -2
  2. data/lib/cfoundry/v2/app.rb +3 -6
  3. data/lib/cfoundry/v2/model.rb +1 -0
  4. data/lib/cfoundry/version.rb +1 -1
  5. data/spec/cfoundry/client_spec.rb +1 -1
  6. data/spec/cfoundry/rest_client_spec.rb +1 -1
  7. data/spec/cfoundry/trace_helpers_spec.rb +6 -6
  8. data/spec/cfoundry/upload_helpers_spec.rb +125 -137
  9. data/spec/cfoundry/v2/app_event_spec.rb +63 -59
  10. data/spec/cfoundry/v2/app_spec.rb +195 -188
  11. data/spec/cfoundry/v2/client_spec.rb +60 -56
  12. data/spec/cfoundry/v2/domain_spec.rb +9 -6
  13. data/spec/cfoundry/v2/model_magic/model_magic/attribute_spec.rb +89 -88
  14. data/spec/cfoundry/v2/model_magic/model_magic/has_summary_spec.rb +12 -13
  15. data/spec/cfoundry/v2/model_magic/model_magic/to_many_spec.rb +46 -52
  16. data/spec/cfoundry/v2/model_magic/model_magic/to_one_spec.rb +96 -87
  17. data/spec/cfoundry/v2/model_spec.rb +236 -241
  18. data/spec/cfoundry/v2/organization_spec.rb +20 -22
  19. data/spec/cfoundry/v2/quota_definition_spec.rb +45 -47
  20. data/spec/cfoundry/v2/route_spec.rb +28 -25
  21. data/spec/cfoundry/v2/space_spec.rb +9 -11
  22. data/spec/cfoundry/validator_spec.rb +69 -67
  23. data/spec/factories/app_events_factory.rb +7 -0
  24. data/spec/factories/apps_factory.rb +11 -0
  25. data/spec/factories/clients_factory.rb +5 -0
  26. data/spec/factories/domains_factory.rb +7 -0
  27. data/spec/factories/organizations_factory.rb +11 -0
  28. data/spec/factories/quota_definitions_factory.rb +8 -0
  29. data/spec/factories/routes_factory.rb +10 -0
  30. data/spec/factories/spaces_factory.rb +10 -0
  31. data/spec/factories/users_factory.rb +10 -0
  32. data/spec/spec_helper.rb +5 -4
  33. data/spec/support/factory_girl.rb +6 -0
  34. data/spec/support/shared_examples/model_summary_examples.rb +7 -7
  35. data/spec/support/test_model_builder.rb +10 -0
  36. metadata +83 -71
  37. data/spec/fakes/app_fake.rb +0 -5
  38. data/spec/fakes/domain_fake.rb +0 -5
  39. data/spec/fakes/framework_fake.rb +0 -5
  40. data/spec/fakes/organization_fake.rb +0 -5
  41. data/spec/fakes/route_fake.rb +0 -5
  42. data/spec/fakes/runtime_fake.rb +0 -5
  43. data/spec/fakes/service_fake.rb +0 -5
  44. data/spec/fakes/service_instance_fake.rb +0 -5
  45. data/spec/fakes/service_plan_fake.rb +0 -5
  46. data/spec/fakes/space_fake.rb +0 -5
  47. data/spec/fakes/user_fake.rb +0 -5
  48. data/spec/support/fake_helper.rb +0 -248
  49. data/spec/support/randoms.rb +0 -3
@@ -1,3 +1,3 @@
1
- Dir[File.expand_path('../../../spec/{support,fakes}/**/*.rb', __FILE__)].each do |file|
2
- require file
1
+ Dir[File.expand_path('../../../spec/{support}/**/*.rb', __FILE__)].each do |file|
2
+ require file unless file =~ /factory_girl/
3
3
  end
@@ -31,7 +31,7 @@ module CFoundry::V2
31
31
  attribute :debug, :string, :default => nil
32
32
  to_many :service_bindings
33
33
  to_many :routes
34
- to_many :app_events
34
+ to_many :events, :as => :app_event
35
35
 
36
36
  scoped_to_space
37
37
 
@@ -47,11 +47,8 @@ module CFoundry::V2
47
47
 
48
48
  private :environment_json
49
49
 
50
- alias :events :app_events
51
- alias :events= :app_events=
52
-
53
- def delete!
54
- super({:recursive => true})
50
+ def delete!(opts = {})
51
+ super(opts.merge(:recursive => true))
55
52
  end
56
53
 
57
54
  def instances
@@ -21,6 +21,7 @@ module CFoundry::V2
21
21
  end
22
22
 
23
23
  attr_accessor :guid, :cache, :changes
24
+ attr_reader :diff
24
25
 
25
26
  def initialize(guid, client, manifest = nil, partial = false)
26
27
  @guid = guid
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "1.5.3".freeze
3
+ VERSION = "2.0.0".freeze
4
4
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe CFoundry::Client do
4
4
  before do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe CFoundry::RestClient do
4
4
  let(:token) { nil }
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe CFoundry::TraceHelpers do
4
- let(:fake_class) { Class.new { include CFoundry::TraceHelpers } }
4
+ let(:tracehelper_test_class) { Class.new { include CFoundry::TraceHelpers } }
5
5
  let(:request) do
6
6
  {
7
7
  :method => "GET",
@@ -21,7 +21,7 @@ describe CFoundry::TraceHelpers do
21
21
  before { response[:body] = response_body }
22
22
 
23
23
  it "traces the provided response" do
24
- fake_class.new.response_trace(response).should == response_trace
24
+ tracehelper_test_class.new.response_trace(response).should == response_trace
25
25
  end
26
26
  end
27
27
 
@@ -30,7 +30,7 @@ describe CFoundry::TraceHelpers do
30
30
  let(:header_trace) { "REQUEST_HEADERS:\n accept : */*\n bb-foo : bar" }
31
31
  let(:body_trace) { "" }
32
32
 
33
- subject { fake_class.new.request_trace(request) }
33
+ subject { tracehelper_test_class.new.request_trace(request) }
34
34
 
35
35
  context "without a request body" do
36
36
  include_examples "request_trace tests"
@@ -45,7 +45,7 @@ describe CFoundry::TraceHelpers do
45
45
  end
46
46
 
47
47
  it "returns nil if request is nil" do
48
- fake_class.new.request_trace(nil).should == nil
48
+ tracehelper_test_class.new.request_trace(nil).should == nil
49
49
  end
50
50
  end
51
51
 
@@ -66,7 +66,7 @@ describe CFoundry::TraceHelpers do
66
66
  end
67
67
 
68
68
  it "returns nil if response is nil" do
69
- fake_class.new.response_trace(nil).should == nil
69
+ tracehelper_test_class.new.response_trace(nil).should == nil
70
70
  end
71
71
  end
72
72
  end
@@ -1,194 +1,182 @@
1
1
  require "spec_helper"
2
2
 
3
- describe CFoundry::UploadHelpers do
4
- describe '#upload' do
5
- let(:base) { Object.new }
6
- let(:guid) { "123" }
7
- let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_cfignore" }
8
- let(:check_resources) { false }
9
- let(:tmpdir) { "#{SPEC_ROOT}/tmp/fake_tmpdir" }
10
-
11
- let(:client) do
12
- client = Object.new
13
- stub(client).base { base }
14
- client
15
- end
3
+ class TestModelWithUploadHelpers < CFoundry::V2::Model
4
+ include CFoundry::UploadHelpers
5
+ end
16
6
 
17
- let(:fake_model) do
18
- class FakeModel
19
- include CFoundry::UploadHelpers
7
+ module CFoundry
8
+ describe UploadHelpers do
9
+ describe "#upload" do
10
+ def relative_glob(dir)
11
+ base_pathname = Pathname.new(dir)
12
+ Dir["#{dir}/**/{*,.[^\.]*}"].map do |file|
13
+ Pathname.new(file).relative_path_from(base_pathname).to_s
14
+ end
15
+ end
20
16
 
21
- def initialize(client, guid)
22
- @client = client
23
- @guid = guid
17
+ def mock_zip(*args, &block)
18
+ if args.empty?
19
+ mock(CFoundry::Zip).pack.with_any_args(&block)
20
+ else
21
+ mock(CFoundry::Zip).pack(*args, &block)
24
22
  end
25
23
  end
26
24
 
27
- FakeModel.new(client, guid)
28
- end
25
+ let(:base) { Object.new }
26
+ let(:guid) { "123" }
27
+ let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_cfignore" }
28
+ let(:check_resources) { false }
29
+ let(:tmpdir) { "#{SPEC_ROOT}/tmp/fake_tmpdir" }
29
30
 
30
- before do
31
- FileUtils.rm_rf tmpdir
31
+ let(:client) { build(:client) }
32
32
 
33
- stub(Dir).tmpdir do
34
- FileUtils.mkdir_p tmpdir
35
- tmpdir
36
- end
33
+ let(:model) { TestModelWithUploadHelpers.new(guid, client) }
37
34
 
38
- stub(base).upload_app.with_any_args
39
- end
35
+ before do
36
+ stub(client).base { base }
37
+ stub(base).upload_app.with_any_args
40
38
 
41
- subject { fake_model.upload(path, check_resources) }
42
-
43
- def relative_glob(dir)
44
- base_pathname = Pathname.new(dir)
45
- Dir["#{dir}/**/{*,.[^\.]*}"].map do |file|
46
- Pathname.new(file).relative_path_from(base_pathname).to_s
39
+ FileUtils.rm_rf tmpdir
40
+ stub(Dir).tmpdir do
41
+ FileUtils.mkdir_p tmpdir
42
+ tmpdir
43
+ end
47
44
  end
48
- end
49
45
 
50
- def mock_zip(*args, &block)
51
- if args.empty?
52
- mock(CFoundry::Zip).pack.with_any_args(&block)
53
- else
54
- mock(CFoundry::Zip).pack(*args, &block)
46
+ it "zips the app and uploads the zip file" do
47
+ zip_path = "#{tmpdir}/#{guid}.zip"
48
+ mock_zip(anything, zip_path) { true }
49
+ mock(base).upload_app(guid, zip_path, [])
50
+ model.upload(path, check_resources)
55
51
  end
56
- end
57
-
58
- it 'zips the app and uploads the zip file' do
59
- zip_path = "#{tmpdir}/#{guid}.zip"
60
- mock_zip(anything, zip_path) { true }
61
- mock(base).upload_app(guid, zip_path, [])
62
- subject
63
- end
64
52
 
65
- it 'uploads an app with the right guid' do
66
- mock_zip
67
- mock(base).upload_app(guid, anything, anything)
68
- subject
69
- end
53
+ it "uploads an app with the right guid" do
54
+ mock_zip
55
+ mock(base).upload_app(guid, anything, anything)
56
+ model.upload(path, check_resources)
57
+ end
70
58
 
71
- it 'uses a unique directory name when it copies the app' do
72
- mock_zip(/#{tmpdir}.*#{guid}.*/, anything)
73
- subject
74
- end
59
+ it "uses a unique directory name when it copies the app" do
60
+ mock_zip(/#{tmpdir}.*#{guid}.*/, anything)
61
+ model.upload(path, check_resources)
62
+ end
75
63
 
76
- it 'cleans up after itself correctly' do
77
- subject
78
- expect(relative_glob(tmpdir)).to be_empty
79
- end
64
+ it "cleans up after itself correctly" do
65
+ model.upload(path, check_resources)
66
+ expect(relative_glob(tmpdir)).to be_empty
67
+ end
80
68
 
81
- it 'includes the source files of the app in the zip file' do
82
- mock_zip do |src, _|
83
- files = relative_glob(src)
84
- expect(files).to include "non_ignored_dir"
85
- expect(files).to include "non_ignored_file.txt"
86
- expect(files).to include "non_ignored_dir/file_in_non_ignored_dir.txt"
69
+ it "includes the source files of the app in the zip file" do
70
+ mock_zip do |src, _|
71
+ files = relative_glob(src)
72
+ expect(files).to include "non_ignored_dir"
73
+ expect(files).to include "non_ignored_file.txt"
74
+ expect(files).to include "non_ignored_dir/file_in_non_ignored_dir.txt"
75
+ end
76
+ model.upload(path, check_resources)
87
77
  end
88
- subject
89
- end
90
78
 
91
- it 'includes hidden files (though stager ignores them currently)' do
92
- mock_zip do |src, _|
93
- expect(relative_glob(src)).to include ".hidden_file"
79
+ it "includes hidden files (though stager ignores them currently)" do
80
+ mock_zip do |src, _|
81
+ expect(relative_glob(src)).to include ".hidden_file"
82
+ end
83
+ model.upload(path, check_resources)
94
84
  end
95
- subject
96
- end
97
85
 
98
- it 'does not include files and directories specified in the cfignore' do
99
- mock_zip do |src, _|
100
- files = relative_glob(src)
101
- expect(files).to match_array(%w[
86
+ it "does not include files and directories specified in the cfignore" do
87
+ mock_zip do |src, _|
88
+ files = relative_glob(src)
89
+ expect(files).to match_array(%w[
102
90
  .hidden_file .cfignore non_ignored_dir ambiguous_ignored
103
91
  non_ignored_dir/file_in_non_ignored_dir.txt non_ignored_file.txt
104
92
  non_ignored_dir/toplevel_ignored.txt
105
93
  ])
94
+ end
95
+ model.upload(path, check_resources)
106
96
  end
107
- subject
108
- end
109
97
 
110
- %w(.git _darcs .svn).each do |source_control_dir_name|
111
- context "when there is a #{source_control_dir_name} directory in the app" do
112
- before { FileUtils.mkdir_p("#{path}/#{source_control_dir_name}") }
98
+ %w(.git _darcs .svn).each do |source_control_dir_name|
99
+ context "when there is a #{source_control_dir_name} directory in the app" do
100
+ before { FileUtils.mkdir_p("#{path}/#{source_control_dir_name}") }
113
101
 
114
- it "ignores that directory" do
115
- mock_zip do |src, _|
116
- expect(relative_glob(src)).not_to include source_control_dir_name
102
+ it "ignores that directory" do
103
+ mock_zip do |src, _|
104
+ expect(relative_glob(src)).not_to include source_control_dir_name
105
+ end
106
+ model.upload(path, check_resources)
117
107
  end
118
- subject
119
108
  end
120
109
  end
121
- end
122
110
 
123
- context 'when there are no files to zip' do
124
- before { mock_zip { false } }
111
+ context "when there are no files to zip" do
112
+ before { mock_zip { false } }
125
113
 
126
- it 'passes `false` to #upload_app' do
127
- mock(base).upload_app(guid, false, [])
128
- subject
114
+ it "passes `false` to #upload_app" do
115
+ mock(base).upload_app(guid, false, [])
116
+ model.upload(path, check_resources)
117
+ end
129
118
  end
130
- end
131
119
 
132
- context 'when all files match existing resources' do
133
- context 'and there are directories' do
134
- let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_nested_directories" }
120
+ context "when all files match existing resources" do
121
+ context "and there are directories" do
122
+ let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_nested_directories" }
135
123
 
136
- it 'prunes them before zipping' do
137
- stub(fake_model).make_fingerprints(anything) do
138
- [[], CFoundry::UploadHelpers::RESOURCE_CHECK_LIMIT + 1]
139
- end
140
-
141
- stub(base).resource_match(anything) do
142
- %w{ xyz foo/bar/baz/fizz }.map do |path|
143
- { :fn => "#{tmpdir}/.cf_#{guid}_files/#{path}" }
124
+ it "prunes them before zipping" do
125
+ stub(model).make_fingerprints(anything) do
126
+ [[], CFoundry::UploadHelpers::RESOURCE_CHECK_LIMIT + 1]
144
127
  end
145
- end
146
128
 
147
- mock(base).upload_app(anything, false, anything)
129
+ stub(base).resource_match(anything) do
130
+ %w{ xyz foo/bar/baz/fizz }.map do |path|
131
+ {:fn => "#{tmpdir}/.cf_#{guid}_files/#{path}"}
132
+ end
133
+ end
148
134
 
149
- fake_model.upload(path)
135
+ mock(base).upload_app(anything, false, anything)
136
+ model.upload(path)
137
+ end
150
138
  end
151
139
  end
152
- end
153
140
 
154
- context "when only dotfiles don't match existing resources" do
155
- let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_dotfiles" }
141
+ context "when only dotfiles don't match existing resources" do
142
+ let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_dotfiles" }
156
143
 
157
- it 'does not prune them' do
158
- stub(fake_model).make_fingerprints(anything) do
159
- [[], CFoundry::UploadHelpers::RESOURCE_CHECK_LIMIT + 1]
160
- end
144
+ it "does not prune them" do
145
+ stub(model).make_fingerprints(anything) do
146
+ [[], CFoundry::UploadHelpers::RESOURCE_CHECK_LIMIT + 1]
147
+ end
161
148
 
162
- stub(base).resource_match(anything) do
163
- %w{ xyz }.map do |path|
164
- { :fn => "#{tmpdir}/.cf_#{guid}_files/#{path}" }
149
+ stub(base).resource_match(anything) do
150
+ %w{ xyz }.map do |path|
151
+ {:fn => "#{tmpdir}/.cf_#{guid}_files/#{path}"}
152
+ end
165
153
  end
166
- end
167
154
 
168
- mock(base).upload_app(anything, anything, anything) do |_, zip, _|
169
- expect(zip).to be_a(String)
170
- end
155
+ mock(base).upload_app(anything, anything, anything) do |_, zip, _|
156
+ expect(zip).to be_a(String)
157
+ end
171
158
 
172
- fake_model.upload(path)
159
+ model.upload(path)
160
+ end
173
161
  end
174
- end
175
162
 
176
- context "when there is a symlink pointing outside of the root" do
177
- let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_external_symlink" }
163
+ context "when there is a symlink pointing outside of the root" do
164
+ let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_external_symlink" }
178
165
 
179
- it "blows up" do
180
- expect {
181
- fake_model.upload(path)
182
- }.to raise_error(CFoundry::Error, /contains links.*that point outside/)
183
- end
166
+ it "blows up" do
167
+ expect {
168
+ model.upload(path)
169
+ }.to raise_error(CFoundry::Error, /contains links.*that point outside/)
170
+ end
184
171
 
185
- context "and it is cfignored" do
186
- let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_ignored_external_symlink" }
172
+ context "and it is cfignored" do
173
+ let(:path) { "#{SPEC_ROOT}/fixtures/apps/with_ignored_external_symlink" }
187
174
 
188
- it "ignores it" do
189
- expect { fake_model.upload(path) }.to_not raise_error
175
+ it "ignores it" do
176
+ expect { model.upload(path) }.to_not raise_error
177
+ end
190
178
  end
191
179
  end
192
180
  end
193
181
  end
194
- end
182
+ end
@@ -1,77 +1,81 @@
1
1
  require "spec_helper"
2
2
 
3
- describe CFoundry::V2::AppEvent do
4
- let(:client) { fake_client }
3
+ module CFoundry
4
+ module V2
5
+ describe AppEvent do
6
+ let(:app) { build(:app) }
7
+ let(:app_event) { build(:app_event, :app => app) }
5
8
 
6
- let(:app) { fake :app }
7
-
8
- subject { described_class.new("app-event-1", client) }
9
-
10
- it "has an app" do
11
- subject.app = app
12
- expect(subject.app).to eq(app)
13
- end
9
+ it "has an app" do
10
+ expect(app_event.app).to eq(app)
11
+ end
14
12
 
15
- describe "#instance_guid" do
16
- it "has an instance guid" do
17
- subject.instance_guid = "foo"
18
- expect(subject.instance_guid).to eq("foo")
19
- end
13
+ describe "#instance_guid" do
14
+ it "has an instance guid" do
15
+ app_event.instance_guid = "foo"
16
+ expect(app_event.instance_guid).to eq("foo")
17
+ end
20
18
 
21
- context "when an invalid value is assigned" do
22
- it "raises a Mismatch exception" do
23
- expect {
24
- subject.instance_guid = 123
25
- }.to raise_error(CFoundry::Mismatch)
19
+ context "when an invalid value is assigned" do
20
+ it "raises a Mismatch exception" do
21
+ expect {
22
+ app_event.instance_guid = 123
23
+ }.to raise_error(Mismatch)
24
+ end
25
+ end
26
26
  end
27
- end
28
- end
29
27
 
30
- describe "#instance_index" do
31
- it "has an instance index" do
32
- subject.instance_index = 123
33
- expect(subject.instance_index).to eq(123)
34
- end
28
+ describe "#instance_index" do
29
+ it "has an instance index" do
30
+ app_event.instance_index = 123
31
+ expect(app_event.instance_index).to eq(123)
32
+ end
35
33
 
36
- context "when an invalid value is assigned" do
37
- it "raises a Mismatch exception" do
38
- expect {
39
- subject.instance_index = "wrong"
40
- }.to raise_error(CFoundry::Mismatch)
34
+ context "when an invalid value is assigned" do
35
+ it "raises a Mismatch exception" do
36
+ expect {
37
+ app_event.instance_index = "wrong"
38
+ }.to raise_error(Mismatch)
39
+ end
40
+ end
41
41
  end
42
- end
43
- end
44
42
 
45
- describe "#exit_status" do
46
- it "has an instance index" do
47
- subject.exit_status = 123
48
- expect(subject.exit_status).to eq(123)
49
- end
43
+ describe "#exit_status" do
44
+ it "has an instance index" do
45
+ app_event.exit_status = 123
46
+ expect(app_event.exit_status).to eq(123)
47
+ end
50
48
 
51
- context "when an invalid value is assigned" do
52
- it "raises a Mismatch exception" do
53
- expect {
54
- subject.exit_status = "wrong"
55
- }.to raise_error(CFoundry::Mismatch)
49
+ context "when an invalid value is assigned" do
50
+ it "raises a Mismatch exception" do
51
+ expect {
52
+ app_event.exit_status = "wrong"
53
+ }.to raise_error(Mismatch)
54
+ end
55
+ end
56
56
  end
57
- end
58
- end
59
57
 
60
- describe "#exit_description" do
61
- it "defaults to an empty string" do
62
- expect(subject.fake.exit_description).to eq("")
63
- end
58
+ describe "#exit_description" do
59
+ before do
60
+ stub_request(:get, /v2\/app_events\/.*/).to_return(:body => {:entity => {}}.to_json)
61
+ end
64
62
 
65
- it "has an instance guid" do
66
- subject.exit_description = "foo"
67
- expect(subject.exit_description).to eq("foo")
68
- end
63
+ it "defaults to an empty string" do
64
+ expect(app_event.exit_description).to eq("")
65
+ end
66
+
67
+ it "has an instance guid" do
68
+ app_event.exit_description = "foo"
69
+ expect(app_event.exit_description).to eq("foo")
70
+ end
69
71
 
70
- context "when an invalid value is assigned" do
71
- it "raises a Mismatch exception" do
72
- expect {
73
- subject.exit_description = 123
74
- }.to raise_error(CFoundry::Mismatch)
72
+ context "when an invalid value is assigned" do
73
+ it "raises a Mismatch exception" do
74
+ expect {
75
+ app_event.exit_description = 123
76
+ }.to raise_error(Mismatch)
77
+ end
78
+ end
75
79
  end
76
80
  end
77
81
  end