Skip to content

Commit

Permalink
Remove chartVersions when listing versions (#1467)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Jan 20, 2020
1 parent 0866d0a commit 4bc36cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 5 additions & 4 deletions cmd/assetsvc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func newChartResponse(c *models.Chart) *apiResponse {
return &apiResponse{
Type: "chart",
ID: c.ID,
Attributes: blankRawIcon(chartAttributes(*c)),
Attributes: blankRawIconAndChartVersions(chartAttributes(*c)),
Links: selfLink{pathPrefix + "/charts/" + c.ID},
Relationships: relMap{
"latestChartVersion": rel{
Expand All @@ -314,11 +314,12 @@ func newChartResponse(c *models.Chart) *apiResponse {
}
}

// blankRawIcon returns the same chart data but with a blank raw icon field.
// blankRawIconAndChartVersions returns the same chart data but with a blank raw icon field and no chartversions.
// TODO(mnelson): The raw icon data should be stored in a separate postgresql column
// rather than the json field so that this isn't necessary.
func blankRawIcon(c models.Chart) models.Chart {
func blankRawIconAndChartVersions(c models.Chart) models.Chart {
c.RawIcon = nil
c.ChartVersions = []models.ChartVersion{}
return c
}

Expand Down Expand Up @@ -354,7 +355,7 @@ func newChartVersionResponse(c *models.Chart, cv models.ChartVersion) *apiRespon
Links: selfLink{pathPrefix + "/charts/" + c.ID + "/versions/" + cv.Version},
Relationships: relMap{
"chart": rel{
Data: blankRawIcon(chartAttributes(*c)),
Data: blankRawIconAndChartVersions(chartAttributes(*c)),
Links: selfLink{pathPrefix + "/charts/" + c.ID},
},
},
Expand Down
3 changes: 1 addition & 2 deletions cmd/assetsvc/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func Test_newChartResponse(t *testing.T) {
assert.Equal(t, cResponse.ID, tt.chart.ID, "chart ID should be the same")
assert.Equal(t, cResponse.Relationships["latestChartVersion"].Data.(models.ChartVersion).Version, tt.chart.ChartVersions[0].Version, "latestChartVersion should match version at index 0")
assert.Equal(t, cResponse.Links.(selfLink).Self, pathPrefix+"/charts/"+tt.chart.ID, "self link should be the same")
assert.Equal(t, len(cResponse.Attributes.(models.Chart).ChartVersions), len(tt.chart.ChartVersions), "number of chart versions in the response should be the same")
// We don't send the raw icon down the wire.
assert.Nil(t, cResponse.Attributes.(models.Chart).RawIcon)
})
Expand Down Expand Up @@ -171,7 +170,6 @@ func Test_newChartListResponse(t *testing.T) {
assert.Equal(t, clResponse[i].ID, tt.result[i].ID, "chart ID should be the same")
assert.Equal(t, clResponse[i].Relationships["latestChartVersion"].Data.(models.ChartVersion).Version, tt.result[i].ChartVersions[0].Version, "latestChartVersion should match version at index 0")
assert.Equal(t, clResponse[i].Links.(selfLink).Self, pathPrefix+"/charts/"+tt.result[i].ID, "self link should be the same")
assert.Equal(t, len(clResponse[i].Attributes.(models.Chart).ChartVersions), len(tt.result[i].ChartVersions), "number of chart versions in the response should be the same")
}
})
}
Expand Down Expand Up @@ -211,6 +209,7 @@ func Test_newChartVersionResponse(t *testing.T) {
expectedChart := tt.chart
expectedChart.RawIcon = nil
expectedChart.Icon = tt.expectedIcon
expectedChart.ChartVersions = []models.ChartVersion{}
assert.Equal(t, cvResponse.Relationships["chart"].Data.(interface{}).(models.Chart), expectedChart, "chart in relatioship matches")
}
})
Expand Down

0 comments on commit 4bc36cf

Please sign in to comment.