(t *testing.T)
| 27 | ) |
| 28 | |
| 29 | func TestValidateGlobalVariableBasic(t *testing.T) { |
| 30 | |
| 31 | tests := []struct { |
| 32 | name string |
| 33 | testFile string |
| 34 | outputFile string |
| 35 | wantWarning VariableWarning |
| 36 | }{ |
| 37 | { |
| 38 | name: "Successful global variable substitution", |
| 39 | testFile: "test-fixtures/all/devfile-good.yaml", |
| 40 | outputFile: "test-fixtures/all/devfile-good-output.yaml", |
| 41 | wantWarning: VariableWarning{}, |
| 42 | }, |
| 43 | { |
| 44 | name: "Invalid Reference", |
| 45 | testFile: "test-fixtures/all/devfile-bad.yaml", |
| 46 | outputFile: "test-fixtures/all/devfile-bad-output.yaml", |
| 47 | wantWarning: VariableWarning{ |
| 48 | Commands: map[string][]string{ |
| 49 | "command1": {"BAR", "tag"}, |
| 50 | "command2": {"abc"}, |
| 51 | "command3": {"abc"}, |
| 52 | }, |
| 53 | Components: map[string][]string{ |
| 54 | "component1": {"a", "b", "bar", "c"}, |
| 55 | "component2": {"bar", "foo", "x"}, |
| 56 | "component3": {"xyz"}, |
| 57 | "component4": {"foo"}, |
| 58 | "component5": {"foo", "tag"}, |
| 59 | }, |
| 60 | Projects: map[string][]string{ |
| 61 | "project1": {"dir", "path", "tag", "version", "version1"}, |
| 62 | "project2": {"tag"}, |
| 63 | }, |
| 64 | StarterProjects: map[string][]string{ |
| 65 | "starterproject1": {"desc", "dir", "tag"}, |
| 66 | "starterproject2": {"tag"}, |
| 67 | }, |
| 68 | DependentProjects: map[string][]string{ |
| 69 | "project1": {"dir", "path", "tag", "version", "version1"}, |
| 70 | "project2": {"tag"}, |
| 71 | }, |
| 72 | }, |
| 73 | }, |
| 74 | } |
| 75 | for _, tt := range tests { |
| 76 | t.Run(tt.name, func(t *testing.T) { |
| 77 | testDWT := v1alpha2.DevWorkspaceTemplateSpec{} |
| 78 | readFileToStruct(t, tt.testFile, &testDWT) |
| 79 | |
| 80 | warning := ValidateAndReplaceGlobalVariable(&testDWT) |
| 81 | |
| 82 | expectedDWT := v1alpha2.DevWorkspaceTemplateSpec{} |
| 83 | readFileToStruct(t, tt.outputFile, &expectedDWT) |
| 84 | assert.Equal(t, expectedDWT, testDWT, "The two values should be the same.") |
| 85 | |
| 86 | // match the warning |
nothing calls this directly
no test coverage detected