travis-packagecloud-ruby 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ {"deb":[{"display_name":"Ubuntu","index_name":"ubuntu","versions":[{"id":1,"display_name":"4.10 Warty Warthog","index_name":"warty","version_number":"4.10"},{"id":2,"display_name":"5.04 Hoary Hedgehog","index_name":"hoary","version_number":"5.04"},{"id":3,"display_name":"5.10 Breezy Badger","index_name":"breezy","version_number":"5.10"},{"id":4,"display_name":"6.06 LTS Dapper Drake","index_name":"dapper","version_number":"6.06"},{"id":5,"display_name":"6.10 Edgy Eft","index_name":"edgy","version_number":"6.10"},{"id":6,"display_name":"7.04 Feisty Fawn","index_name":"feisty","version_number":"7.04"},{"id":7,"display_name":"7.10 Gutsy Gibbon","index_name":"gutsy","version_number":"7.10"},{"id":8,"display_name":"8.04 LTS Hardy Heron","index_name":"hardy","version_number":"8.04"},{"id":9,"display_name":"8.10 Intrepid Ibex","index_name":"intrepid","version_number":"8.10"},{"id":10,"display_name":"9.04 Jaunty Jackalope","index_name":"jaunty","version_number":"9.04"},{"id":11,"display_name":"9.10 Karmic Koala","index_name":"karmic","version_number":"9.10"},{"id":12,"display_name":"10.04 LTS Lucid Lynx","index_name":"lucid","version_number":"10.04"},{"id":13,"display_name":"10.10 Maverick Meerkat","index_name":"maverick","version_number":"10.10"},{"id":14,"display_name":"11.04 Natty Narwhal","index_name":"natty","version_number":"11.04"},{"id":15,"display_name":"11.10 Oneiric Ocelot","index_name":"oneiric","version_number":"11.10"},{"id":16,"display_name":"12.04 LTS Precise Pangolin","index_name":"precise","version_number":"12.04"},{"id":17,"display_name":"12.10 Quantal Quetzal","index_name":"quantal","version_number":"12.10"},{"id":18,"display_name":"13.04 Raring Ringtail","index_name":"raring","version_number":"13.04"},{"id":19,"display_name":"13.10 Saucy Salamander","index_name":"saucy","version_number":"13.10"},{"id":20,"display_name":"14.04 LTS Trusty Tahr","index_name":"trusty","version_number":"14.04"},{"id":142,"display_name":"14.10 Utopic Unicorn","index_name":"utopic","version_number":"14.10"},{"id":148,"display_name":"15.04 Vivid Vervet","index_name":"vivid","version_number":"15.04"},{"id":152,"display_name":"15.10 Wily Werewolf","index_name":"wily","version_number":"15.10"},{"id":165,"display_name":"16.04 LTS Xenial Xerus","index_name":"xenial","version_number":"16.04"},{"id":168,"display_name":"16.10 Yakkety Yak","index_name":"yakkety","version_number":"16.10"},{"id":183,"display_name":"17.04 Zesty Zapus","index_name":"zesty","version_number":"17.04"},{"id":187,"display_name":"17.10 Artful Aardvark","index_name":"artful","version_number":"17.10"},{"id":190,"display_name":"18.04 LTS Bionic Beaver","index_name":"bionic","version_number":"18.04"}]},{"display_name":"Debian","index_name":"debian","versions":[{"id":21,"display_name":"4.0 etch","index_name":"etch","version_number":"4.0"},{"id":22,"display_name":"5.0 lenny","index_name":"lenny","version_number":"5.0"},{"id":23,"display_name":"6.0 squeeze","index_name":"squeeze","version_number":"6.0"},{"id":24,"display_name":"7 wheezy","index_name":"wheezy","version_number":"7.0"},{"id":25,"display_name":"8 jessie","index_name":"jessie","version_number":"8.0"},{"id":149,"display_name":"9 stretch","index_name":"stretch","version_number":"9.0"},{"id":150,"display_name":"10 buster","index_name":"buster","version_number":"10.0"}]},{"display_name":"Any deb-based distribution.","index_name":"any","versions":[{"id":35,"display_name":"Any version.","index_name":"any","version_number":null}]},{"display_name":"LinuxMint","index_name":"linuxmint","versions":[{"id":157,"display_name":"16 petra","index_name":"petra","version_number":"16"},{"id":158,"display_name":"17 qiana","index_name":"qiana","version_number":"17"},{"id":159,"display_name":"17.1 rebecca","index_name":"rebecca","version_number":"17.1"},{"id":160,"display_name":"17.2 rafaela","index_name":"rafaela","version_number":"17.2"},{"id":161,"display_name":"17.3 rosa","index_name":"rosa","version_number":"17.3"},{"id":170,"display_name":"18 sarah","index_name":"sarah","version_number":"18"},{"id":180,"display_name":"18.1 serena","index_name":"serena","version_number":"18.1"},{"id":185,"display_name":"18.2 sonya","index_name":"sonya","version_number":"18.2"},{"id":189,"display_name":"18.3 sylvia","index_name":"sylvia","version_number":"18.3"}]},{"display_name":"Raspbian","index_name":"raspbian","versions":[{"id":153,"display_name":"7 wheezy","index_name":"wheezy","version_number":"7.0"},{"id":154,"display_name":"8 jessie","index_name":"jessie","version_number":"8.0"},{"id":155,"display_name":"9 stretch","index_name":"stretch","version_number":"9.0"},{"id":156,"display_name":"10 buster","index_name":"buster","version_number":"10.0"}]},{"display_name":"elementary OS","index_name":"elementaryos","versions":[{"id":162,"display_name":"0.1 jupiter","index_name":"jupiter","version_number":"0.1"},{"id":163,"display_name":"0.2 luna","index_name":"luna","version_number":"0.2"},{"id":164,"display_name":"0.3 freya","index_name":"freya","version_number":"0.3"}]}],"rpm":[{"display_name":"Enterprise Linux","index_name":"el","versions":[{"id":26,"display_name":"Enterprise Linux 5.0","index_name":"5","version_number":"5.0"},{"id":27,"display_name":"Enterprise Linux 6.0","index_name":"6","version_number":"6.0"},{"id":140,"display_name":"Enterprise Linux 7.0","index_name":"7","version_number":"7.0"}]},{"display_name":"Fedora","index_name":"fedora","versions":[{"id":28,"display_name":"14 Laughlin","index_name":"14","version_number":"14.0"},{"id":29,"display_name":"15 Lovelock","index_name":"15","version_number":"15.0"},{"id":30,"display_name":"16 Verne","index_name":"16","version_number":"16.0"},{"id":31,"display_name":"17 Beefy Miracle","index_name":"17","version_number":"17.0"},{"id":32,"display_name":"18 Spherical Cow","index_name":"18","version_number":"18.0"},{"id":33,"display_name":"19 Schrödinger's Cat","index_name":"19","version_number":"19.0"},{"id":34,"display_name":"20 Heisenbug","index_name":"20","version_number":"20.0"},{"id":143,"display_name":"21 Fedora 21","index_name":"21","version_number":"21.0"},{"id":147,"display_name":"22 Fedora 22","index_name":"22","version_number":"22.0"},{"id":151,"display_name":"23 Fedora 23","index_name":"23","version_number":"23.0"},{"id":169,"display_name":"24 Fedora 24","index_name":"24","version_number":"24.0"},{"id":179,"display_name":"25 Fedora 25","index_name":"25","version_number":"25.0"},{"id":184,"display_name":"26 Fedora 26","index_name":"26","version_number":"26.0"},{"id":188,"display_name":"27 Fedora 27","index_name":"27","version_number":"27.0"}]},{"display_name":"Scientific Linux","index_name":"scientific","versions":[{"id":138,"display_name":"Scientific Linux 5.0","index_name":"5","version_number":"5.0"},{"id":139,"display_name":"Scientific Linux 6.0","index_name":"6","version_number":"6.0"},{"id":141,"display_name":"Scientific Linux 7.0","index_name":"7","version_number":"7.0"}]},{"display_name":"Oracle Linux","index_name":"ol","versions":[{"id":144,"display_name":"Oracle Linux 5.0","index_name":"5","version_number":"5.0"},{"id":145,"display_name":"Oracle Linux 6.0","index_name":"6","version_number":"6.0"},{"id":146,"display_name":"Oracle Linux 7.0","index_name":"7","version_number":"7.0"}]},{"display_name":"poky (Yocto Project Reference Distribution)","index_name":"poky","versions":[{"id":171,"display_name":"2.0 Jethro","index_name":"jethro","version_number":"2.0"},{"id":172,"display_name":"2.1 Krogoth","index_name":"krogoth","version_number":"2.1"}]},{"display_name":"openSUSE","index_name":"opensuse","versions":[{"id":173,"display_name":"openSUSE 13.1","index_name":"13.1","version_number":"13.1"},{"id":174,"display_name":"openSUSE 13.2","index_name":"13.2","version_number":"13.2"},{"id":175,"display_name":"openSUSE Leap 42.1","index_name":"42.1","version_number":"42.1"},{"id":181,"display_name":"openSUSE Leap 42.2","index_name":"42.2","version_number":"42.2"},{"id":186,"display_name":"openSUSE Leap 42.3","index_name":"42.3","version_number":"42.3"}]},{"display_name":"SUSE Linux Enterprise Server","index_name":"sles","versions":[{"id":176,"display_name":"SUSE Linux Enterprise Server 11.4","index_name":"11.4","version_number":"11.4"},{"id":177,"display_name":"SUSE Linux Enterprise Server 12","index_name":"12.0","version_number":"12.0"},{"id":178,"display_name":"SUSE Linux Enterprise Server 12.1","index_name":"12.1","version_number":"12.1"},{"id":182,"display_name":"SUSE Linux Enterprise Server 12.2","index_name":"12.2","version_number":"12.2"}]}],"py":[{"display_name":"Python","index_name":"python","versions":[{"id":166,"display_name":"Python"}]}],"jar":[{"display_name":"Java","index_name":"java","versions":[{"id":167,"display_name":"Maven 2","index_name":"maven2","version_number":"2"}]}],"node":[{"display_name":"Node.js","index_name":"node","versions":[{"id":191,"display_name":"Node.js","index_name":"1","version_number":"1"}]}],"dsc":[{"display_name":"Ubuntu","index_name":"ubuntu","versions":[{"id":1,"display_name":"4.10 Warty Warthog","index_name":"warty","version_number":"4.10"},{"id":2,"display_name":"5.04 Hoary Hedgehog","index_name":"hoary","version_number":"5.04"},{"id":3,"display_name":"5.10 Breezy Badger","index_name":"breezy","version_number":"5.10"},{"id":4,"display_name":"6.06 LTS Dapper Drake","index_name":"dapper","version_number":"6.06"},{"id":5,"display_name":"6.10 Edgy Eft","index_name":"edgy","version_number":"6.10"},{"id":6,"display_name":"7.04 Feisty Fawn","index_name":"feisty","version_number":"7.04"},{"id":7,"display_name":"7.10 Gutsy Gibbon","index_name":"gutsy","version_number":"7.10"},{"id":8,"display_name":"8.04 LTS Hardy Heron","index_name":"hardy","version_number":"8.04"},{"id":9,"display_name":"8.10 Intrepid Ibex","index_name":"intrepid","version_number":"8.10"},{"id":10,"display_name":"9.04 Jaunty Jackalope","index_name":"jaunty","version_number":"9.04"},{"id":11,"display_name":"9.10 Karmic Koala","index_name":"karmic","version_number":"9.10"},{"id":12,"display_name":"10.04 LTS Lucid Lynx","index_name":"lucid","version_number":"10.04"},{"id":13,"display_name":"10.10 Maverick Meerkat","index_name":"maverick","version_number":"10.10"},{"id":14,"display_name":"11.04 Natty Narwhal","index_name":"natty","version_number":"11.04"},{"id":15,"display_name":"11.10 Oneiric Ocelot","index_name":"oneiric","version_number":"11.10"},{"id":16,"display_name":"12.04 LTS Precise Pangolin","index_name":"precise","version_number":"12.04"},{"id":17,"display_name":"12.10 Quantal Quetzal","index_name":"quantal","version_number":"12.10"},{"id":18,"display_name":"13.04 Raring Ringtail","index_name":"raring","version_number":"13.04"},{"id":19,"display_name":"13.10 Saucy Salamander","index_name":"saucy","version_number":"13.10"},{"id":20,"display_name":"14.04 LTS Trusty Tahr","index_name":"trusty","version_number":"14.04"},{"id":142,"display_name":"14.10 Utopic Unicorn","index_name":"utopic","version_number":"14.10"},{"id":148,"display_name":"15.04 Vivid Vervet","index_name":"vivid","version_number":"15.04"},{"id":152,"display_name":"15.10 Wily Werewolf","index_name":"wily","version_number":"15.10"},{"id":165,"display_name":"16.04 LTS Xenial Xerus","index_name":"xenial","version_number":"16.04"},{"id":168,"display_name":"16.10 Yakkety Yak","index_name":"yakkety","version_number":"16.10"},{"id":183,"display_name":"17.04 Zesty Zapus","index_name":"zesty","version_number":"17.04"},{"id":187,"display_name":"17.10 Artful Aardvark","index_name":"artful","version_number":"17.10"},{"id":190,"display_name":"18.04 LTS Bionic Beaver","index_name":"bionic","version_number":"18.04"}]},{"display_name":"Debian","index_name":"debian","versions":[{"id":21,"display_name":"4.0 etch","index_name":"etch","version_number":"4.0"},{"id":22,"display_name":"5.0 lenny","index_name":"lenny","version_number":"5.0"},{"id":23,"display_name":"6.0 squeeze","index_name":"squeeze","version_number":"6.0"},{"id":24,"display_name":"7 wheezy","index_name":"wheezy","version_number":"7.0"},{"id":25,"display_name":"8 jessie","index_name":"jessie","version_number":"8.0"},{"id":149,"display_name":"9 stretch","index_name":"stretch","version_number":"9.0"},{"id":150,"display_name":"10 buster","index_name":"buster","version_number":"10.0"}]},{"display_name":"Any deb-based distribution.","index_name":"any","versions":[{"id":35,"display_name":"Any version.","index_name":"any","version_number":null}]},{"display_name":"LinuxMint","index_name":"linuxmint","versions":[{"id":157,"display_name":"16 petra","index_name":"petra","version_number":"16"},{"id":158,"display_name":"17 qiana","index_name":"qiana","version_number":"17"},{"id":159,"display_name":"17.1 rebecca","index_name":"rebecca","version_number":"17.1"},{"id":160,"display_name":"17.2 rafaela","index_name":"rafaela","version_number":"17.2"},{"id":161,"display_name":"17.3 rosa","index_name":"rosa","version_number":"17.3"},{"id":170,"display_name":"18 sarah","index_name":"sarah","version_number":"18"},{"id":180,"display_name":"18.1 serena","index_name":"serena","version_number":"18.1"},{"id":185,"display_name":"18.2 sonya","index_name":"sonya","version_number":"18.2"},{"id":189,"display_name":"18.3 sylvia","index_name":"sylvia","version_number":"18.3"}]},{"display_name":"Raspbian","index_name":"raspbian","versions":[{"id":153,"display_name":"7 wheezy","index_name":"wheezy","version_number":"7.0"},{"id":154,"display_name":"8 jessie","index_name":"jessie","version_number":"8.0"},{"id":155,"display_name":"9 stretch","index_name":"stretch","version_number":"9.0"},{"id":156,"display_name":"10 buster","index_name":"buster","version_number":"10.0"}]},{"display_name":"elementary OS","index_name":"elementaryos","versions":[{"id":162,"display_name":"0.1 jupiter","index_name":"jupiter","version_number":"0.1"},{"id":163,"display_name":"0.2 luna","index_name":"luna","version_number":"0.2"},{"id":164,"display_name":"0.3 freya","index_name":"freya","version_number":"0.3"}]}]}
@@ -0,0 +1,27 @@
1
+ Format: 3.0 (quilt)
2
+ Source: jake
3
+ Binary: jake, jake-doc
4
+ Architecture: i386 amd64 all
5
+ Version: 1.0-7
6
+ Origin: Ubuntu
7
+ Maintainer: jake <joe@packagecloud.io>
8
+ Dm-Upload-Allowed: yes
9
+ Homepage: http://www.chkrootkit.org/
10
+ Standards-Version: 3.9.3
11
+ Vcs-Browser: http://git.debian.org/?p=collab-maint/chkrootkit.git
12
+ Vcs-Git: git://git.debian.org/git/collab-maint/chkrootkit.git
13
+ Build-Depends: pkg-config, quilt
14
+ Build-Depends-Indep: debhelper (>= 2.0.40), gettext, bzip2, cpio
15
+ Build-Conflicts: tk8.0-dev
16
+ Package-List:
17
+ jake deb misc optional
18
+ jake-doc deb doc optional
19
+ Checksums-Sha1:
20
+ 4c054ea8b265d50ee09cac44c9707dbb0ee9a91f 1108 jake_1.0.orig.tar.bz2
21
+ e4749cf9995cd5340a9f23f1656282467e3e105c 1571 jake_1.0-7.debian.tar.gz
22
+ Checksums-Sha256:
23
+ 759cdaf056dc76ba07e5ae7bbd4a452c95aa054d87047cbee0225637ab25d572 1108 jake_1.0.orig.tar.bz2
24
+ be58a87fa814ef56008d0973f60432aec990d427de72e91f84ef0029f0fba46f 1571 jake_1.0-7.debian.tar.gz
25
+ Files:
26
+ a7a309b55424198ee98abcb8092d7be0 1108 jake_1.0.orig.tar.bz2
27
+ 0fa5395e95ddf846b419e96575ce8044 1571 jake_1.0-7.debian.tar.gz
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'packagecloud'
3
+
4
+ describe Package do
5
+ it "should raise for nil file" do
6
+ expect { Package.new }.to raise_error("file cannot be nil")
7
+ end
8
+
9
+ it "should raise for file that doesn't exist" do
10
+ expect { Package.new(:file => "hi") }.to raise_error
11
+ end
12
+
13
+ it "should be able to open String file paths" do
14
+ pkg = Package.new(:file => "spec/fixtures/chewbacca-1.0.0.gem")
15
+ expect(pkg.filename).to eql("chewbacca-1.0.0.gem")
16
+ end
17
+
18
+ it "should be able to open File objects" do
19
+ pkg = Package.new(:file => File.open("spec/fixtures/chewbacca-1.0.0.gem"))
20
+ expect(pkg.filename).to eql("chewbacca-1.0.0.gem")
21
+ end
22
+
23
+ it "should raise if IO object is passed without filename" do
24
+ fd = IO.sysopen("spec/fixtures/chewbacca-1.0.0.gem", "r")
25
+ io = IO.new(fd)
26
+ expect { Package.new(:file => io) }.to raise_error("filename cannot be nil")
27
+ end
28
+
29
+ it "should handle IO object if passed with filename" do
30
+ fd = IO.sysopen("spec/fixtures/chewbacca-1.0.0.gem", "r")
31
+ io = IO.new(fd)
32
+ pkg = Package.new(:file => io, :filename => "chewbacca-1.0.0.gem")
33
+ expect(pkg.filename).to eql("chewbacca-1.0.0.gem")
34
+ end
35
+
36
+ it "should handle source_files options" do
37
+ pkg = Package.new(:file => "spec/fixtures/natty_dsc/jake_1.0-7.dsc", :source_files => {"foo" => "bar"})
38
+ expect(pkg.source_files).to eql({"foo" => "bar"})
39
+ end
40
+
41
+ it "should always have a {} as default for source files" do
42
+ pkg = Package.new(:file => "spec/fixtures/natty_dsc/jake_1.0-7.dsc", :source_files => nil)
43
+ expect(pkg.source_files).to be_empty
44
+ end
45
+
46
+ end
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+ require 'webrick'
3
+
4
+ class PackagecloudServer < WEBrick::HTTPServlet::AbstractServlet
5
+ DISTRIBUTIONS = File.read("spec/fixtures/distros.json")
6
+ PACKAGE_CONTENTS = "{\"files\":[{\"filename\":\"jake_1.0.orig.tar.bz2\",\"size\":1108,\"md5sum\":\"a7a309b55424198ee98abcb8092d7be0\"},{\"filename\":\"jake_1.0-7.debian.tar.gz\",\"size\":1571,\"md5sum\":\"0fa5395e95ddf846b419e96575ce8044\"}]}"
7
+ GEM_VERSION = "{\"major\":\"0\",\"minor\":\"2\",\"patch\":\"1\"}"
8
+ REPO = '{"name": "test_repo","created_at": "2014-08-30T03:51:37.000Z","url": "https://packagecloud.io/joedamato/test_repo","last_push_human": "about 2 months ago","package_count_human": "4 packages","private": true,"fqname": "joedamato/test_repo"}'
9
+ REPOS = "[#{REPO}]"
10
+ READ_TOKENS = '{"read_tokens":[{"id":"1","name":"testread","value":"notreal"}]}'
11
+
12
+ def json_response(request, response, body)
13
+ response.status = 200
14
+ response['Content-Type'] = "application/json"
15
+ response.body = body
16
+ $request, $response = request, response
17
+ end
18
+
19
+ def plain_response(request, response, body)
20
+ response.status = 200
21
+ response['Content-Type'] = "text/plain"
22
+ response.body = body
23
+ $request, $response = request, response
24
+ end
25
+
26
+ def created_response(request, response)
27
+ response.status = 201
28
+ response['Content-Type'] = "text/plain"
29
+ response.body = "{}"
30
+ ### Cheap hack to avoid parsing a multipart request here,
31
+ ### instead we just check that the body isn't impossibly small
32
+ if (request.body.size < 1000)
33
+ raise "Request is too small! #{request.body.size}"
34
+ end
35
+ $request, $response = request, response
36
+ end
37
+
38
+ def default_response(request, response)
39
+ response.status = 404
40
+ response['Content-Type'] = "text/plain"
41
+ response.body = "nope"
42
+ $request, $response = request, response
43
+ end
44
+
45
+ def forbidden_response(request, response)
46
+ response.status = 401
47
+ response['Content-Type'] = "text/plain"
48
+ response.body = "{ 'error': 'unauthenticated' }"
49
+
50
+ $request, $response = request, response
51
+ end
52
+
53
+ def nocontent_response(request, response)
54
+ response.status = 204
55
+ response['Content-Type'] = 'text/plain'
56
+ response.body = ''
57
+ $request, $response = request, response
58
+ end
59
+
60
+ def can_acess?(request)
61
+ request["Authorization"] == "Basic dGVzdF90b2tlbjo="
62
+ end
63
+
64
+ def route(request, response)
65
+ return forbidden_response(request, response) unless can_acess?(request)
66
+
67
+ path = request.path
68
+ case path
69
+ when "/api/v1/distributions.json"
70
+ json_response(request, response, DISTRIBUTIONS)
71
+ when "/api/v1/repos.json"
72
+ if request.request_method == "GET"
73
+ json_response(request, response, REPOS)
74
+ else
75
+ plain_response(request, response, "{}")
76
+ end
77
+ when "/api/v1/repos/joedamato/test_repo.json"
78
+ json_response(request, response, REPO)
79
+ when "/api/v1/repos/joedamato/test_repo/packages.json"
80
+ created_response(request, response)
81
+ when "/api/v1/repos/joedamato/test_repo/packages/contents.json"
82
+ plain_response(request, response, PACKAGE_CONTENTS)
83
+ when "/api/v1/gem_version.json"
84
+ json_response(request, response, GEM_VERSION)
85
+ when "/api/v1/repos/joedamato/test_repo/master_tokens/test_master_token/read_tokens.json"
86
+ json_response(request, response, READ_TOKENS)
87
+ else
88
+ default_response(request, response)
89
+ $request, $response = request, response
90
+ end
91
+ end
92
+
93
+ def do_GET(request, response)
94
+ route(request, response)
95
+ end
96
+
97
+ def do_POST(request, response)
98
+ route(request, response)
99
+ end
100
+
101
+ def do_DELETE(request, response)
102
+ return forbidden_response(request, response) unless can_acess?(request)
103
+
104
+ path = request.path
105
+ case path
106
+ when "/api/v1/repos/joedamato/test_repo/master_tokens/test_master_token/read_tokens/1"
107
+ nocontent_response(request, response)
108
+ else
109
+ default_response(request, response)
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,284 @@
1
+ require 'spec_helper'
2
+ require 'excon'
3
+ require 'packagecloud_server'
4
+ require 'packagecloud'
5
+ require 'webrick'
6
+
7
+ @server = Thread.start do
8
+ server = WEBrick::HTTPServer.new(:Port => 8000)
9
+ server.mount "/", PackagecloudServer
10
+ trap "INT" do
11
+ server.shutdown
12
+ end
13
+ server.start
14
+ end
15
+
16
+ until @server.status == "sleep" do
17
+ puts "waiting for server to start..."
18
+ end
19
+
20
+ describe Packagecloud do
21
+
22
+ include Packagecloud
23
+
24
+ before(:all) do
25
+ credentials = Credentials.new("joedamato", "test_token")
26
+ connection = Connection.new("http", "localhost", 8000)
27
+
28
+ @client = Client.new(credentials, "test_client", connection)
29
+ end
30
+
31
+ it "should have a VERSION constant" do
32
+ expect(subject.const_get('VERSION')).to_not be_empty
33
+ end
34
+
35
+ it "GET api/v1/distributions.json" do
36
+ distros = @client.distributions
37
+ expect(distros.succeeded).to be_truthy
38
+
39
+ deb = distros.response["deb"]
40
+ dsc = distros.response["dsc"]
41
+ rpm = distros.response["rpm"]
42
+
43
+ expect(deb).not_to be_empty
44
+ expect(dsc).not_to be_empty
45
+ expect(rpm).not_to be_empty
46
+ end
47
+
48
+ it "POST debian package /api/v1/repos/joedamato/test_repo/packages.json" do
49
+ path = "spec/fixtures/libampsharp2.0-cil_2.0.4-1_all.deb"
50
+ size = File.size(path)
51
+ package = Package.new(:file => path)
52
+
53
+ result = @client.put_package("test_repo", package, 22)
54
+ expect(result.succeeded).to be_truthy
55
+
56
+ #assert content type is set correctly
57
+ expect($request.content_type).to include("boundary=")
58
+ expect($request.content_type).to include("multipart/form-data")
59
+
60
+ # assert body is at least bigger than fixture file
61
+ expect($request.content_length > size).to be_truthy
62
+ end
63
+
64
+ it "POST debian package /api/v1/repos/joedamato/test_repo/packages.json twice" do
65
+ path = "spec/fixtures/libampsharp2.0-cil_2.0.4-1_all.deb"
66
+
67
+ package = Package.new(:file => path)
68
+
69
+ @client.put_package("test_repo", package, 22)
70
+ result = @client.put_package("test_repo", package, 21)
71
+ expect(result.succeeded).to be_truthy
72
+ end
73
+
74
+
75
+ it "POST gem package /api/v1/repos/joedamato/test_repo/packages.json" do
76
+ path = "spec/fixtures/chewbacca-1.0.0.gem"
77
+ size = File.size(path)
78
+ package = Package.new(:file => path)
79
+
80
+ result = @client.put_package("test_repo", package)
81
+ expect(result.succeeded).to be_truthy
82
+
83
+ #assert content type is set correctly
84
+ expect($request.content_type).to include("boundary=")
85
+ expect($request.content_type).to include("multipart/form-data")
86
+
87
+ # assert body is at least bigger than fixture file
88
+ expect($request.content_length > size).to be_truthy
89
+ end
90
+
91
+ it "POST debian package /api/v1/repos/joedamato/test_repo/packages.json with string distro_version_id" do
92
+ allow(@client).to receive(:find_distribution_id).and_return(3)
93
+ path = "spec/fixtures/libampsharp2.0-cil_2.0.4-1_all.deb"
94
+ size = File.size(path)
95
+ package = Package.new(:file => path)
96
+
97
+ result = @client.put_package("test_repo", package, "ubuntu/breezy")
98
+
99
+ expect(@client).to have_received(:find_distribution_id)
100
+ expect(result.succeeded).to be_truthy
101
+
102
+ #assert content type is set correctly
103
+ expect($request.content_type).to include("boundary=")
104
+ expect($request.content_type).to include("multipart/form-data")
105
+
106
+ # assert body is at least bigger than fixture file
107
+ expect($request.content_length > size).to be_truthy
108
+ end
109
+
110
+ it "POST source package /api/v1/repos/joedamato/test_repo/packages.json" do
111
+ dsc = File.dirname(__FILE__) + '/fixtures/natty_dsc/jake_1.0-7.dsc'
112
+ jake_orig = File.dirname(__FILE__) + '/fixtures/natty_dsc/jake_1.0.orig.tar.bz2'
113
+ jake_debian = File.dirname(__FILE__) + '/fixtures/natty_dsc/jake_1.0-7.debian.tar.gz'
114
+
115
+ source_packages = { "jake_1.0.orig.tar.bz2" => open(jake_orig),
116
+ "jake_1.0-7.debian.tar.gz" => open(jake_debian),}
117
+
118
+ dsc_size = File.size(dsc)
119
+ jake_orig_size = File.size(jake_orig)
120
+ jake_debian_size = File.size(jake_debian)
121
+ combined_size = dsc_size + jake_orig_size + jake_debian_size
122
+
123
+ package = Package.new(:file => dsc, :source_files => source_packages)
124
+
125
+ result = @client.put_package("test_repo", package, 22)
126
+ expect(result.succeeded).to be_truthy
127
+
128
+ #assert content type is set correctly
129
+ expect($request.content_type).to include("boundary=")
130
+ expect($request.content_type).to include("multipart/form-data")
131
+
132
+ # assert body is at least bigger than fixture file
133
+ expect($request.content_length > combined_size).to be_truthy
134
+ end
135
+
136
+ it "POST /api/v1/repos/joedamato/test_repo/packages/contents.json" do
137
+ dsc = 'spec/fixtures/natty_dsc/jake_1.0-7.dsc'
138
+ size = File.size(dsc)
139
+ package = Package.new(:file => dsc)
140
+
141
+ result = @client.package_contents("test_repo", package, 99999)
142
+ expect(result.succeeded).to be_truthy
143
+ expect(result.response["files"]).not_to be_empty
144
+
145
+ #assert content type is set correctly
146
+ expect($request.content_type).to include("boundary=")
147
+ expect($request.content_type).to include("multipart/form-data")
148
+
149
+ # assert body is at least bigger than fixture file
150
+ expect($request.content_length > size).to be_truthy
151
+ end
152
+
153
+ it "GET /api/v1/gem_version.json" do
154
+ result = @client.gem_version
155
+ expect(result.succeeded).to be_truthy
156
+ expect(result.response["major"]).to eq("0")
157
+ expect(result.response["minor"]).to eq("2")
158
+ expect(result.response["patch"]).to eq("1")
159
+ end
160
+
161
+ it "GET /api/v1/repos.json" do
162
+ result = @client.repositories
163
+ expect(result.succeeded).to be_truthy
164
+ expect(result.response[0]["private"]).to be_truthy
165
+ expect(result.response[0]["fqname"]).to eq("joedamato/test_repo")
166
+ expect(result.response[0]["name"]).to eq("test_repo")
167
+ end
168
+
169
+ it "POST /api/v1/repos.json" do
170
+ body = { "repository" => { "name" => "my_repo", "private" => "0" } }.to_json
171
+ result = @client.create_repository("my_repo")
172
+ expect(result.succeeded).to be_truthy
173
+ expect($request.content_type).to include("json")
174
+ expect($request.content_length).to eq(body.size)
175
+ end
176
+
177
+ it "GET /api/v1/repos/joedamato/test_repo.json" do
178
+ result = @client.repository("test_repo")
179
+ expect(result.succeeded).to be_truthy
180
+ expect(result.response["private"]).to be_truthy
181
+ expect(result.response["fqname"]).to eq("joedamato/test_repo")
182
+ expect(result.response["name"]).to eq("test_repo")
183
+ end
184
+
185
+ it "should raise if the repo name is invalid" do
186
+ expect do
187
+ result = @client.repository("hi/test_repo")
188
+ end.to raise_error(InvalidRepoNameException)
189
+ end
190
+
191
+ it "GET /api/v1/repos/joedamato/invalid_repo.json (invalid repo)" do
192
+ result = @client.repository("invalid_repo")
193
+ expect(result.succeeded).to be_falsey
194
+ end
195
+
196
+ it "should have a distinct User-Agent that includes the version" do
197
+ @client.distributions
198
+ expect($request["User-Agent"]).to eq("packagecloud-ruby #{Packagecloud::VERSION}/test_client")
199
+ end
200
+
201
+ it "should raise if the username has an @ in it" do
202
+ expect do
203
+ credentials = Credentials.new("hi@test.com", "test_token")
204
+ end.to raise_error(InvalidUsernameException)
205
+ end
206
+
207
+ it "invalid credentials should raise unauthenticated exception" do
208
+ credentials = Credentials.new("joedamato", "test_tafdfasoken")
209
+ connection = Connection.new("http", "localhost", 8000)
210
+ expect {
211
+ Client.new(credentials, "test_client", connection)
212
+ }.to raise_error(UnauthenticatedException)
213
+ end
214
+
215
+ it "deletes read token" do
216
+ result = @client.delete_read_token("test_repo", "test_master_token", 1)
217
+ expect(result.succeeded).to be_truthy
218
+ end
219
+
220
+ it "fails to delete invalid read token" do
221
+ result = @client.delete_read_token("test_repo", "test_master_token", 2323)
222
+ expect(result.succeeded).to be_falsey
223
+ end
224
+
225
+ it "lists read tokens" do
226
+ result = @client.list_read_tokens("test_repo", "test_master_token")
227
+ expect(result.succeeded).to be_truthy
228
+ expect(result.response["read_tokens"].first).to eq({"id" => "1", "name" => "testread", "value" => "notreal" })
229
+ end
230
+
231
+ context "timeouts" do
232
+ it "should have defaults" do
233
+ credentials = Credentials.new("joedamato", "test_token")
234
+ connection = Connection.new("http", "localhost", 8000)
235
+ client = Client.new(credentials, "test_client", connection)
236
+ expect(client.connection.read_timeout).to eql(60)
237
+ expect(client.connection.write_timeout).to eql(180)
238
+ expect(client.connection.connect_timeout).to eql(60)
239
+ end
240
+
241
+ it "should respect passed values" do
242
+ credentials = Credentials.new("joedamato", "test_token")
243
+ timeouts = { :connect_timeout => 10, :read_timeout => 80, :write_timeout => 280 }
244
+ connection = Connection.new("http", "localhost", 8000, timeouts)
245
+ client = Client.new(credentials, "test_client", connection)
246
+ expect(client.connection.read_timeout).to eql(80)
247
+ expect(client.connection.write_timeout).to eql(280)
248
+ expect(client.connection.connect_timeout).to eql(10)
249
+ end
250
+ end
251
+
252
+ describe "find_distribution_id" do
253
+ it "should find ubuntu/breezy" do
254
+ id = @client.find_distribution_id("ubuntu/breezy")
255
+ expect(id).to be(3)
256
+ end
257
+
258
+ it "should find just breezy" do
259
+ id = @client.find_distribution_id("breezy")
260
+ expect(id).to be(3)
261
+ end
262
+
263
+ it "should find python" do
264
+ id = @client.find_distribution_id("python")
265
+ expect(id).to be(166)
266
+ end
267
+
268
+ it "should find node" do
269
+ id = @client.find_distribution_id("node")
270
+ expect(id).to be(191)
271
+ end
272
+
273
+ it "should return nil for invalid distro" do
274
+ id = @client.find_distribution_id("ubuasdalsdntu/breezy")
275
+ expect(id).to be_nil
276
+ end
277
+
278
+ it "should raise for amiguous distro queries" do
279
+ expect {
280
+ @client.find_distribution_id("ubuntu")
281
+ }.to raise_error
282
+ end
283
+ end
284
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'simplecov'
3
+ require 'packagecloud/version'
4
+ SimpleCov.start
5
+
6
+ include Packagecloud