gitlab-akerl 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.prospectus +11 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +229 -0
- data/CONTRIBUTING.md +195 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +192 -0
- data/Rakefile +9 -0
- data/bin/console +10 -0
- data/bin/setup +6 -0
- data/exe/gitlab +7 -0
- data/gitlab-akerl.gemspec +31 -0
- data/lib/gitlab.rb +45 -0
- data/lib/gitlab/api.rb +19 -0
- data/lib/gitlab/cli.rb +89 -0
- data/lib/gitlab/cli_helpers.rb +241 -0
- data/lib/gitlab/client.rb +48 -0
- data/lib/gitlab/client/branches.rb +91 -0
- data/lib/gitlab/client/build_triggers.rb +51 -0
- data/lib/gitlab/client/build_variables.rb +66 -0
- data/lib/gitlab/client/builds.rb +106 -0
- data/lib/gitlab/client/commits.rb +121 -0
- data/lib/gitlab/client/groups.rb +144 -0
- data/lib/gitlab/client/issues.rb +113 -0
- data/lib/gitlab/client/labels.rb +57 -0
- data/lib/gitlab/client/merge_requests.rb +168 -0
- data/lib/gitlab/client/milestones.rb +78 -0
- data/lib/gitlab/client/namespaces.rb +20 -0
- data/lib/gitlab/client/notes.rb +161 -0
- data/lib/gitlab/client/pipelines.rb +68 -0
- data/lib/gitlab/client/projects.rb +471 -0
- data/lib/gitlab/client/repositories.rb +78 -0
- data/lib/gitlab/client/repository_files.rb +88 -0
- data/lib/gitlab/client/runners.rb +115 -0
- data/lib/gitlab/client/services.rb +50 -0
- data/lib/gitlab/client/snippets.rb +91 -0
- data/lib/gitlab/client/system_hooks.rb +59 -0
- data/lib/gitlab/client/tags.rb +96 -0
- data/lib/gitlab/client/users.rb +250 -0
- data/lib/gitlab/configuration.rb +55 -0
- data/lib/gitlab/error.rb +85 -0
- data/lib/gitlab/file_response.rb +46 -0
- data/lib/gitlab/help.rb +95 -0
- data/lib/gitlab/objectified_hash.rb +34 -0
- data/lib/gitlab/page_links.rb +33 -0
- data/lib/gitlab/paginated_response.rb +97 -0
- data/lib/gitlab/request.rb +117 -0
- data/lib/gitlab/shell.rb +84 -0
- data/lib/gitlab/shell_history.rb +59 -0
- data/lib/gitlab/version.rb +3 -0
- data/spec/fixtures/branch.json +1 -0
- data/spec/fixtures/branch_delete.json +3 -0
- data/spec/fixtures/branches.json +1 -0
- data/spec/fixtures/build.json +38 -0
- data/spec/fixtures/build_artifacts.json +0 -0
- data/spec/fixtures/build_cancel.json +24 -0
- data/spec/fixtures/build_erase.json +24 -0
- data/spec/fixtures/build_retry.json +24 -0
- data/spec/fixtures/builds.json +78 -0
- data/spec/fixtures/builds_commits.json +64 -0
- data/spec/fixtures/compare_merge_request_diff.json +31 -0
- data/spec/fixtures/error_already_exists.json +1 -0
- data/spec/fixtures/error_project_not_found.json +1 -0
- data/spec/fixtures/get_repository_file.json +1 -0
- data/spec/fixtures/git_hook.json +1 -0
- data/spec/fixtures/group.json +60 -0
- data/spec/fixtures/group_create.json +1 -0
- data/spec/fixtures/group_create_with_description.json +1 -0
- data/spec/fixtures/group_delete.json +1 -0
- data/spec/fixtures/group_member.json +1 -0
- data/spec/fixtures/group_member_delete.json +1 -0
- data/spec/fixtures/group_member_edit.json +1 -0
- data/spec/fixtures/group_members.json +1 -0
- data/spec/fixtures/group_projects.json +44 -0
- data/spec/fixtures/group_search.json +2 -0
- data/spec/fixtures/groups.json +2 -0
- data/spec/fixtures/issue.json +1 -0
- data/spec/fixtures/issues.json +1 -0
- data/spec/fixtures/key.json +1 -0
- data/spec/fixtures/keys.json +1 -0
- data/spec/fixtures/label.json +1 -0
- data/spec/fixtures/labels.json +1 -0
- data/spec/fixtures/merge_request.json +1 -0
- data/spec/fixtures/merge_request_changes.json +1 -0
- data/spec/fixtures/merge_request_comment.json +1 -0
- data/spec/fixtures/merge_request_comments.json +1 -0
- data/spec/fixtures/merge_request_commits.json +1 -0
- data/spec/fixtures/merge_requests.json +1 -0
- data/spec/fixtures/milestone.json +1 -0
- data/spec/fixtures/milestone_issues.json +1 -0
- data/spec/fixtures/milestones.json +1 -0
- data/spec/fixtures/namespaces.json +1 -0
- data/spec/fixtures/note.json +1 -0
- data/spec/fixtures/notes.json +1 -0
- data/spec/fixtures/pipeline.json +23 -0
- data/spec/fixtures/pipeline_cancel.json +23 -0
- data/spec/fixtures/pipeline_create.json +23 -0
- data/spec/fixtures/pipeline_retry.json +23 -0
- data/spec/fixtures/pipelines.json +48 -0
- data/spec/fixtures/project.json +1 -0
- data/spec/fixtures/project_commit.json +13 -0
- data/spec/fixtures/project_commit_comment.json +1 -0
- data/spec/fixtures/project_commit_comments.json +1 -0
- data/spec/fixtures/project_commit_diff.json +10 -0
- data/spec/fixtures/project_commit_status.json +42 -0
- data/spec/fixtures/project_commits.json +1 -0
- data/spec/fixtures/project_edit.json +21 -0
- data/spec/fixtures/project_events.json +1 -0
- data/spec/fixtures/project_for_user.json +1 -0
- data/spec/fixtures/project_fork.json +50 -0
- data/spec/fixtures/project_fork_link.json +1 -0
- data/spec/fixtures/project_forked_for_user.json +50 -0
- data/spec/fixtures/project_hook.json +1 -0
- data/spec/fixtures/project_hooks.json +1 -0
- data/spec/fixtures/project_issues.json +1 -0
- data/spec/fixtures/project_key.json +6 -0
- data/spec/fixtures/project_keys.json +6 -0
- data/spec/fixtures/project_runner_enable.json +7 -0
- data/spec/fixtures/project_runners.json +16 -0
- data/spec/fixtures/project_search.json +1 -0
- data/spec/fixtures/project_star.json +44 -0
- data/spec/fixtures/project_tag_annotated.json +1 -0
- data/spec/fixtures/project_tag_lightweight.json +1 -0
- data/spec/fixtures/project_tags.json +1 -0
- data/spec/fixtures/project_unstar.json +44 -0
- data/spec/fixtures/project_update_commit_status.json +20 -0
- data/spec/fixtures/projects.json +1 -0
- data/spec/fixtures/raw_file.json +2 -0
- data/spec/fixtures/release_create.json +1 -0
- data/spec/fixtures/release_update.json +1 -0
- data/spec/fixtures/repository_file.json +1 -0
- data/spec/fixtures/runner.json +26 -0
- data/spec/fixtures/runner_delete.json +7 -0
- data/spec/fixtures/runner_edit.json +26 -0
- data/spec/fixtures/runners.json +16 -0
- data/spec/fixtures/runners_all.json +30 -0
- data/spec/fixtures/service.json +1 -0
- data/spec/fixtures/session.json +1 -0
- data/spec/fixtures/shell_history.json +2 -0
- data/spec/fixtures/snippet.json +1 -0
- data/spec/fixtures/snippet_content.json +3 -0
- data/spec/fixtures/snippets.json +1 -0
- data/spec/fixtures/system_hook.json +1 -0
- data/spec/fixtures/system_hooks.json +1 -0
- data/spec/fixtures/tag.json +1 -0
- data/spec/fixtures/tag_create.json +1 -0
- data/spec/fixtures/tag_create_with_description.json +1 -0
- data/spec/fixtures/tag_delete.json +1 -0
- data/spec/fixtures/tags.json +1 -0
- data/spec/fixtures/team_member.json +1 -0
- data/spec/fixtures/team_members.json +1 -0
- data/spec/fixtures/tree.json +1 -0
- data/spec/fixtures/trigger.json +7 -0
- data/spec/fixtures/triggers.json +16 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/fixtures/user_block_unblock.json +1 -0
- data/spec/fixtures/user_email.json +1 -0
- data/spec/fixtures/user_emails.json +1 -0
- data/spec/fixtures/user_search.json +1 -0
- data/spec/fixtures/users.json +1 -0
- data/spec/fixtures/variable.json +4 -0
- data/spec/fixtures/variables.json +10 -0
- data/spec/gitlab/cli_helpers_spec.rb +57 -0
- data/spec/gitlab/cli_spec.rb +110 -0
- data/spec/gitlab/client/branches_spec.rb +99 -0
- data/spec/gitlab/client/build_triggers_spec.rb +67 -0
- data/spec/gitlab/client/build_variables_spec.rb +86 -0
- data/spec/gitlab/client/builds_spec.rb +148 -0
- data/spec/gitlab/client/client_spec.rb +11 -0
- data/spec/gitlab/client/commits_spec.rb +137 -0
- data/spec/gitlab/client/groups_spec.rb +197 -0
- data/spec/gitlab/client/issues_spec.rb +138 -0
- data/spec/gitlab/client/labels_spec.rb +68 -0
- data/spec/gitlab/client/merge_requests_spec.rb +177 -0
- data/spec/gitlab/client/milestones_spec.rb +82 -0
- data/spec/gitlab/client/namespaces_spec.rb +22 -0
- data/spec/gitlab/client/notes_spec.rb +205 -0
- data/spec/gitlab/client/pipelines_spec.rb +95 -0
- data/spec/gitlab/client/projects_spec.rb +603 -0
- data/spec/gitlab/client/repositories_spec.rb +109 -0
- data/spec/gitlab/client/repository_files_spec.rb +62 -0
- data/spec/gitlab/client/runners_spec.rb +185 -0
- data/spec/gitlab/client/services_spec.rb +55 -0
- data/spec/gitlab/client/snippets_spec.rb +100 -0
- data/spec/gitlab/client/system_hooks_spec.rb +69 -0
- data/spec/gitlab/client/tags_spec.rb +109 -0
- data/spec/gitlab/client/users_spec.rb +418 -0
- data/spec/gitlab/error_spec.rb +45 -0
- data/spec/gitlab/file_response_spec.rb +33 -0
- data/spec/gitlab/help_spec.rb +46 -0
- data/spec/gitlab/objectified_hash_spec.rb +48 -0
- data/spec/gitlab/page_links_spec.rb +16 -0
- data/spec/gitlab/paginated_response_spec.rb +60 -0
- data/spec/gitlab/request_spec.rb +73 -0
- data/spec/gitlab/shell_history_spec.rb +53 -0
- data/spec/gitlab/shell_spec.rb +80 -0
- data/spec/gitlab_spec.rb +97 -0
- data/spec/spec_helper.rb +74 -0
- metadata +476 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Gitlab::Error do
|
4
|
+
describe "#handle_message" do
|
5
|
+
require "stringio"
|
6
|
+
|
7
|
+
before do
|
8
|
+
request_object = HTTParty::Request.new(Net::HTTP::Get, '/')
|
9
|
+
response_object = Net::HTTPOK.new('1.1', 200, 'OK')
|
10
|
+
body = StringIO.new("{foo:'bar'}")
|
11
|
+
def body.message; self.string; end
|
12
|
+
|
13
|
+
parsed_response = lambda { body }
|
14
|
+
response_object['last-modified'] = Date.new(2010, 1, 15).to_s
|
15
|
+
response_object['content-length'] = "1024"
|
16
|
+
|
17
|
+
response = HTTParty::Response.new(request_object, response_object, parsed_response, body: body)
|
18
|
+
@error = Gitlab::Error::ResponseError.new(response)
|
19
|
+
|
20
|
+
@array = Array.new(['First message.', 'Second message.'])
|
21
|
+
@obj_h = Gitlab::ObjectifiedHash.new(user: ['not set'],
|
22
|
+
password: ['too short'],
|
23
|
+
embed_entity: { foo: ['bar'], sna: ['fu'] })
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when passed an ObjectifiedHash" do
|
27
|
+
it "should return a joined string of error messages sorted by key" do
|
28
|
+
expect(@error.send(:handle_message, @obj_h)).to eq("'embed_entity' (foo: bar) (sna: fu), 'password' too short, 'user' not set")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when passed an Array" do
|
33
|
+
it "should return a joined string of messages" do
|
34
|
+
expect(@error.send(:handle_message, @array)).to eq("First message. Second message.")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when passed a String" do
|
39
|
+
it "should return the String untouched" do
|
40
|
+
error = 'this is an error string'
|
41
|
+
expect(@error.send(:handle_message, error)).to eq('this is an error string')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitlab::FileResponse do
|
4
|
+
before do
|
5
|
+
@file_response = Gitlab::FileResponse.new StringIO.new("", 'rb+')
|
6
|
+
end
|
7
|
+
|
8
|
+
context '.empty?' do
|
9
|
+
it "shoudl return false" do
|
10
|
+
expect(@file_response.empty?).to be false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context '.to_hash' do
|
15
|
+
it "should have `filename` key and `data` key" do
|
16
|
+
h = @file_response.to_hash
|
17
|
+
expect(h.has_key?(:filename)).to be_truthy
|
18
|
+
expect(h.has_key?(:data)).to be_truthy
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context '.parse_headers!' do
|
23
|
+
it "should parse headers" do
|
24
|
+
@file_response.parse_headers!('Content-Disposition' => 'attachment; filename=artifacts.zip')
|
25
|
+
expect(@file_response.filename).to eq "artifacts.zip"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should handle quoted filenames" do
|
29
|
+
@file_response.parse_headers!('Content-Disposition' => 'attachment; filename="artifacts.zip"')
|
30
|
+
expect(@file_response.filename).to eq "artifacts.zip"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitlab::Help do
|
4
|
+
describe ".ri_cmd" do
|
5
|
+
context "ri command found" do
|
6
|
+
it "should return the path to RI" do
|
7
|
+
allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('/usr/bin/ri')
|
8
|
+
expect(Gitlab::Help.ri_cmd).to eq('/usr/bin/ri')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "ri command NOT found" do
|
13
|
+
it "should raise" do
|
14
|
+
allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('')
|
15
|
+
expect { Gitlab::Help.ri_cmd }.to raise_error RuntimeError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".change_help_output!" do
|
21
|
+
before do
|
22
|
+
@cmd = "create_branch"
|
23
|
+
@help_output = "Gitlab.#{@cmd}(4, 'new-branch', 'master')"
|
24
|
+
@help_output_with_options = "Gitlab.groups({ per_page: 3 })"
|
25
|
+
end
|
26
|
+
it "should return a String of modified output" do
|
27
|
+
Gitlab::Help.change_help_output! @cmd, @help_output
|
28
|
+
expect(@help_output).to eq("Gitlab.create_branch 4 'new-branch' 'master'")
|
29
|
+
end
|
30
|
+
it "should format options hash and return a String of modified output" do
|
31
|
+
Gitlab::Help.change_help_output! 'groups', @help_output_with_options
|
32
|
+
expect(@help_output_with_options).to eq("Gitlab.groups \"{ per_page: 3 }\"")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".namespace" do
|
37
|
+
before do
|
38
|
+
@cmd = 'create_tag'
|
39
|
+
@namespace = Gitlab::Help.namespace @cmd
|
40
|
+
end
|
41
|
+
it "should return the full namespace for a command" do
|
42
|
+
expect(@namespace).to be_a String
|
43
|
+
expect(@namespace).to eq("Gitlab::Client::Tags.#{@cmd}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitlab::ObjectifiedHash do
|
4
|
+
before do
|
5
|
+
@hash = { a: 1, b: 2, 'string' => 'string', symbol: :symbol }
|
6
|
+
@oh = Gitlab::ObjectifiedHash.new @hash
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should objectify hash" do
|
10
|
+
expect(@oh.a).to eq(@hash[:a])
|
11
|
+
expect(@oh.b).to eq(@hash[:b])
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#to_hash" do
|
15
|
+
it "should return an original hash" do
|
16
|
+
expect(@oh.to_hash).to eq(@hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have an alias #to_h" do
|
20
|
+
expect(@oh.respond_to?(:to_h)).to be_truthy
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#inspect" do
|
25
|
+
it "should return a formatted string" do
|
26
|
+
pretty_string = "#<#{@oh.class.name}:#{@oh.object_id} {hash: #{@hash}}"
|
27
|
+
expect(@oh.inspect).to eq(pretty_string)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#respond_to" do
|
32
|
+
it "should return true for methods this object responds to through method_missing as sym" do
|
33
|
+
expect(@oh.respond_to?(:a)).to be_truthy
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return true for methods this object responds to through method_missing as string" do
|
37
|
+
expect(@oh.respond_to?('string')).to be_truthy
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not care if you use a string or symbol to reference a method" do
|
41
|
+
expect(@oh.respond_to?(:string)).to be_truthy
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not care if you use a string or symbol to reference a method" do
|
45
|
+
expect(@oh.respond_to?('symbol')).to be_truthy
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitlab::PageLinks do
|
4
|
+
before do
|
5
|
+
@page_links = Gitlab::PageLinks.new('Link' => "<http://example.com/api/v3/projects?page=1&per_page=5>; rel=\"first\", <http://example.com/api/v3/projects?page=20&per_page=5>; rel=\"last\", <http://example.com/api/v3/projects?page=7&per_page=5>; rel=\"prev\", <http://example.com/api/v3/projects?page=9&per_page=5>; rel=\"next\"")
|
6
|
+
end
|
7
|
+
|
8
|
+
context '.extract_links' do
|
9
|
+
it 'should extract link header appropriately' do
|
10
|
+
expect(@page_links.last).to eql 'http://example.com/api/v3/projects?page=20&per_page=5'
|
11
|
+
expect(@page_links.first).to eql 'http://example.com/api/v3/projects?page=1&per_page=5'
|
12
|
+
expect(@page_links.next).to eql 'http://example.com/api/v3/projects?page=9&per_page=5'
|
13
|
+
expect(@page_links.prev).to eql 'http://example.com/api/v3/projects?page=7&per_page=5'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitlab::PaginatedResponse do
|
4
|
+
before do
|
5
|
+
array = [1, 2, 3, 4]
|
6
|
+
@paginated_response = Gitlab::PaginatedResponse.new array
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should respond to *_page and has_*_page methods" do
|
10
|
+
expect(@paginated_response).to respond_to :first_page
|
11
|
+
expect(@paginated_response).to respond_to :last_page
|
12
|
+
expect(@paginated_response).to respond_to :next_page
|
13
|
+
expect(@paginated_response).to respond_to :prev_page
|
14
|
+
expect(@paginated_response).to respond_to :has_first_page?
|
15
|
+
expect(@paginated_response).to respond_to :has_last_page?
|
16
|
+
expect(@paginated_response).to respond_to :has_next_page?
|
17
|
+
expect(@paginated_response).to respond_to :has_prev_page?
|
18
|
+
end
|
19
|
+
|
20
|
+
context '.parse_headers!' do
|
21
|
+
it "should parse headers" do
|
22
|
+
@paginated_response.parse_headers!('Link' => "<http://example.com/api/v3/projects?page=1&per_page=5>; rel=\"first\", <http://example.com/api/v3/projects?page=20&per_page=5>; rel=\"last\"")
|
23
|
+
client = @paginated_response.client = double('client')
|
24
|
+
first_page_response = double('first_page_response')
|
25
|
+
last_page_response = double('last_page_response')
|
26
|
+
allow(client).to receive(:endpoint).and_return("http://example.com/api/v3")
|
27
|
+
allow(client).to receive(:get).with("/projects?page=1&per_page=5").and_return(first_page_response)
|
28
|
+
allow(client).to receive(:get).with("/projects?page=20&per_page=5").and_return(last_page_response)
|
29
|
+
expect(@paginated_response.has_first_page?).to be true
|
30
|
+
expect(@paginated_response.has_last_page?).to be true
|
31
|
+
expect(@paginated_response.has_next_page?).to be false
|
32
|
+
expect(@paginated_response.has_prev_page?).to be false
|
33
|
+
expect(@paginated_response.first_page).to be first_page_response
|
34
|
+
expect(@paginated_response.last_page).to be last_page_response
|
35
|
+
expect(@paginated_response.next_page).to be_nil
|
36
|
+
expect(@paginated_response.prev_page).to be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context '.each_page' do
|
41
|
+
it "should iterate pages" do
|
42
|
+
next_page = double('next_page')
|
43
|
+
allow(@paginated_response).to receive(:has_next_page?).and_return(true)
|
44
|
+
allow(@paginated_response).to receive(:next_page).and_return(next_page)
|
45
|
+
allow(next_page).to receive(:has_next_page?).and_return(false)
|
46
|
+
expect { |b| @paginated_response.each_page(&b) }.to yield_successive_args(@paginated_response, next_page)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '.auto_paginate' do
|
51
|
+
it "should returns an array if block is not given" do
|
52
|
+
next_page = double('next_page')
|
53
|
+
allow(@paginated_response).to receive(:has_next_page?).and_return(true)
|
54
|
+
allow(@paginated_response).to receive(:next_page).and_return(next_page)
|
55
|
+
allow(next_page).to receive(:has_next_page?).and_return(false)
|
56
|
+
allow(next_page).to receive(:to_ary).and_return([5, 6, 7, 8])
|
57
|
+
expect(@paginated_response.auto_paginate).to contain_exactly(1, 2, 3, 4, 5, 6, 7, 8)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitlab::Request do
|
4
|
+
it { should respond_to :get }
|
5
|
+
it { should respond_to :post }
|
6
|
+
it { should respond_to :put }
|
7
|
+
it { should respond_to :delete }
|
8
|
+
before do
|
9
|
+
@request = Gitlab::Request.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".default_options" do
|
13
|
+
it "should have default values" do
|
14
|
+
default_options = Gitlab::Request.default_options
|
15
|
+
expect(default_options).to be_a Hash
|
16
|
+
expect(default_options[:parser]).to be_a Proc
|
17
|
+
expect(default_options[:format]).to eq(:json)
|
18
|
+
expect(default_options[:headers]).to eq('Accept' => 'application/json')
|
19
|
+
expect(default_options[:default_params]).to be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".parse" do
|
24
|
+
it "should return ObjectifiedHash" do
|
25
|
+
body = JSON.unparse(a: 1, b: 2)
|
26
|
+
expect(Gitlab::Request.parse(body)).to be_an Gitlab::ObjectifiedHash
|
27
|
+
expect(Gitlab::Request.parse("true")).to be true
|
28
|
+
expect(Gitlab::Request.parse("false")).to be false
|
29
|
+
|
30
|
+
expect { Gitlab::Request.parse("string") }.to raise_error(Gitlab::Error::Parsing)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#set_request_defaults" do
|
35
|
+
context "when endpoint is not set" do
|
36
|
+
it "should raise Error::MissingCredentials" do
|
37
|
+
@request.endpoint = nil
|
38
|
+
expect do
|
39
|
+
@request.set_request_defaults
|
40
|
+
end.to raise_error(Gitlab::Error::MissingCredentials, 'Please set an endpoint to API')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when endpoint is set" do
|
45
|
+
before(:each) do
|
46
|
+
@request.endpoint = 'http://rabbit-hole.example.org'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should set default_params" do
|
50
|
+
@request.set_request_defaults('sudoer')
|
51
|
+
expect(Gitlab::Request.default_params).to eq(sudo: 'sudoer')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#set_authorization_header" do
|
57
|
+
it "should raise MissingCredentials when auth_token and private_token are not set" do
|
58
|
+
expect do
|
59
|
+
@request.send(:set_authorization_header, {})
|
60
|
+
end.to raise_error(Gitlab::Error::MissingCredentials)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set the correct header when given a private_token" do
|
64
|
+
@request.private_token = 'ys9BtunN3rDKbaJCYXaN'
|
65
|
+
expect(@request.send(:set_authorization_header, {})).to eq("PRIVATE-TOKEN" => 'ys9BtunN3rDKbaJCYXaN')
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set the correct header when setting an auth_token via the private_token config option" do
|
69
|
+
@request.private_token = '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603'
|
70
|
+
expect(@request.send(:set_authorization_header, {})).to eq("Authorization" => "Bearer 3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe Gitlab::Shell::History do
|
5
|
+
context 'saving to a file' do
|
6
|
+
before do
|
7
|
+
@file = Tempfile.new('.gitlab_shell_history')
|
8
|
+
@history = Gitlab::Shell::History.new(file_path: @file.path)
|
9
|
+
end
|
10
|
+
|
11
|
+
after { @file.close(true) }
|
12
|
+
|
13
|
+
it 'saves the lines' do
|
14
|
+
@history << 'party on, dudes'
|
15
|
+
@history << 'be excellent to each other'
|
16
|
+
@history.save
|
17
|
+
expect(File.read @file.path).
|
18
|
+
to eq("party on, dudes\nbe excellent to each other\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has the lines' do
|
22
|
+
@history << 'party on, dudes'
|
23
|
+
@history << 'be excellent to each other'
|
24
|
+
expect(@history.lines).
|
25
|
+
to eq(["party on, dudes", "be excellent to each other"])
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'limits the lines to GITLAB_HISTFILESIZE' do
|
29
|
+
ENV['GITLAB_HISTFILESIZE'] = '2'
|
30
|
+
@history << 'bogus'
|
31
|
+
@history << 'party on, dudes'
|
32
|
+
@history << 'be excellent to each other'
|
33
|
+
@history.save
|
34
|
+
expect(@history.lines).
|
35
|
+
to eq(["party on, dudes", "be excellent to each other"])
|
36
|
+
expect(File.read @file.path).
|
37
|
+
to eq("party on, dudes\nbe excellent to each other\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'loading a file' do
|
42
|
+
before do
|
43
|
+
@file = load_fixture('shell_history')
|
44
|
+
@history = Gitlab::Shell::History.new(file_path: @file.path)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'has the lines' do
|
48
|
+
@history.load
|
49
|
+
expect(@history.lines).
|
50
|
+
to eq(["party on, dudes", "be excellent to each other"])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitlab::Shell do
|
4
|
+
before do
|
5
|
+
Gitlab::Shell.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".execute" do
|
9
|
+
context "invalid command" do
|
10
|
+
it "should raise" do
|
11
|
+
expect { Gitlab::Shell.execute 'foobar', [] }.to raise_error(RuntimeError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".history" do
|
17
|
+
before do
|
18
|
+
@history = Gitlab::Shell.history
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return a Gitlab::Shell::History instance" do
|
22
|
+
expect(@history).to be_a Gitlab::Shell::History
|
23
|
+
end
|
24
|
+
it "should respond to :save" do
|
25
|
+
expect(@history).to respond_to :save
|
26
|
+
end
|
27
|
+
it "should respond to :load" do
|
28
|
+
expect(@history).to respond_to :load
|
29
|
+
end
|
30
|
+
it "should respond to :<<" do
|
31
|
+
expect(@history).to respond_to :<<
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".setup" do
|
36
|
+
it "should set the Readline completion_proc" do
|
37
|
+
completion = Readline.completion_proc
|
38
|
+
expect(completion).to be_truthy
|
39
|
+
expect(completion).to be_a Proc
|
40
|
+
end
|
41
|
+
it "should set the Readline completion_append_character" do
|
42
|
+
completion_character = Readline.completion_append_character
|
43
|
+
expect(completion_character).to eq(' ')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".completion" do
|
48
|
+
before do
|
49
|
+
@comp = Gitlab::Shell.completion
|
50
|
+
end
|
51
|
+
it "should return a Proc object" do
|
52
|
+
expect(@comp).to be_a Proc
|
53
|
+
end
|
54
|
+
context "called with an argument" do
|
55
|
+
it "should return an Array of matching commands" do
|
56
|
+
completed_cmds = @comp.call 'group'
|
57
|
+
expect(completed_cmds).to be_a Array
|
58
|
+
expect(completed_cmds.sort).to eq(%w(group group_members group_projects group_search groups))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ".parse_input" do
|
64
|
+
context "with arguments" do
|
65
|
+
it "should set command & arguments" do
|
66
|
+
Gitlab::Shell.parse_input('create_branch 1 "api" "master"')
|
67
|
+
expect(Gitlab::Shell.command).to eq('create_branch')
|
68
|
+
expect(Gitlab::Shell.arguments).to eq(%w(1 api master))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "without arguments" do
|
73
|
+
it 'should set command & empty arguments' do
|
74
|
+
Gitlab::Shell.parse_input('exit')
|
75
|
+
expect(Gitlab::Shell.command).to eq('exit')
|
76
|
+
expect(Gitlab::Shell.arguments).to be_empty
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|