| 251 | } |
| 252 | |
| 253 | func TestChartfile(t *testing.T) { |
| 254 | t.Run("Chart.yaml basic validity issues", func(t *testing.T) { |
| 255 | linter := support.Linter{ChartDir: badChartDir} |
| 256 | Chartfile(&linter) |
| 257 | msgs := linter.Messages |
| 258 | expectedNumberOfErrorMessages := 7 |
| 259 | |
| 260 | if len(msgs) != expectedNumberOfErrorMessages { |
| 261 | t.Errorf("Expected %d errors, got %d", expectedNumberOfErrorMessages, len(msgs)) |
| 262 | return |
| 263 | } |
| 264 | |
| 265 | if !strings.Contains(msgs[0].Err.Error(), "name is required") { |
| 266 | t.Errorf("Unexpected message 0: %s", msgs[0].Err) |
| 267 | } |
| 268 | |
| 269 | if !strings.Contains(msgs[1].Err.Error(), "apiVersion is required. The value must be either \"v1\" or \"v2\"") { |
| 270 | t.Errorf("Unexpected message 1: %s", msgs[1].Err) |
| 271 | } |
| 272 | |
| 273 | if !strings.Contains(msgs[2].Err.Error(), "version '0.0.0.0' is not a valid SemVer") { |
| 274 | t.Errorf("Unexpected message 2: %s", msgs[2].Err) |
| 275 | } |
| 276 | |
| 277 | if !strings.Contains(msgs[3].Err.Error(), "icon is recommended") { |
| 278 | t.Errorf("Unexpected message 3: %s", msgs[3].Err) |
| 279 | } |
| 280 | |
| 281 | if !strings.Contains(msgs[4].Err.Error(), "chart type is not valid in apiVersion") { |
| 282 | t.Errorf("Unexpected message 4: %s", msgs[4].Err) |
| 283 | } |
| 284 | |
| 285 | if !strings.Contains(msgs[5].Err.Error(), "dependencies are not valid in the Chart file with apiVersion") { |
| 286 | t.Errorf("Unexpected message 5: %s", msgs[5].Err) |
| 287 | } |
| 288 | if !strings.Contains(msgs[6].Err.Error(), "version '0.0.0.0' is not a valid SemVerV2") { |
| 289 | t.Errorf("Unexpected message 6: %s", msgs[6].Err) |
| 290 | } |
| 291 | }) |
| 292 | |
| 293 | t.Run("Chart.yaml validity issues due to type mismatch", func(t *testing.T) { |
| 294 | linter := support.Linter{ChartDir: anotherBadChartDir} |
| 295 | Chartfile(&linter) |
| 296 | msgs := linter.Messages |
| 297 | expectedNumberOfErrorMessages := 4 |
| 298 | |
| 299 | if len(msgs) != expectedNumberOfErrorMessages { |
| 300 | t.Errorf("Expected %d errors, got %d", expectedNumberOfErrorMessages, len(msgs)) |
| 301 | return |
| 302 | } |
| 303 | |
| 304 | if !strings.Contains(msgs[0].Err.Error(), "version should be of type string") { |
| 305 | t.Errorf("Unexpected message 0: %s", msgs[0].Err) |
| 306 | } |
| 307 | |
| 308 | if !strings.Contains(msgs[1].Err.Error(), "version '7.2445e+06' is not a valid SemVer") { |
| 309 | t.Errorf("Unexpected message 1: %s", msgs[1].Err) |
| 310 | } |