Skip to content
Snippets Groups Projects
Commit 0d054f8a authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Merge branch 'package-promotion' into 'master'

Package Promotion

See merge request !3
parents 5f59593e dc340e77
No related branches found
No related tags found
1 merge request!3Package Promotion
Pipeline #
Loading
Loading
@@ -2,3 +2,5 @@ Gemfile.lock
doc/
pkg/
vendor/cache/*.gem
.idea/
coverage/
# Change Log
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Support for promoting packages
### Changed
- Using MultiJson everywhere to create json from Hash (fix exception in IRB)
## [1.0.5] - 2016-12-09
### TODO
## [1.0.4] - 2016-05-04
### TODO
## [1.0.3] - 2016-03-22
### TODO
## [1.0.2] - 2016-01-14
### TODO
## [1.0.1] - 2016-01-08
### TODO
## [1.0.0] - 2016-01-08
### TODO
## [0.2.23] - 2015-12-03
### TODO
## [0.2.22] - 2015-10-23
### TODO
## [0.2.21] - 2015-10-23
### TODO
## [0.2.19] - 2015-03-13
### TODO
[Unreleased]: https://gitlab.com/gitlab-org/packagecloud-ruby/compare/v1.0.5...HEAD
[1.0.5]: https://github.com/computology/packagecloud-ruby/compare/v1.0.4...v1.0.5
[1.0.4]: https://github.com/computology/packagecloud-ruby/compare/v1.0.3...v1.0.4
[1.0.3]: https://github.com/computology/packagecloud-ruby/compare/v1.0.2...v1.0.3
[1.0.2]: https://github.com/computology/packagecloud-ruby/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/computology/packagecloud-ruby/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/computology/packagecloud-ruby/compare/v0.2.23...v1.0.0
[0.2.23]: https://github.com/computology/packagecloud-ruby/compare/v0.2.22...v0.2.23
[0.2.22]: https://github.com/computology/packagecloud-ruby/compare/v0.2.21...v0.2.22
[0.2.21]: https://github.com/computology/packagecloud-ruby/compare/v0.2.19...v0.2.21
[0.2.19]: https://github.com/computology/packagecloud-ruby/compare/03ea04a91292b2043ede61051fc7182ea5cca384...v0.2.19
Loading
Loading
@@ -4,6 +4,7 @@ require 'excon'
require 'packagecloud/result'
require 'packagecloud/connection'
require 'packagecloud/version'
require 'uri'
 
module Packagecloud
SUPPORTED_EXTENSIONS = ["deb", "dsc", "gem", "rpm", "whl", "zip", "egg", "egg-info", "tar", "bz2", "Z", "gz"]
Loading
Loading
@@ -128,6 +129,17 @@ module Packagecloud
parsed_json_result(response)
end
 
def promote_package(repo, distro, distro_release, package_filename, destination)
assert_valid_repo_name(repo)
assert_valid_repo_name(destination)
url = "/api/v1/repos/#{username}/#{repo}/#{distro}/#{distro_release}/#{package_filename}/promote.json"
body = URI.encode_www_form("destination" => "#{username}/#{destination}")
response = post(url, body, "application/x-www-form-urlencoded")
parsed_json_result(response)
end
def put_package(repo, package, distro_version_id=nil)
assert_valid_repo_name(repo)
 
Loading
Loading
@@ -251,9 +263,10 @@ module Packagecloud
if content_type != nil
headers.merge!({ "Content-Type" => content_type })
end
request_params = { :method => method, :path => url, :headers => headers }
if body != nil
request_params.merge!({ :body => body })
request_params[:body] = body
end
 
@excon.request(request_params.merge({:read_timeout => connection.read_timeout, :write_timeout => connection.write_timeout }))
Loading
Loading
@@ -275,6 +288,5 @@ module Packagecloud
end
result
end
end
end
Loading
Loading
@@ -42,5 +42,4 @@ describe Package do
pkg = Package.new(:file => "spec/fixtures/natty_dsc/jake_1.0-7.dsc", :source_files => nil)
expect(pkg.source_files).to be_empty
end
end
Loading
Loading
@@ -3,10 +3,12 @@ require 'webrick'
 
class PackagecloudServer < WEBrick::HTTPServlet::AbstractServlet
DISTRIBUTIONS = File.read("spec/fixtures/distros.json")
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\"}]}"
GEM_VERSION = "{\"major\":\"0\",\"minor\":\"2\",\"patch\":\"1\"}"
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"}]}'
GEM_VERSION = '{"major":"0","minor":"2","patch":"1"}'
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"}'
REPOS = "[#{REPO}]"
PACKAGES = '[{"name":"gitlab-ce","distro_version":"ubuntu/xenial","created_at":"2017-01-21T23:50:27.000Z","version":"8.15.5","release":"ce.0","epoch": 0,"private":true,"type":"deb","filename":"gitlab-ce_8.15.5-ce.0_amd64.deb","uploader_name":"joedamato","indexed":true,"repository_html_url":"/joedamato/test_repo","package_url":"/api/v1/repos/joedamato/test_repo/package/deb/ubuntu/xenial/gitlab-ce/amd64/8.15.5-ce.0.json","downloads_detail_url":"/api/v1/repos/joedamato/test_repo/package/deb/ubuntu/xenial/gitlab-ce/amd64/8.15.5-ce.0/stats/downloads/detail.json","downloads_series_url": "/api/v1/repos/joedamato/test_repo/package/deb/ubuntu/xenial/gitlab-ce/amd64/8.15.5-ce.0/stats/downloads/series/daily.json","downloads_count_url": "/api/v1/repos/joedamato/test_repo/package/deb/ubuntu/xenial/gitlab-ce/amd64/8.15.5-ce.0/stats/downloads/count.json","package_html_url": "/joedamato/test_repo/packages/ubuntu/xenial/gitlab-ce_8.15.5-ce.0_amd64.deb","promote_url":"/api/v1/repos/joedamato/test_repo/ubuntu/xenial/gitlab-ce_8.15.5-ce.0_amd64.deb/promote.json"}]'
PROMOTED = '{"name":"gitlab-ce","distro_version":"ubuntu/xenial","architecture":"amd64","repository":"public","size":"311509298","summary":null,"filename":"gitlab-ce_8.15.5-ce.0_amd64.deb","description":"GitLab Community Edition and GitLab CI (including NGINX, Postgres, Redis)","dependencies":[{"context":"depends","dependencies":["openssh-server"]}],"md5sum":"bd1427fbe923607536912d00e52c6a15","sha1sum":"b6acc61629026e33046122049213b29ecfc8c25a","sha256sum":"9cdcd68a5e7bb391a88d7279c9bf178aacba62c6827b9a0db0e4dd67604a33b5","sha512sum":"3b81d3e09fec4d0c4c97bfeccb4bb040b8c7b7913cc3aa7b6380ccd581f1eea08d605fbecf526f6e549e609242f4ba725d5ec8cdab01fe6ecbf3754e8cd93b84","private":false,"uploader_name":"joedamato","created_at":"2017-01-21T23:50:27.000Z","licenses":[],"version":"8.15.5","release":"ce.0","epoch":0,"indexed":false,"repository_url":"/api/v1/repos/joedamato/public","repository_html_url":"/joedamato/public","package_url":"/api/v1/repos/gabriel/public/package/deb/ubuntu/xenial/gitlab-ce/amd64/8.15.5-ce.0.json","versions_url":"/api/v1/repos/gabriel/public/package/deb/ubuntu/xenial/gitlab-ce/amd64/versions.json","promote_url":"/api/v1/repos/joedamato/test_repo/ubuntu/xenial/gitlab-ce_8.15.5-ce.0_amd64.deb/promote.json","total_downloads_count":0,"download_url":"https://packages.gitlab.com/joedamato/public/packages/ubuntu/xenial/gitlab-ce_8.15.5-ce.0_amd64.deb/download","package_html_url":"/joedamato/public/packages/ubuntu/xenial/gitlab-ce_8.15.5-ce.0_amd64.deb","downloads_detail_url":"/api/v1/repos/joedamato/public/package/deb/ubuntu/xenial/gitlab-ce/amd64/8.15.5-ce.0/stats/downloads/detail.json","downloads_series_url":"/api/v1/repos/joedamato/public/package/deb/ubuntu/xenial/gitlab-ce/amd64/8.15.5-ce.0/stats/downloads/series/daily.json","downloads_count_url":"/api/v1/repos/joedamato/public/package/deb/ubuntu/xenial/gitlab-ce/amd64/8.15.5-ce.0/stats/downloads/count.json","self_url":"/api/v1/repos/joedamato/public/package/deb/ubuntu/xenial/gitlab-ce/amd64/8.15.5-ce.0.json"}'
 
def json_response(request, response, body)
response.status = 200
Loading
Loading
@@ -48,10 +50,12 @@ class PackagecloudServer < WEBrick::HTTPServlet::AbstractServlet
 
$request, $response = request, response
end
def route(request, response)
if request["Authorization"] && request["Authorization"] != "Basic dGVzdF90b2tlbjo="
return forbidden_response(request, response)
end
path = request.path
case path
when "/api/v1/distributions.json"
Loading
Loading
@@ -65,7 +69,17 @@ class PackagecloudServer < WEBrick::HTTPServlet::AbstractServlet
when "/api/v1/repos/joedamato/test_repo.json"
json_response(request, response, REPO)
when "/api/v1/repos/joedamato/test_repo/packages.json"
created_response(request, response)
if request.request_method == "POST"
created_response(request, response)
elsif request.request_method == "GET"
json_response(request, response, PACKAGES)
end
when "/api/v1/repos/joedamato/test_repo/ubuntu/xenial/gitlab-ce_8.15.5-ce.0_amd64.deb/promote.json"
if request.request_method == "POST"
if request.query.key? "destination"
json_response(request, response, PROMOTED)
end
end
when "/api/v1/repos/joedamato/test_repo/packages/contents.json"
plain_response(request, response, PACKAGE_CONTENTS)
when "/api/v1/gem_version.json"
Loading
Loading
@@ -83,5 +97,4 @@ class PackagecloudServer < WEBrick::HTTPServlet::AbstractServlet
def do_POST(request, response)
route(request, response)
end
end
Loading
Loading
@@ -18,7 +18,6 @@ until @server.status == "sleep" do
end
 
describe Packagecloud do
include Packagecloud
 
before(:all) do
Loading
Loading
@@ -28,236 +27,275 @@ describe Packagecloud do
@client = Client.new(credentials, "test_client", connection)
end
 
let(:credentials) { Credentials.new("joedamato", "test_token") }
let(:connection) { connection = Connection.new("http", "localhost", 8000) }
it "should have a VERSION constant" do
expect(subject.const_get('VERSION')).to_not be_empty
end
 
it "GET api/v1/distributions.json" do
distros = @client.distributions
expect(distros.succeeded).to be_truthy
context "root level requests" do
it "GET api/v1/distributions.json" do
distros = @client.distributions
expect(distros.succeeded).to be_truthy
 
deb = distros.response["deb"]
dsc = distros.response["dsc"]
rpm = distros.response["rpm"]
deb = distros.response["deb"]
dsc = distros.response["dsc"]
rpm = distros.response["rpm"]
 
expect(deb).not_to be_empty
expect(dsc).not_to be_empty
expect(rpm).not_to be_empty
end
expect(deb).not_to be_empty
expect(dsc).not_to be_empty
expect(rpm).not_to be_empty
end
 
it "POST debian package /api/v1/repos/joedamato/test_repo/packages.json" do
path = "spec/fixtures/libampsharp2.0-cil_2.0.4-1_all.deb"
size = File.size(path)
package = Package.new(:file => path)
it "GET /api/v1/gem_version.json" do
result = @client.gem_version
 
result = @client.put_package("test_repo", package, 22)
expect(result.succeeded).to be_truthy
expect(result.succeeded).to be_truthy
expect(result.response["major"]).to eq("0")
expect(result.response["minor"]).to eq("2")
expect(result.response["patch"]).to eq("1")
end
 
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
it "GET /api/v1/repos.json" do
result = @client.repositories
 
# assert body is at least bigger than fixture file
expect($request.content_length > size).to be_truthy
end
expect(result.succeeded).to be_truthy
expect(result.response[0]["private"]).to be_truthy
expect(result.response[0]["fqname"]).to eq("joedamato/test_repo")
expect(result.response[0]["name"]).to eq("test_repo")
end
 
it "POST debian package /api/v1/repos/joedamato/test_repo/packages.json twice" do
path = "spec/fixtures/libampsharp2.0-cil_2.0.4-1_all.deb"
it "POST /api/v1/repos.json" do
body = MultiJson.dump({ "repository" => { "name" => "my_repo", "private" => "0" } })
result = @client.create_repository("my_repo")
 
package = Package.new(:file => path)
expect(result.succeeded).to be_truthy
expect($request.content_type).to include("json")
expect($request.content_length).to eq(body.size)
end
 
@client.put_package("test_repo", package, 22)
result = @client.put_package("test_repo", package, 21)
expect(result.succeeded).to be_truthy
describe "find_distribution_id" do
it "should find ubuntu/breezy" do
id = @client.find_distribution_id("ubuntu/breezy")
expect(id).to be(3)
end
it "should find just breezy" do
id = @client.find_distribution_id("breezy")
expect(id).to be(3)
end
it "should find python" do
id = @client.find_distribution_id("python")
expect(id).to be(166)
end
it "should return nil for invalid distro" do
id = @client.find_distribution_id("ubuasdalsdntu/breezy")
expect(id).to be_nil
end
it "should raise for ambiguous distro queries" do
expect {
@client.find_distribution_id("ubuntu")
}.to raise_error
end
end
end
 
context "repository level requests" do
describe "publishing a new package" do
it "POST debian package /api/v1/repos/joedamato/test_repo/packages.json" do
path = "spec/fixtures/libampsharp2.0-cil_2.0.4-1_all.deb"
size = File.size(path)
package = Package.new(:file => path)
 
it "POST gem package /api/v1/repos/joedamato/test_repo/packages.json" do
path = "spec/fixtures/chewbacca-1.0.0.gem"
size = File.size(path)
package = Package.new(:file => path)
result = @client.put_package("test_repo", package, 22)
expect(result.succeeded).to be_truthy
 
result = @client.put_package("test_repo", package)
expect(result.succeeded).to be_truthy
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
 
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
# assert body is at least bigger than fixture file
expect($request.content_length > size).to be_truthy
end
 
# assert body is at least bigger than fixture file
expect($request.content_length > size).to be_truthy
end
it "POST debian package /api/v1/repos/joedamato/test_repo/packages.json twice" do
path = "spec/fixtures/libampsharp2.0-cil_2.0.4-1_all.deb"
package = Package.new(:file => path)
 
it "POST debian package /api/v1/repos/joedamato/test_repo/packages.json with string distro_version_id" do
allow(@client).to receive(:find_distribution_id).and_return(3)
path = "spec/fixtures/libampsharp2.0-cil_2.0.4-1_all.deb"
size = File.size(path)
package = Package.new(:file => path)
@client.put_package("test_repo", package, 22)
result = @client.put_package("test_repo", package, 21)
 
result = @client.put_package("test_repo", package, "ubuntu/breezy")
expect(result.succeeded).to be_truthy
end
 
expect(@client).to have_received(:find_distribution_id)
expect(result.succeeded).to be_truthy
it "POST gem package /api/v1/repos/joedamato/test_repo/packages.json" do
path = "spec/fixtures/chewbacca-1.0.0.gem"
size = File.size(path)
package = Package.new(:file => path)
 
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
result = @client.put_package("test_repo", package)
expect(result.succeeded).to be_truthy
 
# assert body is at least bigger than fixture file
expect($request.content_length > size).to be_truthy
end
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
 
it "POST source package /api/v1/repos/joedamato/test_repo/packages.json" do
dsc = File.dirname(__FILE__) + '/fixtures/natty_dsc/jake_1.0-7.dsc'
jake_orig = File.dirname(__FILE__) + '/fixtures/natty_dsc/jake_1.0.orig.tar.bz2'
jake_debian = File.dirname(__FILE__) + '/fixtures/natty_dsc/jake_1.0-7.debian.tar.gz'
# assert body is at least bigger than fixture file
expect($request.content_length > size).to be_truthy
end
 
source_packages = { "jake_1.0.orig.tar.bz2" => open(jake_orig),
"jake_1.0-7.debian.tar.gz" => open(jake_debian),}
it "POST debian package /api/v1/repos/joedamato/test_repo/packages.json with string distro_version_id" do
allow(@client).to receive(:find_distribution_id).and_return(3)
path = "spec/fixtures/libampsharp2.0-cil_2.0.4-1_all.deb"
size = File.size(path)
package = Package.new(:file => path)
 
dsc_size = File.size(dsc)
jake_orig_size = File.size(jake_orig)
jake_debian_size = File.size(jake_debian)
combined_size = dsc_size + jake_orig_size + jake_debian_size
result = @client.put_package("test_repo", package, "ubuntu/breezy")
 
package = Package.new(:file => dsc, :source_files => source_packages)
expect(@client).to have_received(:find_distribution_id)
expect(result.succeeded).to be_truthy
 
result = @client.put_package("test_repo", package, 22)
expect(result.succeeded).to be_truthy
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
 
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
# assert body is at least bigger than fixture file
expect($request.content_length > size).to be_truthy
end
 
# assert body is at least bigger than fixture file
expect($request.content_length > combined_size).to be_truthy
end
it "POST source package /api/v1/repos/joedamato/test_repo/packages.json" do
dsc = File.dirname(__FILE__) + '/fixtures/natty_dsc/jake_1.0-7.dsc'
jake_orig = File.dirname(__FILE__) + '/fixtures/natty_dsc/jake_1.0.orig.tar.bz2'
jake_debian = File.dirname(__FILE__) + '/fixtures/natty_dsc/jake_1.0-7.debian.tar.gz'
 
it "POST /api/v1/repos/joedamato/test_repo/packages/contents.json" do
dsc = 'spec/fixtures/natty_dsc/jake_1.0-7.dsc'
size = File.size(dsc)
package = Package.new(:file => dsc)
source_packages = { "jake_1.0.orig.tar.bz2" => open(jake_orig),
"jake_1.0-7.debian.tar.gz" => open(jake_debian), }
 
result = @client.package_contents("test_repo", package, 99999)
expect(result.succeeded).to be_truthy
expect(result.response["files"]).not_to be_empty
dsc_size = File.size(dsc)
jake_orig_size = File.size(jake_orig)
jake_debian_size = File.size(jake_debian)
combined_size = dsc_size + jake_orig_size + jake_debian_size
 
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
package = Package.new(:file => dsc, :source_files => source_packages)
 
# assert body is at least bigger than fixture file
expect($request.content_length > size).to be_truthy
end
result = @client.put_package("test_repo", package, 22)
expect(result.succeeded).to be_truthy
 
it "GET /api/v1/gem_version.json" do
result = @client.gem_version
expect(result.succeeded).to be_truthy
expect(result.response["major"]).to eq("0")
expect(result.response["minor"]).to eq("2")
expect(result.response["patch"]).to eq("1")
end
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
 
it "GET /api/v1/repos.json" do
result = @client.repositories
expect(result.succeeded).to be_truthy
expect(result.response[0]["private"]).to be_truthy
expect(result.response[0]["fqname"]).to eq("joedamato/test_repo")
expect(result.response[0]["name"]).to eq("test_repo")
end
# assert body is at least bigger than fixture file
expect($request.content_length > combined_size).to be_truthy
end
end
 
it "POST /api/v1/repos.json" do
body = MultiJson.dump({ "repository" => { "name" => "my_repo", "private" => "0" } })
result = @client.create_repository("my_repo")
expect(result.succeeded).to be_truthy
expect($request.content_type).to include("json")
expect($request.content_length).to eq(body.size)
end
describe "listing existing packages in a repository" do
it "returns a json list of packages" do
result = @client.list_packages("test_repo")
expect(result.succeeded).to be_truthy
expect(result.response).to be_a(Array)
package = result.response.first
expect(package["name"]).to eq("gitlab-ce")
expect(package["distro_version"]).to eq("ubuntu/xenial")
expect(package["filename"]).to eq("gitlab-ce_8.15.5-ce.0_amd64.deb")
end
end
 
it "GET /api/v1/repos/joedamato/test_repo.json" do
result = @client.repository("test_repo")
expect(result.succeeded).to be_truthy
expect(result.response["private"]).to be_truthy
expect(result.response["fqname"]).to eq("joedamato/test_repo")
expect(result.response["name"]).to eq("test_repo")
end
describe "package promotion" do
it "promotes an existing package to an existing repository" do
result = @client.promote_package("test_repo", "ubuntu", "xenial", "gitlab-ce_8.15.5-ce.0_amd64.deb", "public")
expect(result.succeeded).to be_truthy
expect(result.response).to be_a(Hash)
expect(result.response["name"]).to eq("gitlab-ce")
expect(result.response["distro_version"]).to eq("ubuntu/xenial")
expect(result.response["repository"]).to eq("public")
expect(result.response["filename"]).to eq("gitlab-ce_8.15.5-ce.0_amd64.deb")
expect(result.response["repository_html_url"]).to eq("/joedamato/public")
end
end
 
it "should raise if the repo name is invalid" do
expect do
result = @client.repository("hi/test_repo")
end.to raise_error(InvalidRepoNameException)
end
it "POST /api/v1/repos/joedamato/test_repo/packages/contents.json" do
dsc = 'spec/fixtures/natty_dsc/jake_1.0-7.dsc'
size = File.size(dsc)
package = Package.new(:file => dsc)
 
it "GET /api/v1/repos/joedamato/invalid_repo.json (invalid repo)" do
result = @client.repository("invalid_repo")
expect(result.succeeded).to be_falsey
end
result = @client.package_contents("test_repo", package, 99999)
expect(result.succeeded).to be_truthy
expect(result.response["files"]).not_to be_empty
 
it "should have a distinct User-Agent that includes the version" do
@client.distributions
expect($request["User-Agent"]).to eq("packagecloud-ruby #{Packagecloud::VERSION}/test_client")
end
#assert content type is set correctly
expect($request.content_type).to include("boundary=")
expect($request.content_type).to include("multipart/form-data")
 
it "should raise if the username has an @ in it" do
expect do
credentials = Credentials.new("hi@test.com", "test_token")
end.to raise_error(InvalidUsernameException)
end
# assert body is at least bigger than fixture file
expect($request.content_length > size).to be_truthy
end
 
it "invalid credentials should raise unauthenticated exception" do
credentials = Credentials.new("joedamato", "test_tafdfasoken")
connection = Connection.new("http", "localhost", 8000)
expect {
Client.new(credentials, "test_client", connection)
}.to raise_error(UnauthenticatedException)
end
it "GET /api/v1/repos/joedamato/test_repo.json" do
result = @client.repository("test_repo")
 
context "timeouts" do
it "should have defaults" do
credentials = Credentials.new("joedamato", "test_token")
connection = Connection.new("http", "localhost", 8000)
client = Client.new(credentials, "test_client", connection)
expect(client.connection.read_timeout).to eql(60)
expect(client.connection.write_timeout).to eql(180)
expect(client.connection.connect_timeout).to eql(60)
expect(result.succeeded).to be_truthy
expect(result.response["private"]).to be_truthy
expect(result.response["fqname"]).to eq("joedamato/test_repo")
expect(result.response["name"]).to eq("test_repo")
end
 
it "should respect passed values" do
credentials = Credentials.new("joedamato", "test_token")
timeouts = { :connect_timeout => 10, :read_timeout => 80, :write_timeout => 280 }
connection = Connection.new("http", "localhost", 8000, timeouts)
client = Client.new(credentials, "test_client", connection)
expect(client.connection.read_timeout).to eql(80)
expect(client.connection.write_timeout).to eql(280)
expect(client.connection.connect_timeout).to eql(10)
it "should raise if the repo name is invalid" do
expect do
result = @client.repository("hi/test_repo")
end.to raise_error(InvalidRepoNameException)
end
end
 
describe "find_distribution_id" do
it "should find ubuntu/breezy" do
id = @client.find_distribution_id("ubuntu/breezy")
expect(id).to be(3)
it "GET /api/v1/repos/joedamato/invalid_repo.json (invalid repo)" do
result = @client.repository("invalid_repo")
expect(result.succeeded).to be_falsey
end
end
 
it "should find just breezy" do
id = @client.find_distribution_id("breezy")
expect(id).to be(3)
context "client error handling and validations" do
it "should have a distinct User-Agent that includes the version" do
@client.distributions
expect($request["User-Agent"]).to eq("packagecloud-ruby #{Packagecloud::VERSION}/test_client")
end
 
it "should find python" do
id = @client.find_distribution_id("python")
expect(id).to be(166)
it "should raise if the username has an @ in it" do
expect do
credentials = Credentials.new("hi@test.com", "test_token")
end.to raise_error(InvalidUsernameException)
end
 
it "should return nil for invalid distro" do
id = @client.find_distribution_id("ubuasdalsdntu/breezy")
expect(id).to be_nil
it "invalid credentials should raise unauthenticated exception" do
wrong_credentials = Credentials.new("joedamato", "test_tafdfasoken")
expect {
Client.new(wrong_credentials, "test_client", connection)
}.to raise_error(UnauthenticatedException)
end
 
it "should raise for amiguous distro queries" do
expect {
@client.find_distribution_id("ubuntu")
}.to raise_error
context "timeouts" do
it "should have defaults" do
client = Client.new(credentials, "test_client", connection)
expect(client.connection.read_timeout).to eql(60)
expect(client.connection.write_timeout).to eql(180)
expect(client.connection.connect_timeout).to eql(60)
end
it "should respect passed values" do
timeouts = { :connect_timeout => 10, :read_timeout => 80, :write_timeout => 280 }
connection_with_timeout = Connection.new("http", "localhost", 8000, timeouts)
client = Client.new(credentials, "test_client", connection_with_timeout)
expect(client.connection.read_timeout).to eql(80)
expect(client.connection.write_timeout).to eql(280)
expect(client.connection.connect_timeout).to eql(10)
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment