|
| 1 | +package v1 |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + corev1 "k8s.io/api/core/v1" |
| 7 | +) |
| 8 | + |
| 9 | +func TestEnvVarExists(t *testing.T) { |
| 10 | + tests := []struct { |
| 11 | + name string |
| 12 | + envName string |
| 13 | + envVars []corev1.EnvVar |
| 14 | + expected bool |
| 15 | + }{ |
| 16 | + { |
| 17 | + name: "env var exists", |
| 18 | + envName: "EXISTING_ENV", |
| 19 | + envVars: []corev1.EnvVar{ |
| 20 | + {Name: "EXISTING_ENV", Value: "value1"}, |
| 21 | + {Name: "ANOTHER_ENV", Value: "value2"}, |
| 22 | + }, |
| 23 | + expected: true, |
| 24 | + }, |
| 25 | + { |
| 26 | + name: "env var does not exist", |
| 27 | + envName: "NON_EXISTING_ENV", |
| 28 | + envVars: []corev1.EnvVar{ |
| 29 | + {Name: "EXISTING_ENV", Value: "value1"}, |
| 30 | + {Name: "ANOTHER_ENV", Value: "value2"}, |
| 31 | + }, |
| 32 | + expected: false, |
| 33 | + }, |
| 34 | + { |
| 35 | + name: "empty env vars", |
| 36 | + envName: "ANY_ENV", |
| 37 | + envVars: []corev1.EnvVar{}, |
| 38 | + expected: false, |
| 39 | + }, |
| 40 | + } |
| 41 | + |
| 42 | + for _, tt := range tests { |
| 43 | + t.Run(tt.name, func(t *testing.T) { |
| 44 | + result := EnvVarExists(tt.envName, tt.envVars) |
| 45 | + if result != tt.expected { |
| 46 | + t.Errorf("EnvVarExists(%s, %v) = %v; expected %v", tt.envName, tt.envVars, result, tt.expected) |
| 47 | + } |
| 48 | + }) |
| 49 | + } |
| 50 | +} |
0 commit comments