diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-24 03:07:31 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-24 03:07:31 +0300 |
commit | 3888bc4261500c275759683076e07baaf352e5ec (patch) | |
tree | eb70e0415be41a1d713cc89f211a6045778cd6b8 /spec | |
parent | 33e1622bfe5afb2eea08ff06e44de490383a93e3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb | 95 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/kubernetes/kube_client_spec.rb | 37 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/ci/pipeline_config_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 1 | ||||
-rw-r--r-- | spec/serializers/build_artifact_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/build_details_entity_spec.rb | 22 | ||||
-rw-r--r-- | spec/services/prometheus/adapter_service_spec.rb | 7 | ||||
-rw-r--r-- | spec/support/helpers/kubernetes_helpers.rb | 127 |
10 files changed, 247 insertions, 73 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb index f84f10bdc46..aaea044595f 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb @@ -29,6 +29,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq 'repository_source' + expect(pipeline.pipeline_config).to be_nil expect(command.config_content).to eq('the-content') end end @@ -40,6 +41,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq 'auto_devops_source' + expect(pipeline.pipeline_config).to be_nil template = Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps') expect(command.config_content).to eq(template.content) end @@ -52,6 +54,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq 'auto_devops_source' + expect(pipeline.pipeline_config).to be_nil template = Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps') expect(command.config_content).to eq(template.content) end @@ -71,6 +74,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq 'repository_source' + expect(pipeline.pipeline_config).to be_nil expect(command.config_content).to eq('the-content') end end @@ -91,6 +95,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq 'auto_devops_source' + expect(pipeline.pipeline_config).to be_nil template = Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps') expect(command.config_content).to eq(template.content) end @@ -105,6 +110,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq 'auto_devops_source' + expect(pipeline.pipeline_config).to be_nil template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') expect(command.config_content).to eq(template.content) end @@ -122,6 +128,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq('unknown_source') + expect(pipeline.pipeline_config).to be_nil expect(command.config_content).to be_nil expect(pipeline.errors.full_messages).to include('Missing CI config file') end @@ -130,6 +137,13 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do context 'when config is defined in a custom path in the repository' do let(:ci_config_path) { 'path/to/config.yml' } + let(:config_content_result) do + <<~EOY + --- + include: + - local: #{ci_config_path} + EOY + end before do expect(project.repository) @@ -142,47 +156,59 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq 'repository_source' - expect(command.config_content).to eq(<<~EOY) - --- - include: - - local: #{ci_config_path} - EOY + expect(pipeline.pipeline_config.content).to eq(config_content_result) + expect(command.config_content).to eq(config_content_result) end end context 'when config is defined remotely' do let(:ci_config_path) { 'http://example.com/path/to/ci/config.yml' } + let(:config_content_result) do + <<~EOY + --- + include: + - remote: #{ci_config_path} + EOY + end it 'builds root config including the remote config' do subject.perform! expect(pipeline.config_source).to eq 'remote_source' - expect(command.config_content).to eq(<<~EOY) - --- - include: - - remote: #{ci_config_path} - EOY + expect(pipeline.pipeline_config.content).to eq(config_content_result) + expect(command.config_content).to eq(config_content_result) end end context 'when config is defined in a separate repository' do let(:ci_config_path) { 'path/to/.gitlab-ci.yml@another-group/another-repo' } - - it 'builds root config including the path to another repository' do - subject.perform! - - expect(pipeline.config_source).to eq 'external_project_source' - expect(command.config_content).to eq(<<~EOY) + let(:config_content_result) do + <<~EOY --- include: - project: another-group/another-repo file: path/to/.gitlab-ci.yml EOY end + + it 'builds root config including the path to another repository' do + subject.perform! + + expect(pipeline.config_source).to eq 'external_project_source' + expect(pipeline.pipeline_config.content).to eq(config_content_result) + expect(command.config_content).to eq(config_content_result) + end end context 'when config is defined in the default .gitlab-ci.yml' do let(:ci_config_path) { nil } + let(:config_content_result) do + <<~EOY + --- + include: + - local: ".gitlab-ci.yml" + EOY + end before do expect(project.repository) @@ -195,16 +221,20 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq 'repository_source' - expect(command.config_content).to eq(<<~EOY) - --- - include: - - local: ".gitlab-ci.yml" - EOY + expect(pipeline.pipeline_config.content).to eq(config_content_result) + expect(command.config_content).to eq(config_content_result) end end context 'when config is the Auto-Devops template' do let(:ci_config_path) { nil } + let(:config_content_result) do + <<~EOY + --- + include: + - template: Beta/Auto-DevOps.gitlab-ci.yml + EOY + end before do expect(project).to receive(:auto_devops_enabled?).and_return(true) @@ -219,11 +249,8 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq 'auto_devops_source' - expect(command.config_content).to eq(<<~EOY) - --- - include: - - template: Beta/Auto-DevOps.gitlab-ci.yml - EOY + expect(pipeline.pipeline_config.content).to eq(config_content_result) + expect(command.config_content).to eq(config_content_result) end end @@ -232,16 +259,21 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do stub_feature_flags(auto_devops_beta: false) end - it 'builds root config including the auto-devops template' do - subject.perform! - - expect(pipeline.config_source).to eq 'auto_devops_source' - expect(command.config_content).to eq(<<~EOY) + let(:config_content_result) do + <<~EOY --- include: - template: Auto-DevOps.gitlab-ci.yml EOY end + + it 'builds root config including the auto-devops template' do + subject.perform! + + expect(pipeline.config_source).to eq 'auto_devops_source' + expect(pipeline.pipeline_config.content).to eq(config_content_result) + expect(command.config_content).to eq(config_content_result) + end end end @@ -256,6 +288,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do subject.perform! expect(pipeline.config_source).to eq('unknown_source') + expect(pipeline.pipeline_config).to be_nil expect(command.config_content).to be_nil expect(pipeline.errors.full_messages).to include('Missing CI config file') end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 8f0f09bc0be..a625d2f6cce 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -190,6 +190,7 @@ ci_pipelines: - job_artifacts - vulnerabilities_occurrence_pipelines - vulnerability_findings +- pipeline_config pipeline_variables: - pipeline stages: diff --git a/spec/lib/gitlab/kubernetes/kube_client_spec.rb b/spec/lib/gitlab/kubernetes/kube_client_spec.rb index 59e81d89a50..e08981a3415 100644 --- a/spec/lib/gitlab/kubernetes/kube_client_spec.rb +++ b/spec/lib/gitlab/kubernetes/kube_client_spec.rb @@ -136,6 +136,20 @@ describe Gitlab::Kubernetes::KubeClient do end end + describe '#istio_client' do + subject { client.istio_client } + + it_behaves_like 'a Kubeclient' + + it 'has the Istio API group endpoint' do + expect(subject.api_endpoint.to_s).to match(%r{\/apis\/networking.istio.io\Z}) + end + + it 'has the api_version' do + expect(subject.instance_variable_get(:@api_version)).to eq('v1alpha3') + end + end + describe '#knative_client' do subject { client.knative_client } @@ -233,6 +247,29 @@ describe Gitlab::Kubernetes::KubeClient do end end + describe 'istio API group' do + let(:istio_client) { client.istio_client } + + [ + :create_gateway, + :get_gateway, + :update_gateway + ].each do |method| + describe "##{method}" do + include_examples 'redirection not allowed', method + include_examples 'dns rebinding not allowed', method + + it 'delegates to the istio client' do + expect(client).to delegate_method(method).to(:istio_client) + end + + it 'responds to the method' do + expect(client).to respond_to method + end + end + end + end + describe 'non-entity methods' do it 'does not proxy for non-entity methods' do expect(client).not_to respond_to :proxy_url diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index ee8e9805c49..f9c17f732b6 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2248,24 +2248,14 @@ describe Ci::Build do end end - describe '#has_expiring_archive_artifacts?' do + describe '#has_expiring_artifacts?' do context 'when artifacts have expiration date set' do before do build.update(artifacts_expire_at: 1.day.from_now) end - context 'and job artifacts file exists' do - let!(:archive) { create(:ci_job_artifact, :archive, job: build) } - - it 'has expiring artifacts' do - expect(build).to have_expiring_archive_artifacts - end - end - - context 'and job artifacts file does not exist' do - it 'does not have expiring artifacts' do - expect(build).not_to have_expiring_archive_artifacts - end + it 'has expiring artifacts' do + expect(build).to have_expiring_artifacts end end @@ -2275,7 +2265,7 @@ describe Ci::Build do end it 'does not have expiring artifacts' do - expect(build).not_to have_expiring_archive_artifacts + expect(build).not_to have_expiring_artifacts end end end diff --git a/spec/models/ci/pipeline_config_spec.rb b/spec/models/ci/pipeline_config_spec.rb new file mode 100644 index 00000000000..25f514ee5ab --- /dev/null +++ b/spec/models/ci/pipeline_config_spec.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::PipelineConfig, type: :model do + it { is_expected.to belong_to(:pipeline) } + + it { is_expected.to validate_presence_of(:pipeline) } + it { is_expected.to validate_presence_of(:content) } +end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 3f9e882ea52..286d2ac4fe6 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -35,6 +35,7 @@ describe Ci::Pipeline, :mailer do it { is_expected.to have_one(:source_pipeline) } it { is_expected.to have_one(:triggered_by_pipeline) } it { is_expected.to have_one(:source_job) } + it { is_expected.to have_one(:pipeline_config) } it { is_expected.to validate_presence_of(:sha) } it { is_expected.to validate_presence_of(:status) } diff --git a/spec/serializers/build_artifact_entity_spec.rb b/spec/serializers/build_artifact_entity_spec.rb index 5f1d5093e0a..09fe094fff1 100644 --- a/spec/serializers/build_artifact_entity_spec.rb +++ b/spec/serializers/build_artifact_entity_spec.rb @@ -4,8 +4,6 @@ require 'spec_helper' describe BuildArtifactEntity do let(:job) { create(:ci_build, name: 'test:job', artifacts_expire_at: 1.hour.from_now) } - let!(:archive) { create(:ci_job_artifact, :archive, job: job) } - let!(:metadata) { create(:ci_job_artifact, :metadata, job: job) } let(:entity) do described_class.new(job, request: double) diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb index 6fe9eaedfeb..91c5fd6bf2c 100644 --- a/spec/serializers/build_details_entity_spec.rb +++ b/spec/serializers/build_details_entity_spec.rb @@ -176,27 +176,5 @@ describe BuildDetailsEntity do expect(subject[:reports].first[:file_type]).to eq('codequality') end end - - context 'when the build has no archive type artifacts' do - let!(:report) { create(:ci_job_artifact, :codequality, job: build) } - - it 'does not expose any artifact actions path' do - expect(subject[:artifact].keys).not_to include(:download_path, :browse_path, :keep_path) - end - end - - context 'when the build has archive type artifacts' do - let!(:report) { create(:ci_job_artifact, :codequality, job: build) } - let!(:archive) { create(:ci_job_artifact, :archive, job: build) } - let!(:metadata) { create(:ci_job_artifact, :metadata, job: build) } - - before do - build.update(artifacts_expire_at: 7.days.from_now) - end - - it 'exposes artifact details' do - expect(subject[:artifact].keys).to include(:download_path, :browse_path, :keep_path, :expire_at, :expired) - end - end end end diff --git a/spec/services/prometheus/adapter_service_spec.rb b/spec/services/prometheus/adapter_service_spec.rb index 52e035e1f70..3c075fc1581 100644 --- a/spec/services/prometheus/adapter_service_spec.rb +++ b/spec/services/prometheus/adapter_service_spec.rb @@ -3,13 +3,12 @@ require 'spec_helper' describe Prometheus::AdapterService do - let(:project) { create(:project) } + let_it_be(:project) { create(:project) } + let_it_be(:cluster, reload: true) { create(:cluster, :provided_by_user, environment_scope: '*', projects: [project]) } - subject { described_class.new(project) } + subject { described_class.new(project, cluster) } describe '#prometheus_adapter' do - let(:cluster) { create(:cluster, :provided_by_user, environment_scope: '*', projects: [project]) } - context 'prometheus service can execute queries' do let(:prometheus_service) { double(:prometheus_service, can_query?: true) } diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index b2145ca729f..2fabfb94928 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -33,6 +33,14 @@ module KubernetesHelpers .to_return(kube_response(kube_v1_rbac_authorization_discovery_body)) end + def stub_kubeclient_discover_istio(api_url) + stub_kubeclient_discover_base(api_url) + + WebMock + .stub_request(:get, api_url + '/apis/networking.istio.io/v1alpha3') + .to_return(kube_response(kube_istio_discovery_body)) + end + def stub_kubeclient_discover(api_url) stub_kubeclient_discover_base(api_url) @@ -244,6 +252,16 @@ module KubernetesHelpers .to_return(kube_response({})) end + def stub_kubeclient_get_gateway(api_url, name, namespace: 'default') + WebMock.stub_request(:get, api_url + "/apis/networking.istio.io/v1alpha3/namespaces/#{namespace}/gateways/#{name}") + .to_return(kube_response(kube_istio_gateway_body(name, namespace))) + end + + def stub_kubeclient_put_gateway(api_url, name, namespace: 'default') + WebMock.stub_request(:put, api_url + "/apis/networking.istio.io/v1alpha3/namespaces/#{namespace}/gateways/#{name}") + .to_return(kube_response({})) + end + def kube_v1_secret_body(**options) { "kind" => "SecretList", @@ -311,6 +329,115 @@ module KubernetesHelpers } end + def kube_istio_discovery_body + { + "kind" => "APIResourceList", + "apiVersion" => "v1", + "groupVersion" => "networking.istio.io/v1alpha3", + "resources" => [ + { + "name" => "gateways", + "singularName" => "gateway", + "namespaced" => true, + "kind" => "Gateway", + "verbs" => %w[delete deletecollection get list patch create update watch], + "shortNames" => %w[gw], + "categories" => %w[istio-io networking-istio-io] + }, + { + "name" => "serviceentries", + "singularName" => "serviceentry", + "namespaced" => true, + "kind" => "ServiceEntry", + "verbs" => %w[delete deletecollection get list patch create update watch], + "shortNames" => %w[se], + "categories" => %w[istio-io networking-istio-io] + }, + { + "name" => "destinationrules", + "singularName" => "destinationrule", + "namespaced" => true, + "kind" => "DestinationRule", + "verbs" => %w[delete deletecollection get list patch create update watch], + "shortNames" => %w[dr], + "categories" => %w[istio-io networking-istio-io] + }, + { + "name" => "envoyfilters", + "singularName" => "envoyfilter", + "namespaced" => true, + "kind" => "EnvoyFilter", + "verbs" => %w[delete deletecollection get list patch create update watch], + "categories" => %w[istio-io networking-istio-io] + }, + { + "name" => "sidecars", + "singularName" => "sidecar", + "namespaced" => true, + "kind" => "Sidecar", + "verbs" => %w[delete deletecollection get list patch create update watch], + "categories" => %w[istio-io networking-istio-io] + }, + { + "name" => "virtualservices", + "singularName" => "virtualservice", + "namespaced" => true, + "kind" => "VirtualService", + "verbs" => %w[delete deletecollection get list patch create update watch], + "shortNames" => %w[vs], + "categories" => %w[istio-io networking-istio-io] + } + ] + } + end + + def kube_istio_gateway_body(name, namespace) + { + "apiVersion" => "networking.istio.io/v1alpha3", + "kind" => "Gateway", + "metadata" => { + "generation" => 1, + "labels" => { + "networking.knative.dev/ingress-provider" => "istio", + "serving.knative.dev/release" => "v0.7.0" + }, + "name" => name, + "namespace" => namespace, + "selfLink" => "/apis/networking.istio.io/v1alpha3/namespaces/#{namespace}/gateways/#{name}" + }, + "spec" => { + "selector" => { + "istio" => "ingressgateway" + }, + "servers" => [ + { + "hosts" => [ + "*" + ], + "port" => { + "name" => "http", + "number" => 80, + "protocol" => "HTTP" + } + }, + { + "hosts" => [ + "*" + ], + "port" => { + "name" => "https", + "number" => 443, + "protocol" => "HTTPS" + }, + "tls" => { + "mode" => "PASSTHROUGH" + } + } + ] + } + } + end + def kube_v1alpha1_serving_knative_discovery_body { "kind" => "APIResourceList", |