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>2021-08-19 12:08:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/kubernetes
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/kubernetes')
-rw-r--r--spec/lib/gitlab/kubernetes/default_namespace_spec.rb30
-rw-r--r--spec/lib/gitlab/kubernetes/kubeconfig/entry/cluster_spec.rb23
-rw-r--r--spec/lib/gitlab/kubernetes/kubeconfig/entry/context_spec.rb23
-rw-r--r--spec/lib/gitlab/kubernetes/kubeconfig/entry/user_spec.rb14
-rw-r--r--spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb84
5 files changed, 160 insertions, 14 deletions
diff --git a/spec/lib/gitlab/kubernetes/default_namespace_spec.rb b/spec/lib/gitlab/kubernetes/default_namespace_spec.rb
index 976fe4a0a87..b6816a18baa 100644
--- a/spec/lib/gitlab/kubernetes/default_namespace_spec.rb
+++ b/spec/lib/gitlab/kubernetes/default_namespace_spec.rb
@@ -32,6 +32,14 @@ RSpec.describe Gitlab::Kubernetes::DefaultNamespace do
subject { generator.from_environment_slug(environment.slug) }
+ shared_examples_for 'handles very long project paths' do
+ before do
+ allow(project).to receive(:path).and_return 'x' * 100
+ end
+
+ it { is_expected.to satisfy { |s| s.length <= 63 } }
+ end
+
context 'namespace per environment is enabled' do
context 'platform namespace is specified' do
let(:platform_namespace) { 'platform-namespace' }
@@ -47,15 +55,12 @@ RSpec.describe Gitlab::Kubernetes::DefaultNamespace do
context 'platform namespace is blank' do
let(:platform_namespace) { nil }
- let(:mock_namespace) { 'mock-namespace' }
- it 'constructs a namespace from the project and environment' do
- expect(Gitlab::NamespaceSanitizer).to receive(:sanitize)
- .with("#{project.path}-#{project.id}-#{environment.slug}".downcase)
- .and_return(mock_namespace)
-
- expect(subject).to eq mock_namespace
+ it 'constructs a namespace from the project and environment slug' do
+ expect(subject).to eq "path-with-capitals-#{project.id}-#{environment.slug}"
end
+
+ it_behaves_like 'handles very long project paths'
end
end
@@ -70,15 +75,12 @@ RSpec.describe Gitlab::Kubernetes::DefaultNamespace do
context 'platform namespace is blank' do
let(:platform_namespace) { nil }
- let(:mock_namespace) { 'mock-namespace' }
- it 'constructs a namespace from the project and environment' do
- expect(Gitlab::NamespaceSanitizer).to receive(:sanitize)
- .with("#{project.path}-#{project.id}".downcase)
- .and_return(mock_namespace)
-
- expect(subject).to eq mock_namespace
+ it 'constructs a namespace from just the project' do
+ expect(subject).to eq "path-with-capitals-#{project.id}"
end
+
+ it_behaves_like 'handles very long project paths'
end
end
end
diff --git a/spec/lib/gitlab/kubernetes/kubeconfig/entry/cluster_spec.rb b/spec/lib/gitlab/kubernetes/kubeconfig/entry/cluster_spec.rb
new file mode 100644
index 00000000000..508808be1be
--- /dev/null
+++ b/spec/lib/gitlab/kubernetes/kubeconfig/entry/cluster_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Kubernetes::Kubeconfig::Entry::Cluster do
+ describe '#to_h' do
+ let(:name) { 'name' }
+ let(:url) { 'url' }
+
+ subject { described_class.new(name: name, url: url).to_h }
+
+ it { is_expected.to eq({ name: name, cluster: { server: url } }) }
+
+ context 'with a certificate' do
+ let(:cert) { 'certificate' }
+ let(:cert_encoded) { Base64.strict_encode64(cert) }
+
+ subject { described_class.new(name: name, url: url, ca_pem: cert).to_h }
+
+ it { is_expected.to eq({ name: name, cluster: { server: url, 'certificate-authority-data': cert_encoded } }) }
+ end
+ end
+end
diff --git a/spec/lib/gitlab/kubernetes/kubeconfig/entry/context_spec.rb b/spec/lib/gitlab/kubernetes/kubeconfig/entry/context_spec.rb
new file mode 100644
index 00000000000..43d4c46fda1
--- /dev/null
+++ b/spec/lib/gitlab/kubernetes/kubeconfig/entry/context_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Kubernetes::Kubeconfig::Entry::Context do
+ describe '#to_h' do
+ let(:name) { 'name' }
+ let(:user) { 'user' }
+ let(:cluster) { 'cluster' }
+
+ subject { described_class.new(name: name, user: user, cluster: cluster).to_h }
+
+ it { is_expected.to eq({ name: name, context: { cluster: cluster, user: user } }) }
+
+ context 'with a namespace' do
+ let(:namespace) { 'namespace' }
+
+ subject { described_class.new(name: name, user: user, cluster: cluster, namespace: namespace).to_h }
+
+ it { is_expected.to eq({ name: name, context: { cluster: cluster, user: user, namespace: namespace } }) }
+ end
+ end
+end
diff --git a/spec/lib/gitlab/kubernetes/kubeconfig/entry/user_spec.rb b/spec/lib/gitlab/kubernetes/kubeconfig/entry/user_spec.rb
new file mode 100644
index 00000000000..3d6acc80823
--- /dev/null
+++ b/spec/lib/gitlab/kubernetes/kubeconfig/entry/user_spec.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Kubernetes::Kubeconfig::Entry::User do
+ describe '#to_h' do
+ let(:name) { 'name' }
+ let(:token) { 'token' }
+
+ subject { described_class.new(name: name, token: token).to_h }
+
+ it { is_expected.to eq({ name: name, user: { token: token } }) }
+ end
+end
diff --git a/spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb b/spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb
new file mode 100644
index 00000000000..057c4373329
--- /dev/null
+++ b/spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Kubernetes::Kubeconfig::Template do
+ let(:template) { described_class.new }
+
+ describe '#valid?' do
+ subject { template.valid? }
+
+ it { is_expected.to be_falsey }
+
+ context 'with configuration added' do
+ before do
+ template.add_context(name: 'name', cluster: 'cluster', user: 'user')
+ end
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
+ describe '#to_h' do
+ subject { described_class.new.to_h }
+
+ it do
+ is_expected.to eq(
+ apiVersion: 'v1',
+ kind: 'Config',
+ clusters: [],
+ users: [],
+ contexts: []
+ )
+ end
+ end
+
+ describe '#to_yaml' do
+ subject { template.to_yaml }
+
+ it { is_expected.to eq(YAML.dump(template.to_h.deep_stringify_keys)) }
+ end
+
+ describe 'adding entries' do
+ let(:entry) { instance_double(entry_class, to_h: attributes) }
+ let(:attributes) do
+ { name: 'name', other: 'other' }
+ end
+
+ subject { template.to_h }
+
+ before do
+ expect(entry_class).to receive(:new).with(attributes).and_return(entry)
+ end
+
+ describe '#add_cluster' do
+ let(:entry_class) { Gitlab::Kubernetes::Kubeconfig::Entry::Cluster }
+
+ before do
+ template.add_cluster(**attributes)
+ end
+
+ it { is_expected.to include(clusters: [attributes]) }
+ end
+
+ describe '#add_user' do
+ let(:entry_class) { Gitlab::Kubernetes::Kubeconfig::Entry::User }
+
+ before do
+ template.add_user(**attributes)
+ end
+
+ it { is_expected.to include(users: [attributes]) }
+ end
+
+ describe '#add_context' do
+ let(:entry_class) { Gitlab::Kubernetes::Kubeconfig::Entry::Context }
+
+ before do
+ template.add_context(**attributes)
+ end
+
+ it { is_expected.to include(contexts: [attributes]) }
+ end
+ end
+end