|
| 1 | +// +build kube |
| 2 | + |
| 3 | +/* |
| 4 | + Copyright 2020 Docker Compose CLI authors |
| 5 | +
|
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +package kube |
| 20 | + |
| 21 | +import ( |
| 22 | + "testing" |
| 23 | + |
| 24 | + "gotest.tools/v3/assert" |
| 25 | +) |
| 26 | + |
| 27 | +func TestContextDescriptionIfEnvVar(t *testing.T) { |
| 28 | + cp := ContextParams{ |
| 29 | + FromEnvironment: true, |
| 30 | + } |
| 31 | + description := cp.getDescription() |
| 32 | + assert.Equal(t, description, "From environment variables") |
| 33 | +} |
| 34 | + |
| 35 | +func TestContextDescriptionIfProvided(t *testing.T) { |
| 36 | + cp := ContextParams{ |
| 37 | + Description: "custom description", |
| 38 | + FromEnvironment: true, |
| 39 | + } |
| 40 | + description := cp.getDescription() |
| 41 | + assert.Equal(t, description, "custom description") |
| 42 | +} |
| 43 | + |
| 44 | +func TestContextDescriptionIfConfigFile(t *testing.T) { |
| 45 | + cp := ContextParams{ |
| 46 | + ContextName: "my-context", |
| 47 | + KubeconfigPath: "~/.kube/config", |
| 48 | + } |
| 49 | + description := cp.getDescription() |
| 50 | + assert.Equal(t, description, "my-context (in ~/.kube/config)") |
| 51 | +} |
| 52 | +func TestContextDescriptionIfDefaultConfigFile(t *testing.T) { |
| 53 | + cp := ContextParams{ |
| 54 | + ContextName: "my-context", |
| 55 | + } |
| 56 | + description := cp.getDescription() |
| 57 | + assert.Equal(t, description, "my-context (in default kube config)") |
| 58 | +} |
0 commit comments