debian-mirror-gitlab/spec/lib/gitlab/kubernetes/helm/base_command_spec.rb

117 lines
2.5 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
require 'spec_helper'
describe Gitlab::Kubernetes::Helm::BaseCommand do
let(:application) { create(:clusters_applications_helm) }
2018-11-20 20:47:30 +05:30
let(:rbac) { false }
2018-11-18 11:00:15 +05:30
let(:test_class) do
Class.new do
include Gitlab::Kubernetes::Helm::BaseCommand
2018-11-20 20:47:30 +05:30
def initialize(rbac)
@rbac = rbac
end
2018-11-18 11:00:15 +05:30
def name
"test-class-name"
end
2018-11-20 20:47:30 +05:30
def rbac?
@rbac
end
2018-11-18 11:00:15 +05:30
def files
{
some: 'value'
}
end
end
end
let(:base_command) do
2018-11-20 20:47:30 +05:30
test_class.new(rbac)
2018-11-18 11:00:15 +05:30
end
2018-03-27 19:54:05 +05:30
2018-10-15 14:42:47 +05:30
subject { base_command }
2018-03-27 19:54:05 +05:30
2018-10-15 14:42:47 +05:30
it_behaves_like 'helm commands' do
let(:commands) { '' }
2018-03-27 19:54:05 +05:30
end
describe '#pod_resource' do
subject { base_command.pod_resource }
2019-07-07 11:18:12 +05:30
it 'returns a kubeclient resoure with pod content for application' do
2018-03-27 19:54:05 +05:30
is_expected.to be_an_instance_of ::Kubeclient::Resource
end
2018-11-20 20:47:30 +05:30
context 'when rbac is true' do
let(:rbac) { true }
it 'also returns a kubeclient resource' do
is_expected.to be_an_instance_of ::Kubeclient::Resource
end
end
2018-03-27 19:54:05 +05:30
end
describe '#pod_name' do
subject { base_command.pod_name }
2018-11-18 11:00:15 +05:30
it { is_expected.to eq('install-test-class-name') }
2018-03-27 19:54:05 +05:30
end
2020-04-22 19:07:51 +05:30
describe '#service_account_resource' do
let(:resource) do
Kubeclient::Resource.new(metadata: { name: 'tiller', namespace: 'gitlab-managed-apps' })
end
subject { base_command.service_account_resource }
context 'rbac is enabled' do
let(:rbac) { true }
it 'generates a Kubeclient resource for the tiller ServiceAccount' do
is_expected.to eq(resource)
end
end
context 'rbac is not enabled' do
let(:rbac) { false }
it 'generates nothing' do
is_expected.to be_nil
end
end
end
describe '#cluster_role_binding_resource' do
let(:resource) do
Kubeclient::Resource.new(
metadata: { name: 'tiller-admin' },
roleRef: { apiGroup: 'rbac.authorization.k8s.io', kind: 'ClusterRole', name: 'cluster-admin' },
subjects: [{ kind: 'ServiceAccount', name: 'tiller', namespace: 'gitlab-managed-apps' }]
)
end
subject { base_command.cluster_role_binding_resource }
context 'rbac is enabled' do
let(:rbac) { true }
it 'generates a Kubeclient resource for the ClusterRoleBinding for tiller' do
is_expected.to eq(resource)
end
end
context 'rbac is not enabled' do
let(:rbac) { false }
it 'generates nothing' do
is_expected.to be_nil
end
end
end
2018-03-27 19:54:05 +05:30
end