cfoundry 0.5.3.rc4 → 0.5.3.rc5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/cfoundry/v1/base.rb +33 -14
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cfoundry/v1/base_spec.rb +38 -0
- metadata +4 -4
data/lib/cfoundry/v1/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "multi_json"
|
2
|
+
require "tmpdir"
|
2
3
|
|
3
4
|
require "cfoundry/baseclient"
|
4
5
|
require "cfoundry/uaaclient"
|
@@ -50,22 +51,40 @@ module CFoundry::V1
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def upload_app(name, zipfile = nil, resources = [])
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
zipfile
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
54
|
+
use_or_create_empty_zipfile(zipfile) do |zipfile|
|
55
|
+
payload = {
|
56
|
+
:_method => "put",
|
57
|
+
:resources => MultiJson.dump(resources),
|
58
|
+
:application =>
|
59
|
+
UploadIO.new(
|
60
|
+
if zipfile.is_a? File
|
61
|
+
zipfile
|
62
|
+
elsif zipfile.is_a? String
|
63
|
+
File.new(zipfile, "rb")
|
64
|
+
end,
|
65
|
+
"application/zip")
|
66
|
+
}
|
67
|
+
|
68
|
+
post("apps", name, "application", :payload => payload)
|
69
|
+
end
|
67
70
|
rescue EOFError
|
68
71
|
retry
|
69
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def use_or_create_empty_zipfile(zipfile)
|
77
|
+
Dir.mktmpdir do |working_dir|
|
78
|
+
zip_path = "#{working_dir}/empty_zip.zip"
|
79
|
+
|
80
|
+
zipfile ||= Dir.mktmpdir do |zip_dir|
|
81
|
+
File.new("#{zip_dir}/.__empty_file", "wb").close
|
82
|
+
CFoundry::Zip.pack(zip_dir, zip_path)
|
83
|
+
zip_path
|
84
|
+
end
|
85
|
+
|
86
|
+
yield zipfile
|
87
|
+
end
|
88
|
+
end
|
70
89
|
end
|
71
90
|
end
|
data/lib/cfoundry/version.rb
CHANGED
@@ -55,4 +55,42 @@ describe CFoundry::V1::Base do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
describe "#upload_app" do
|
60
|
+
let!(:stubbed_request) do
|
61
|
+
stub_request(:post, 'https://api.cloudfoundry.com/apps/app_name/application').to_return(:status => 200).with(:body => /#{expected_zipfile}/)
|
62
|
+
end
|
63
|
+
|
64
|
+
subject { base.upload_app("app_name", zipfile)}
|
65
|
+
|
66
|
+
context "when passed a falsy zipfile" do
|
67
|
+
let(:zipfile) { false }
|
68
|
+
let(:expected_zipfile) { "empty.zip" }
|
69
|
+
|
70
|
+
it "creates a temporary empty zipfile" do
|
71
|
+
subject
|
72
|
+
|
73
|
+
stubbed_request.should have_been_requested
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when passed a valid zipfile" do
|
78
|
+
let(:zipfile) { "proper-zipfile.zip" }
|
79
|
+
let(:expected_zipfile) { zipfile }
|
80
|
+
|
81
|
+
before do
|
82
|
+
File.new(zipfile, "wb")
|
83
|
+
end
|
84
|
+
|
85
|
+
after do
|
86
|
+
FileUtils.rm(zipfile)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "uses that zipfile" do
|
90
|
+
subject
|
91
|
+
|
92
|
+
stubbed_request.should have_been_requested
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
58
96
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfoundry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -
|
4
|
+
hash: -2049338452
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
9
|
- 3
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 0.5.3.
|
11
|
+
- 5
|
12
|
+
version: 0.5.3.rc5
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Cloud Foundry Team
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2013-03-
|
21
|
+
date: 2013-03-14 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|