debian-mirror-gitlab/spec/factories/clusters/kubernetes_namespaces.rb

34 lines
1,016 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
FactoryBot.define do
factory :cluster_kubernetes_namespace, class: Clusters::KubernetesNamespace do
association :cluster, :project, :provided_by_gcp
after(:build) do |kubernetes_namespace|
2019-10-12 21:52:04 +05:30
cluster = kubernetes_namespace.cluster
if cluster.project_type?
cluster_project = cluster.cluster_project
2018-12-13 13:39:08 +05:30
2019-02-15 15:39:39 +05:30
kubernetes_namespace.project = cluster_project.project
kubernetes_namespace.cluster_project = cluster_project
end
2019-10-12 21:52:04 +05:30
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-12-13 13:39:08 +05:30
end
trait :with_token do
service_account_token { FFaker::Lorem.characters(10) }
end
2019-09-04 21:01:54 +05:30
trait :without_token do
2019-12-21 20:55:43 +05:30
service_account_token { nil }
2019-09-04 21:01:54 +05:30
end
2018-12-13 13:39:08 +05:30
end
end