2018-10-16 20:03:59 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FactoryBot.define do
|
2020-01-09 18:07:52 +00:00
|
|
|
factory :cluster_kubernetes_namespace, class: 'Clusters::KubernetesNamespace' do
|
2018-11-02 15:46:15 +00:00
|
|
|
association :cluster, :project, :provided_by_gcp
|
|
|
|
|
|
|
|
after(:build) do |kubernetes_namespace|
|
2019-08-07 04:40:29 +00:00
|
|
|
cluster = kubernetes_namespace.cluster
|
|
|
|
|
|
|
|
if cluster.project_type?
|
|
|
|
cluster_project = cluster.cluster_project
|
2018-11-02 15:46:15 +00:00
|
|
|
|
2018-11-27 04:30:09 +00:00
|
|
|
kubernetes_namespace.project = cluster_project.project
|
|
|
|
kubernetes_namespace.cluster_project = cluster_project
|
|
|
|
end
|
2019-08-07 04:40:29 +00:00
|
|
|
|
|
|
|
kubernetes_namespace.namespace ||=
|
|
|
|
Gitlab::Kubernetes::DefaultNamespace.new(
|
|
|
|
cluster,
|
|
|
|
project: kubernetes_namespace.project
|
|
|
|
).from_environment_slug(kubernetes_namespace.environment&.slug)
|
|
|
|
kubernetes_namespace.service_account_name ||= "#{kubernetes_namespace.namespace}-service-account"
|
2018-11-02 15:46:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_token do
|
2018-11-13 10:27:21 +00:00
|
|
|
service_account_token { FFaker::Lorem.characters(10) }
|
2018-11-02 15:46:15 +00:00
|
|
|
end
|
2019-06-14 05:57:48 +00:00
|
|
|
|
|
|
|
trait :without_token do
|
2019-10-02 00:06:26 +00:00
|
|
|
service_account_token { nil }
|
2019-06-14 05:57:48 +00:00
|
|
|
end
|
2018-10-16 20:03:59 +00:00
|
|
|
end
|
|
|
|
end
|