|
| 1 | +/* |
| 2 | +Copyright 2024. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | +package support |
| 17 | + |
| 18 | +import ( |
| 19 | + "os" |
| 20 | + "testing" |
| 21 | + |
| 22 | + . "github.com/onsi/gomega" |
| 23 | +) |
| 24 | + |
| 25 | +func TestCreateOrGetTestNamespaceCreatingNamespace(t *testing.T) { |
| 26 | + test := NewTest(t) |
| 27 | + |
| 28 | + namespace := test.CreateOrGetTestNamespace() |
| 29 | + |
| 30 | + test.Expect(namespace).NotTo(BeNil()) |
| 31 | + test.Expect(namespace.GenerateName).To(Equal("test-ns-")) |
| 32 | +} |
| 33 | + |
| 34 | +func TestCreateOrGetTestNamespaceGettingExistingNamespace(t *testing.T) { |
| 35 | + test := NewTest(t) |
| 36 | + |
| 37 | + CreateTestNamespaceWithName(test, "test-namespace") |
| 38 | + os.Setenv(testNamespaceNameEnvVar, "test-namespace") |
| 39 | + defer os.Unsetenv(testNamespaceNameEnvVar) |
| 40 | + |
| 41 | + namespace := test.CreateOrGetTestNamespace() |
| 42 | + |
| 43 | + test.Expect(namespace).NotTo(BeNil()) |
| 44 | + test.Expect(namespace.Name).To(Equal("test-namespace")) |
| 45 | +} |
| 46 | + |
| 47 | +func TestCreateOrGetTestNamespaceGettingNonExistingNamespace(t *testing.T) { |
| 48 | + test := NewTest(t) |
| 49 | + |
| 50 | + os.Setenv(testNamespaceNameEnvVar, "non-existing-namespace") |
| 51 | + defer os.Unsetenv(testNamespaceNameEnvVar) |
| 52 | + |
| 53 | + namespace := test.CreateOrGetTestNamespace() |
| 54 | + |
| 55 | + test.Expect(namespace).NotTo(BeNil()) |
| 56 | + test.Expect(namespace.Name).To(Equal("non-existing-namespace")) |
| 57 | +} |
0 commit comments