2018-10-22 17:47:54 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Kubernetes::RoleBinding, '#generate' do
|
|
|
|
let(:role_name) { 'edit' }
|
|
|
|
let(:namespace) { 'my-namespace' }
|
|
|
|
let(:service_account_name) { 'my-service-account' }
|
|
|
|
|
|
|
|
let(:subjects) do
|
|
|
|
[
|
|
|
|
{
|
|
|
|
kind: 'ServiceAccount',
|
|
|
|
name: service_account_name,
|
|
|
|
namespace: namespace
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:role_ref) do
|
|
|
|
{
|
|
|
|
apiGroup: 'rbac.authorization.k8s.io',
|
2018-11-02 11:46:15 -04:00
|
|
|
kind: 'ClusterRole',
|
2018-10-22 17:47:54 -04:00
|
|
|
name: role_name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:resource) do
|
|
|
|
::Kubeclient::Resource.new(
|
|
|
|
metadata: { name: "gitlab-#{namespace}", namespace: namespace },
|
|
|
|
roleRef: role_ref,
|
|
|
|
subjects: subjects
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
described_class.new(
|
2018-11-02 11:46:15 -04:00
|
|
|
name: "gitlab-#{namespace}",
|
2018-10-22 17:47:54 -04:00
|
|
|
role_name: role_name,
|
|
|
|
namespace: namespace,
|
|
|
|
service_account_name: service_account_name
|
|
|
|
).generate
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should build a Kubeclient Resource' do
|
|
|
|
is_expected.to eq(resource)
|
|
|
|
end
|
|
|
|
end
|