Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-27 18:09:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-27 18:09:24 +0300
commitf8d15ca65390475e356b06dedc51e10ccd179f86 (patch)
treeef916d4e8e11c9e00d809e5cdcf63814e86d6e89 /spec/services
parent3ab4feda4dce9c9f0672375ae27c2f7c2ba6f4ad (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/clusters/applications/create_service_spec.rb20
-rw-r--r--spec/services/clusters/applications/update_service_spec.rb21
-rw-r--r--spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb32
-rw-r--r--spec/services/serverless/associate_domain_service_spec.rb74
4 files changed, 145 insertions, 2 deletions
diff --git a/spec/services/clusters/applications/create_service_spec.rb b/spec/services/clusters/applications/create_service_spec.rb
index f62af86f1bf..0b48af408e1 100644
--- a/spec/services/clusters/applications/create_service_spec.rb
+++ b/spec/services/clusters/applications/create_service_spec.rb
@@ -137,10 +137,14 @@ describe Clusters::Applications::CreateService do
let(:params) do
{
application: 'knative',
- hostname: 'example.com'
+ hostname: 'example.com',
+ pages_domain_id: domain.id
}
end
+ let(:domain) { create(:pages_domain, :instance_serverless) }
+ let(:associate_domain_service) { double('AssociateDomainService') }
+
before do
expect_any_instance_of(Clusters::Applications::Knative)
.to receive(:make_scheduled!)
@@ -158,6 +162,20 @@ describe Clusters::Applications::CreateService do
it 'sets the hostname' do
expect(subject.hostname).to eq('example.com')
end
+
+ it 'executes AssociateDomainService' do
+ expect(Serverless::AssociateDomainService).to receive(:new) do |knative, args|
+ expect(knative).to be_a(Clusters::Applications::Knative)
+ expect(args[:pages_domain_id]).to eq(params[:pages_domain_id])
+ expect(args[:creator]).to eq(user)
+
+ associate_domain_service
+ end
+
+ expect(associate_domain_service).to receive(:execute)
+
+ subject
+ end
end
context 'elastic stack application' do
diff --git a/spec/services/clusters/applications/update_service_spec.rb b/spec/services/clusters/applications/update_service_spec.rb
index 2d299882af0..4676951faff 100644
--- a/spec/services/clusters/applications/update_service_spec.rb
+++ b/spec/services/clusters/applications/update_service_spec.rb
@@ -7,8 +7,9 @@ describe Clusters::Applications::UpdateService do
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:user) { create(:user) }
- let(:params) { { application: 'knative', hostname: 'udpate.example.com' } }
+ let(:params) { { application: 'knative', hostname: 'update.example.com', pages_domain_id: domain.id } }
let(:service) { described_class.new(cluster, user, params) }
+ let(:domain) { create(:pages_domain, :instance_serverless) }
subject { service.execute(test_request) }
@@ -51,6 +52,24 @@ describe Clusters::Applications::UpdateService do
subject
end
+
+ context 'knative application' do
+ let(:associate_domain_service) { double('AssociateDomainService') }
+
+ it 'executes AssociateDomainService' do
+ expect(Serverless::AssociateDomainService).to receive(:new) do |knative, args|
+ expect(knative.id).to eq(application.id)
+ expect(args[:pages_domain_id]).to eq(params[:pages_domain_id])
+ expect(args[:creator]).to eq(user)
+
+ associate_domain_service
+ end
+
+ expect(associate_domain_service).to receive(:execute)
+
+ subject
+ end
+ end
end
context 'application is not schedulable' do
diff --git a/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb b/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb
index 572e2b91187..9238f7debd0 100644
--- a/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb
+++ b/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb
@@ -194,4 +194,36 @@ describe Clusters::Kubernetes::ConfigureIstioIngressService, '#execute' do
)
end
end
+
+ context 'when there is an error' do
+ before do
+ cluster.application_knative = create(:clusters_applications_knative)
+
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:configure_passthrough).and_raise(error)
+ end
+ end
+
+ context 'Kubeclient::HttpError' do
+ let(:error) { Kubeclient::HttpError.new(404, nil, nil) }
+
+ it 'puts Knative into an errored state' do
+ subject
+
+ expect(cluster.application_knative).to be_errored
+ expect(cluster.application_knative.status_reason).to eq('Kubernetes error: 404')
+ end
+ end
+
+ context 'StandardError' do
+ let(:error) { RuntimeError.new('something went wrong') }
+
+ it 'puts Knative into an errored state' do
+ subject
+
+ expect(cluster.application_knative).to be_errored
+ expect(cluster.application_knative.status_reason).to eq('Failed to update.')
+ end
+ end
+ end
end
diff --git a/spec/services/serverless/associate_domain_service_spec.rb b/spec/services/serverless/associate_domain_service_spec.rb
new file mode 100644
index 00000000000..3d1a878bcf5
--- /dev/null
+++ b/spec/services/serverless/associate_domain_service_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Serverless::AssociateDomainService do
+ subject { described_class.new(knative, pages_domain_id: pages_domain_id, creator: creator) }
+
+ let(:sdc) { create(:serverless_domain_cluster, pages_domain: create(:pages_domain, :instance_serverless)) }
+ let(:knative) { sdc.knative }
+ let(:creator) { sdc.creator }
+ let(:pages_domain_id) { sdc.pages_domain_id }
+
+ context 'when the domain is unchanged' do
+ let(:creator) { create(:user) }
+
+ it 'does not update creator' do
+ expect { subject.execute }.not_to change { sdc.reload.creator }
+ end
+ end
+
+ context 'when domain is changed to nil' do
+ let(:pages_domain_id) { nil }
+ let(:creator) { create(:user) }
+
+ it 'removes the association between knative and the domain' do
+ expect { subject.execute }.to change { knative.reload.pages_domain }.from(sdc.pages_domain).to(nil)
+ end
+
+ it 'does not attempt to update creator' do
+ expect { subject.execute }.not_to raise_error
+ end
+ end
+
+ context 'when a new domain is associated' do
+ let(:pages_domain_id) { create(:pages_domain, :instance_serverless).id }
+ let(:creator) { create(:user) }
+
+ it 'creates an association with the domain' do
+ expect { subject.execute }.to change { knative.pages_domain.id }.from(sdc.pages_domain.id).to(pages_domain_id)
+ end
+
+ it 'updates creator' do
+ expect { subject.execute }.to change { sdc.reload.creator }.from(sdc.creator).to(creator)
+ end
+ end
+
+ context 'when knative is not authorized to use the pages domain' do
+ let(:pages_domain_id) { create(:pages_domain).id }
+
+ before do
+ expect(knative).to receive(:available_domains).and_return(PagesDomain.none)
+ end
+
+ it 'sets pages_domain_id to nil' do
+ expect { subject.execute }.to change { knative.reload.pages_domain }.from(sdc.pages_domain).to(nil)
+ end
+ end
+
+ context 'when knative hostname is nil' do
+ let(:knative) { build(:clusters_applications_knative, hostname: nil) }
+
+ it 'sets hostname to a placeholder value' do
+ expect { subject.execute }.to change { knative.hostname }.to('example.com')
+ end
+ end
+
+ context 'when knative hostname exists' do
+ let(:knative) { build(:clusters_applications_knative, hostname: 'hostname.com') }
+
+ it 'does not change hostname' do
+ expect { subject.execute }.not_to change { knative.hostname }
+ end
+ end
+end