2015-09-25 12:07:36 +05:30
|
|
|
module StubGitlabCalls
|
|
|
|
def stub_gitlab_calls
|
|
|
|
stub_user
|
|
|
|
stub_project_8
|
|
|
|
stub_project_8_hooks
|
|
|
|
stub_projects
|
|
|
|
stub_projects_owned
|
|
|
|
stub_ci_enable
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_js_gitlab_calls
|
|
|
|
allow_any_instance_of(Network).to receive(:projects) { project_hash_array }
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def stub_ci_pipeline_to_return_yaml_file
|
|
|
|
stub_ci_pipeline_yaml_file(gitlab_ci_yaml)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def stub_ci_pipeline_yaml_file(ci_yaml)
|
|
|
|
allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file) { ci_yaml }
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def stub_repository_ci_yaml_file(sha:, path: '.gitlab-ci.yml')
|
|
|
|
allow_any_instance_of(Repository)
|
|
|
|
.to receive(:gitlab_ci_yml_for).with(sha, path)
|
|
|
|
.and_return(gitlab_ci_yaml)
|
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
def stub_ci_builds_disabled
|
|
|
|
allow_any_instance_of(Project).to receive(:builds_enabled?).and_return(false)
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def stub_container_registry_config(registry_settings)
|
|
|
|
allow(Gitlab.config.registry).to receive_messages(registry_settings)
|
2017-08-17 22:00:37 +05:30
|
|
|
allow(Auth::ContainerRegistryAuthenticationService)
|
|
|
|
.to receive(:full_access_token).and_return('token')
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def stub_container_registry_tags(repository: :any, tags:)
|
|
|
|
repository = any_args if repository == :any
|
|
|
|
|
|
|
|
allow_any_instance_of(ContainerRegistry::Client)
|
|
|
|
.to receive(:repository_tags).with(repository)
|
|
|
|
.and_return({ 'tags' => tags })
|
|
|
|
|
|
|
|
allow_any_instance_of(ContainerRegistry::Client)
|
2018-03-17 18:26:18 +05:30
|
|
|
.to receive(:repository_manifest).with(repository, anything)
|
2017-08-17 22:00:37 +05:30
|
|
|
.and_return(stub_container_registry_tag_manifest)
|
|
|
|
|
|
|
|
allow_any_instance_of(ContainerRegistry::Client)
|
2018-03-17 18:26:18 +05:30
|
|
|
.to receive(:blob).with(repository, anything, 'application/octet-stream')
|
2017-08-17 22:00:37 +05:30
|
|
|
.and_return(stub_container_registry_blob)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
private
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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-09-25 12:07:36 +05:30
|
|
|
def gitlab_url
|
|
|
|
Gitlab.config.gitlab.url
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_user
|
|
|
|
f = File.read(Rails.root.join('spec/support/gitlab_stubs/user.json'))
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
stub_request(:get, "#{gitlab_url}api/v4/user?private_token=Wvjy2Krpb7y8xi93owUz")
|
2017-09-10 17:25:29 +05:30
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' })
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
stub_request(:get, "#{gitlab_url}api/v4/user?access_token=some_token")
|
2017-09-10 17:25:29 +05:30
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' })
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def stub_project_8
|
|
|
|
data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8.json'))
|
|
|
|
allow_any_instance_of(Network).to receive(:project).and_return(JSON.parse(data))
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_project_8_hooks
|
|
|
|
data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8_hooks.json'))
|
|
|
|
allow_any_instance_of(Network).to receive(:project_hooks).and_return(JSON.parse(data))
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_projects
|
|
|
|
f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json'))
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
stub_request(:get, "#{gitlab_url}api/v4/projects.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz")
|
2017-09-10 17:25:29 +05:30
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' })
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def stub_projects_owned
|
2018-11-08 19:23:39 +05:30
|
|
|
stub_request(:get, "#{gitlab_url}api/v4/projects?owned=true&archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz")
|
2017-09-10 17:25:29 +05:30
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: "", headers: {})
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def stub_ci_enable
|
2018-11-08 19:23:39 +05:30
|
|
|
stub_request(:put, "#{gitlab_url}api/v4/projects/2/services/gitlab-ci.json?private_token=Wvjy2Krpb7y8xi93owUz")
|
2017-09-10 17:25:29 +05:30
|
|
|
.with(headers: { 'Content-Type' => 'application/json' })
|
|
|
|
.to_return(status: 200, body: "", headers: {})
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def project_hash_array
|
|
|
|
f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json'))
|
|
|
|
JSON.parse f
|
|
|
|
end
|
|
|
|
end
|