2015-08-26 01:42:46 +00:00
|
|
|
module StubGitlabCalls
|
|
|
|
def stub_gitlab_calls
|
|
|
|
stub_session
|
|
|
|
stub_user
|
|
|
|
stub_project_8
|
|
|
|
stub_project_8_hooks
|
|
|
|
stub_projects
|
|
|
|
stub_projects_owned
|
|
|
|
stub_ci_enable
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_js_gitlab_calls
|
2015-09-10 14:55:09 +00:00
|
|
|
allow_any_instance_of(Network).to receive(:projects) { project_hash_array }
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
2016-06-03 14:22:26 +00:00
|
|
|
def stub_ci_pipeline_to_return_yaml_file
|
|
|
|
stub_ci_pipeline_yaml_file(gitlab_ci_yaml)
|
2015-10-05 11:12:00 +00:00
|
|
|
end
|
|
|
|
|
2016-06-03 14:22:26 +00:00
|
|
|
def stub_ci_pipeline_yaml_file(ci_yaml)
|
2016-06-02 14:19:18 +00:00
|
|
|
allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file) { ci_yaml }
|
2015-10-05 11:12:00 +00:00
|
|
|
end
|
|
|
|
|
2015-12-14 11:24:45 +00:00
|
|
|
def stub_ci_builds_disabled
|
|
|
|
allow_any_instance_of(Project).to receive(:builds_enabled?).and_return(false)
|
2015-12-08 10:59:46 +00:00
|
|
|
end
|
|
|
|
|
2016-05-16 23:03:55 +00:00
|
|
|
def stub_container_registry_config(registry_settings)
|
2017-09-15 15:43:49 +00:00
|
|
|
allow(Gitlab.config.registry).to receive_messages(registry_settings)
|
2017-03-24 13:58:25 +00:00
|
|
|
allow(Auth::ContainerRegistryAuthenticationService)
|
|
|
|
.to receive(:full_access_token).and_return('token')
|
2016-05-16 23:03:55 +00:00
|
|
|
end
|
|
|
|
|
2017-04-03 13:52:24 +00:00
|
|
|
def stub_container_registry_tags(repository: :any, tags:)
|
|
|
|
repository = any_args if repository == :any
|
|
|
|
|
2017-04-03 08:38:37 +00:00
|
|
|
allow_any_instance_of(ContainerRegistry::Client)
|
2017-04-03 13:52:24 +00:00
|
|
|
.to receive(:repository_tags).with(repository)
|
|
|
|
.and_return({ 'tags' => tags })
|
2017-04-03 08:38:37 +00:00
|
|
|
|
|
|
|
allow_any_instance_of(ContainerRegistry::Client)
|
2017-04-03 13:52:24 +00:00
|
|
|
.to receive(:repository_manifest).with(repository)
|
|
|
|
.and_return(stub_container_registry_tag_manifest)
|
2017-04-03 08:38:37 +00:00
|
|
|
|
2017-04-03 13:52:24 +00:00
|
|
|
allow_any_instance_of(ContainerRegistry::Client)
|
|
|
|
.to receive(:blob).with(repository)
|
|
|
|
.and_return(stub_container_registry_blob)
|
2016-05-09 20:32:18 +00:00
|
|
|
end
|
|
|
|
|
2015-08-26 01:42:46 +00:00
|
|
|
private
|
|
|
|
|
2017-04-03 13:52:24 +00:00
|
|
|
def stub_container_registry_tag_manifest
|
|
|
|
fixture_path = 'spec/fixtures/container_registry/tag_manifest.json'
|
|
|
|
|
|
|
|
JSON.parse(File.read(Rails.root + fixture_path))
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_container_registry_blob
|
|
|
|
fixture_path = 'spec/fixtures/container_registry/config_blob.json'
|
|
|
|
|
|
|
|
File.read(Rails.root + fixture_path)
|
|
|
|
end
|
|
|
|
|
2015-08-26 01:42:46 +00:00
|
|
|
def gitlab_url
|
2015-09-10 14:04:06 +00:00
|
|
|
Gitlab.config.gitlab.url
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_session
|
|
|
|
f = File.read(Rails.root.join('spec/support/gitlab_stubs/session.json'))
|
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:post, "#{gitlab_url}api/v3/session.json")
|
|
|
|
.with(body: "{\"email\":\"test@test.com\",\"password\":\"123456\"}",
|
|
|
|
headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 201, body: f, headers: { 'Content-Type' => 'application/json' })
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_user
|
|
|
|
f = File.read(Rails.root.join('spec/support/gitlab_stubs/user.json'))
|
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, "#{gitlab_url}api/v3/user?private_token=Wvjy2Krpb7y8xi93owUz")
|
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' })
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, "#{gitlab_url}api/v3/user?access_token=some_token")
|
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' })
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_project_8
|
|
|
|
data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8.json'))
|
2015-09-10 14:55:09 +00:00
|
|
|
allow_any_instance_of(Network).to receive(:project).and_return(JSON.parse(data))
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_project_8_hooks
|
|
|
|
data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8_hooks.json'))
|
2015-09-10 14:55:09 +00:00
|
|
|
allow_any_instance_of(Network).to receive(:project_hooks).and_return(JSON.parse(data))
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_projects
|
|
|
|
f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json'))
|
2015-09-10 14:04:06 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, "#{gitlab_url}api/v3/projects.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz")
|
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' })
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_projects_owned
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, "#{gitlab_url}api/v3/projects/owned.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz")
|
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: "", headers: {})
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_ci_enable
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:put, "#{gitlab_url}api/v3/projects/2/services/gitlab-ci.json?private_token=Wvjy2Krpb7y8xi93owUz")
|
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: "", headers: {})
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_hash_array
|
|
|
|
f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json'))
|
2015-09-14 11:37:18 +00:00
|
|
|
JSON.parse f
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
end
|