|
1 | 1 | package integration
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "os" |
4 | 5 | "os/exec"
|
5 | 6 | "strings"
|
6 | 7 | "testing"
|
7 | 8 | )
|
8 | 9 |
|
9 | 10 | func TestEnvsubstIntegration_NoSubst_GlobPatterns_Yaml(t *testing.T) {
|
10 | 11 |
|
11 |
| - // if os.Getenv(integrationTestEnv) != integrationTestFlag { |
12 |
| - // t.Log("integration test was skipped due to configuration") |
13 |
| - // return |
14 |
| - // } |
| 12 | + if os.Getenv(integrationTestEnv) != integrationTestFlag { |
| 13 | + t.Log("integration test was skipped due to configuration") |
| 14 | + return |
| 15 | + } |
15 | 16 |
|
16 | 17 | printEnvsubstVersionInfo(t)
|
17 | 18 |
|
@@ -50,8 +51,58 @@ func TestEnvsubstIntegration_NoSubst_GlobPatterns_Yaml(t *testing.T) {
|
50 | 51 | for _, er := range unExpectResources {
|
51 | 52 | unExpectedOutput := strings.Contains(stringOutput, er)
|
52 | 53 | if unExpectedOutput {
|
| 54 | + t.Errorf("Expected substituted output does not contain '%s'", er) |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | +} |
| 59 | + |
| 60 | +func TestEnvsubstIntegration_NoSubst_GlobPatterns_Json(t *testing.T) { |
| 61 | + |
| 62 | + if os.Getenv(integrationTestEnv) != integrationTestFlag { |
| 63 | + t.Log("integration test was skipped due to configuration") |
| 64 | + return |
| 65 | + } |
| 66 | + |
| 67 | + printEnvsubstVersionInfo(t) |
| 68 | + |
| 69 | + namespaceName := "kubectl-envsubst-plain-glob" |
| 70 | + createNs(t, namespaceName) |
| 71 | + |
| 72 | + // Setup context |
| 73 | + setContextNs(t, namespaceName) |
| 74 | + |
| 75 | + // Run kubectl-envsubst |
| 76 | + |
| 77 | + cmdEnvsubstApply := exec.Command("kubectl", "envsubst", "apply", "-f", "immutable_data/resolve/plain-glob/*.json") |
| 78 | + output, err := cmdEnvsubstApply.CombinedOutput() |
| 79 | + stringOutput := string(output) |
| 80 | + if err != nil { |
| 81 | + t.Fatalf("Failed to run kubectl envsubst: %v, output: %s", err, stringOutput) |
| 82 | + } |
| 83 | + t.Logf("\n%s\n", strings.TrimSpace(stringOutput)) |
| 84 | + |
| 85 | + expectResources := []string{ |
| 86 | + "cm-3-level-0", // *.json |
| 87 | + } |
| 88 | + |
| 89 | + unExpectResources := []string{ |
| 90 | + "cm-1-level-0", // *.yaml |
| 91 | + "cm-2-level-0", // *.yaml |
| 92 | + } |
| 93 | + |
| 94 | + for _, er := range expectResources { |
| 95 | + expectedOutput := strings.Contains(stringOutput, er) |
| 96 | + if !expectedOutput { |
53 | 97 | t.Errorf("Expected substituted output to contain '%s', got %s", er, stringOutput)
|
54 | 98 | }
|
55 | 99 | }
|
56 | 100 |
|
| 101 | + for _, er := range unExpectResources { |
| 102 | + unExpectedOutput := strings.Contains(stringOutput, er) |
| 103 | + if unExpectedOutput { |
| 104 | + t.Errorf("Expected substituted output does not contain '%s'", er) |
| 105 | + } |
| 106 | + } |
| 107 | + |
57 | 108 | }
|
0 commit comments