(t *testing.T)
| 77 | } |
| 78 | |
| 79 | func TestLoadArchive(t *testing.T) { |
| 80 | testCases := []struct { |
| 81 | name string |
| 82 | chartName string |
| 83 | apiVersion string |
| 84 | extraFiles map[string][]byte |
| 85 | inputReader io.Reader |
| 86 | expectedChart chart.Charter |
| 87 | expectedError string |
| 88 | createChartYaml bool |
| 89 | }{ |
| 90 | { |
| 91 | name: "valid v2 chart archive", |
| 92 | chartName: "mychart-v2", |
| 93 | apiVersion: c2.APIVersionV2, |
| 94 | extraFiles: map[string][]byte{"templates/config.yaml": []byte("key: value")}, |
| 95 | expectedChart: &c2.Chart{ |
| 96 | Metadata: &c2.Metadata{APIVersion: c2.APIVersionV2, Name: "mychart-v2", Version: "0.1.0", Description: "A test chart"}, |
| 97 | }, |
| 98 | createChartYaml: true, |
| 99 | }, |
| 100 | { |
| 101 | name: "valid v3 chart archive", |
| 102 | chartName: "mychart-v3", |
| 103 | apiVersion: c3.APIVersionV3, |
| 104 | extraFiles: map[string][]byte{"templates/config.yaml": []byte("key: value")}, |
| 105 | expectedChart: &c3.Chart{ |
| 106 | Metadata: &c3.Metadata{APIVersion: c3.APIVersionV3, Name: "mychart-v3", Version: "0.1.0", Description: "A test chart"}, |
| 107 | }, |
| 108 | createChartYaml: true, |
| 109 | }, |
| 110 | { |
| 111 | name: "invalid gzip header", |
| 112 | inputReader: bytes.NewBufferString("not a gzip file"), |
| 113 | expectedError: "stream does not appear to be a valid chart file (details: gzip: invalid header)", |
| 114 | }, |
| 115 | { |
| 116 | name: "archive without Chart.yaml", |
| 117 | chartName: "no-chart-yaml", |
| 118 | apiVersion: c2.APIVersionV2, // This will be ignored as Chart.yaml is missing |
| 119 | extraFiles: map[string][]byte{"values.yaml": []byte("foo: bar")}, |
| 120 | expectedError: "unable to detect chart version, no Chart.yaml found", |
| 121 | createChartYaml: false, |
| 122 | }, |
| 123 | { |
| 124 | name: "archive with malformed Chart.yaml", |
| 125 | chartName: "malformed-chart-yaml", |
| 126 | apiVersion: c2.APIVersionV2, |
| 127 | extraFiles: map[string][]byte{"Chart.yaml": []byte("apiVersion: v2\nname: mychart\nversion: 0.1.0\ndescription: A test chart\ninvalid: :")}, |
| 128 | expectedError: "cannot load Chart.yaml: error converting YAML to JSON: yaml: line 5: mapping values are not allowed in this context", |
| 129 | createChartYaml: false, |
| 130 | }, |
| 131 | { |
| 132 | name: "unsupported API version", |
| 133 | chartName: "unsupported-api", |
| 134 | apiVersion: "v99", |
| 135 | expectedError: "unsupported chart version", |
| 136 | createChartYaml: true, |
nothing calls this directly
no test coverage detected
searching dependent graphs…