Skip to content

Commit

Permalink
Fix single chart path for linting builders releases
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Sep 29, 2023
1 parent 0b3fd43 commit 9a1051c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
6 changes: 3 additions & 3 deletions pkg/handlers/builders_lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func LintBuildersRelease(c *gin.Context) {
Type: "error",
Message: err.Error(),
})
} else {
numChartsRendered += 1
specFiles = append(specFiles, files...)
}

numChartsRendered += 1
specFiles = append(specFiles, files...)
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "content type must be application/gzip or application/tar"})
return
Expand Down
55 changes: 33 additions & 22 deletions pkg/handlers/builders_lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,17 @@ func Test_LintBuildersRelease(t *testing.T) {
}

tests := []struct {
name string
chartReader func() io.Reader
isValidChart bool
want resultType
skip bool
name string
chartReader func() io.ReadCloser
contentType string
want resultType
}{
{
skip: false,
name: "one valid chart without preflights",
chartReader: func() io.Reader {
return getTarReader([]string{"testchart-with-labels-16.2.2.tgz"})
chartReader: func() io.ReadCloser {
return io.NopCloser(getTarReader([]string{"testchart-with-labels-16.2.2.tgz"}))
},
isValidChart: true,
contentType: "application/tar",
want: resultType{
LintExpressions: []kots.LintExpression{
{
Expand All @@ -84,12 +82,11 @@ func Test_LintBuildersRelease(t *testing.T) {
},
},
{
skip: false,
name: "one valid chart without preflights and one invalid chart",
chartReader: func() io.Reader {
return getTarReader([]string{"testchart-with-labels-16.2.2.tgz", "not-a-chart.tgz"})
chartReader: func() io.ReadCloser {
return io.NopCloser(getTarReader([]string{"testchart-with-labels-16.2.2.tgz", "not-a-chart.tgz"}))
},
isValidChart: true,
contentType: "application/tar",
want: resultType{
LintExpressions: []kots.LintExpression{
{
Expand All @@ -110,12 +107,11 @@ func Test_LintBuildersRelease(t *testing.T) {
},
},
{
skip: false,
name: "one invalid chart",
chartReader: func() io.Reader {
return getTarReader([]string{"not-a-chart.tgz"})
chartReader: func() io.ReadCloser {
return io.NopCloser(getTarReader([]string{"not-a-chart.tgz"}))
},
isValidChart: true,
contentType: "application/tar",
want: resultType{
LintExpressions: []kots.LintExpression{
{
Expand All @@ -128,19 +124,34 @@ func Test_LintBuildersRelease(t *testing.T) {
},
},
},
{
name: "one invalid chart",
chartReader: func() io.ReadCloser {
r, _ := testdata.Open("test-data/builders/not-a-chart.tgz")
return r
},
contentType: "application/gzip",
want: resultType{
LintExpressions: []kots.LintExpression{
{
Rule: "rendering",
Type: "error",
Message: "load chart archive: EOF",
Positions: nil,
},
},
},
},
}

for _, tt := range tests {
if tt.skip {
continue
}
t.Run(tt.name, func(t *testing.T) {
req := require.New(t)

clientRequest := &http.Request{
Body: io.NopCloser(tt.chartReader()),
Body: tt.chartReader(),
Header: http.Header{
"Content-Type": []string{"application/tar"},
"Content-Type": []string{tt.contentType},
},
}
respWriter := httptest.NewRecorder()
Expand Down

0 comments on commit 9a1051c

Please sign in to comment.