summaryrefslogtreecommitdiff
path: root/spec/models/environment_spec.rb
diff options
context:
space:
mode:
authorTiger <twatson@gitlab.com>2019-05-22 13:55:15 -0500
committerTiger <twatson@gitlab.com>2019-06-25 09:22:20 +1000
commit90c27ea52ada6bc3f3a18bcf61f9c034c8cb65ba (patch)
tree5f83528e99902b59ab9f95b2aaa2b2573a962078 /spec/models/environment_spec.rb
parentdb9783f7826ed5ba58a8941dd80a1cd7dda517b0 (diff)
downloadgitlab-ce-90c27ea52ada6bc3f3a18bcf61f9c034c8cb65ba.tar.gz
Move terminal construction logic to Environment61156-instance-level-cluster-pod-terminal-access
This enables terminals for group and project level clusters. Previously there was no way to determine which project (and therefore kubernetes namespace) to connect to, moving this logic onto Environment means the assoicated project can be used to look up the correct namespace.
Diffstat (limited to 'spec/models/environment_spec.rb')
-rw-r--r--spec/models/environment_spec.rb63
1 files changed, 50 insertions, 13 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 379dda1f5c4..fe4d64818b4 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -2,10 +2,14 @@
require 'spec_helper'
-describe Environment do
+describe Environment, :use_clean_rails_memory_store_caching do
+ include ReactiveCachingHelpers
+
let(:project) { create(:project, :stubbed_repository) }
subject(:environment) { create(:environment, project: project) }
+ it { is_expected.to be_kind_of(ReactiveCaching) }
+
it { is_expected.to belong_to(:project).required }
it { is_expected.to have_many(:deployments) }
@@ -573,32 +577,65 @@ describe Environment do
describe '#terminals' do
subject { environment.terminals }
- context 'when the environment has terminals' do
+ before do
+ allow(environment).to receive(:deployment_platform).and_return(double)
+ end
+
+ context 'reactive cache is empty' do
before do
- allow(environment).to receive(:has_terminals?).and_return(true)
+ stub_reactive_cache(environment, nil)
end
- context 'when user configured kubernetes from CI/CD > Clusters' do
- let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
- let(:project) { cluster.project }
+ it { is_expected.to be_nil }
+ end
+
+ context 'reactive cache has pod data' do
+ let(:cache_data) { Hash(pods: %w(pod1 pod2)) }
+
+ before do
+ stub_reactive_cache(environment, cache_data)
+ end
- it 'returns the terminals from the deployment service' do
- expect(environment.deployment_platform)
- .to receive(:terminals).with(environment)
- .and_return(:fake_terminals)
+ it 'retrieves terminals from the deployment platform' do
+ expect(environment.deployment_platform)
+ .to receive(:terminals).with(environment, cache_data)
+ .and_return(:fake_terminals)
- is_expected.to eq(:fake_terminals)
- end
+ is_expected.to eq(:fake_terminals)
end
end
+ end
+
+ describe '#calculate_reactive_cache' do
+ let(:cluster) { create(:cluster, :project, :provided_by_user) }
+ let(:project) { cluster.project }
+ let(:environment) { create(:environment, project: project) }
+ let!(:deployment) { create(:deployment, :success, environment: environment) }
+
+ subject { environment.calculate_reactive_cache }
+
+ it 'returns cache data from the deployment platform' do
+ expect(environment.deployment_platform).to receive(:calculate_reactive_cache_for)
+ .with(environment).and_return(pods: %w(pod1 pod2))
+
+ is_expected.to eq(pods: %w(pod1 pod2))
+ end
- context 'when the environment does not have terminals' do
+ context 'environment does not have terminals available' do
before do
allow(environment).to receive(:has_terminals?).and_return(false)
end
it { is_expected.to be_nil }
end
+
+ context 'project is pending deletion' do
+ before do
+ allow(environment.project).to receive(:pending_delete?).and_return(true)
+ end
+
+ it { is_expected.to be_nil }
+ end
end
describe '#has_metrics?' do