diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2017-10-26 17:38:10 +0300 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2017-10-26 19:18:11 +0300 |
commit | 3aafcc16fbdde08bf333eab97c5b1b3c4249a5cf (patch) | |
tree | 31ba13811ff498a1508d33754d6035e12e2d09be /spec | |
parent | 6798bab12a0faabf43f61eb65561b9f058824e4d (diff) |
Add KubernetesService#default_namespace tests
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/project_services/kubernetes_service_spec.rb | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/spec/models/project_services/kubernetes_service_spec.rb b/spec/models/project_services/kubernetes_service_spec.rb index 69da4375245..fa478a22cf4 100644 --- a/spec/models/project_services/kubernetes_service_spec.rb +++ b/spec/models/project_services/kubernetes_service_spec.rb @@ -99,8 +99,25 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do describe '#actual_namespace' do subject { service.actual_namespace } - it "returns the default namespace" do - is_expected.to eq(service.send(:default_namespace)) + shared_examples 'a correctly formatted namespace' do + it 'returns a valid Kubernetes namespace name' do + expect(subject).to match(Gitlab::Regex.kubernetes_namespace_regex) + expect(subject).to eq(expected_namespace) + end + end + + it_behaves_like 'a correctly formatted namespace' do + let(:expected_namespace) { service.send(:default_namespace) } + end + + context 'when the project path contains forbidden characters' do + before do + project.path = '-a_Strange.Path--forSure' + end + + it_behaves_like 'a correctly formatted namespace' do + let(:expected_namespace) { "a-strange-path--forsure-#{project.id}" } + end end context 'when namespace is specified' do @@ -108,8 +125,8 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do service.namespace = 'my-namespace' end - it "returns the user-namespace" do - is_expected.to eq('my-namespace') + it_behaves_like 'a correctly formatted namespace' do + let(:expected_namespace) { 'my-namespace' } end end @@ -118,7 +135,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do service.project = nil end - it "does not return namespace" do + it 'does not return namespace' do is_expected.to be_nil end end |