| 28 | } |
| 29 | |
| 30 | func TestConfigValidation(t *testing.T) { |
| 31 | testcases := []struct { |
| 32 | desc string |
| 33 | config validator |
| 34 | valid bool |
| 35 | expectedError string |
| 36 | }{ |
| 37 | { |
| 38 | desc: "gen config with valid yaml value is valid", |
| 39 | config: &GenConfig{ |
| 40 | StaticPlugins: []*manifest.Manifest{ |
| 41 | { |
| 42 | SonobuoyConfig: manifest.SonobuoyConfig{ |
| 43 | PluginName: "test", |
| 44 | }, |
| 45 | ConfigMap: map[string]string{ |
| 46 | "test.yaml": "test: \"valid\"", |
| 47 | }, |
| 48 | }, |
| 49 | }, |
| 50 | }, |
| 51 | valid: true, |
| 52 | }, |
| 53 | { |
| 54 | desc: "gen config with valid yml value is valid", |
| 55 | config: &GenConfig{ |
| 56 | StaticPlugins: []*manifest.Manifest{ |
| 57 | { |
| 58 | SonobuoyConfig: manifest.SonobuoyConfig{ |
| 59 | PluginName: "test", |
| 60 | }, |
| 61 | ConfigMap: map[string]string{ |
| 62 | "test.yml": "test: \"valid\"", |
| 63 | }, |
| 64 | }, |
| 65 | }, |
| 66 | }, |
| 67 | valid: true, |
| 68 | }, |
| 69 | { |
| 70 | desc: "gen config with invalid yaml value is not valid", |
| 71 | config: &GenConfig{ |
| 72 | StaticPlugins: []*manifest.Manifest{ |
| 73 | { |
| 74 | SonobuoyConfig: manifest.SonobuoyConfig{ |
| 75 | PluginName: "test", |
| 76 | }, |
| 77 | ConfigMap: map[string]string{ |
| 78 | "test.yaml": "test: \"in\"valid\"", |
| 79 | }, |
| 80 | }, |
| 81 | }, |
| 82 | }, |
| 83 | valid: false, |
| 84 | expectedError: "failed to parse value of key test.yaml in ConfigMap for plugin test: error converting YAML to JSON: yaml: did not find expected key", |
| 85 | }, |
| 86 | { |
| 87 | desc: "gen config with invalid yml value is not valid", |