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:
Diffstat (limited to 'spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb')
-rw-r--r--spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb b/spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb
index 057c4373329..7d1f1aea291 100644
--- a/spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb
+++ b/spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb
@@ -39,6 +39,51 @@ RSpec.describe Gitlab::Kubernetes::Kubeconfig::Template do
it { is_expected.to eq(YAML.dump(template.to_h.deep_stringify_keys)) }
end
+ describe '#merge_yaml' do
+ it 'appends to the configuration and overwrites the current context' do
+ template.add_cluster(name: 'hello-cluster', url: 'hello-url')
+ template.add_context(name: 'hello-context', cluster: 'hello-cluster', user: 'hello-user')
+ template.add_user(name: 'hello-user', token: 'hello-token')
+ ca_pem = Base64.strict_encode64('a certificate')
+ template.merge_yaml(<<~YAML)
+ apiVersion: v1
+ kind: Config
+ clusters:
+ - name: 'gitlab-deploy'
+ cluster:
+ server: url
+ certificate-authority-data: #{ca_pem.inspect}
+ contexts:
+ - name: gitlab-deploy
+ context:
+ cluster: gitlab-deploy
+ namespace: namespace
+ user: gitlab-deploy
+ current-context: gitlab-deploy
+ users:
+ - name: 'gitlab-deploy'
+ user: { token: token }
+ YAML
+ expect(template.to_h).to eq({
+ apiVersion: 'v1',
+ kind: 'Config',
+ clusters: [
+ { name: 'hello-cluster', cluster: { server: 'hello-url' } },
+ { name: 'gitlab-deploy', cluster: { server: 'url', 'certificate-authority-data': ca_pem } }
+ ],
+ contexts: [
+ { name: 'hello-context', context: { cluster: 'hello-cluster', user: 'hello-user' } },
+ { name: 'gitlab-deploy', context: { cluster: 'gitlab-deploy', namespace: 'namespace', user: 'gitlab-deploy' } }
+ ],
+ users: [
+ { name: 'hello-user', user: { token: 'hello-token' } },
+ { name: 'gitlab-deploy', user: { token: 'token' } }
+ ],
+ 'current-context': 'gitlab-deploy'
+ })
+ end
+ end
+
describe 'adding entries' do
let(:entry) { instance_double(entry_class, to_h: attributes) }
let(:attributes) do