Skip to content

Commit

Permalink
RHINENG-2420: add tests for filters in /view{/systems/advisories,/adv…
Browse files Browse the repository at this point in the history
…isories/systems}
  • Loading branch information
MichaelMraka committed Nov 6, 2023
1 parent 789c2b2 commit c21d328
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions manager/controllers/systems_advisories_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/assert"
)

func doTestView(t *testing.T, handler gin.HandlerFunc, limit, offset *int) *httptest.ResponseRecorder {
func doTestView(t *testing.T, handler gin.HandlerFunc, url string, limit, offset *int) *httptest.ResponseRecorder {
core.SetupTest(t)
body := SystemsAdvisoriesRequest{
Systems: []SystemID{"00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000002"},
Expand All @@ -26,12 +26,12 @@ func doTestView(t *testing.T, handler gin.HandlerFunc, limit, offset *int) *http
panic(err)
}

w := CreateRequestRouterWithParams("POST", "/", bytes.NewBuffer(bodyJSON), "", handler, 1, "POST", "/")
w := CreateRequestRouterWithParams("POST", url, bytes.NewBuffer(bodyJSON), "", handler, 1, "POST", "/")
return w
}

func TestSystemsAdvisoriesView(t *testing.T) {
w := doTestView(t, PostSystemsAdvisories, nil, nil)
w := doTestView(t, PostSystemsAdvisories, "/", nil, nil)
var output SystemsAdvisoriesResponse
CheckResponse(t, w, http.StatusOK, &output)
assert.Equal(t, output.Data["00000000-0000-0000-0000-000000000001"][0], AdvisoryName("RH-1"))
Expand All @@ -40,17 +40,32 @@ func TestSystemsAdvisoriesView(t *testing.T) {
}

func TestAdvisoriesSystemsView(t *testing.T) {
w := doTestView(t, PostAdvisoriesSystems, nil, nil)
w := doTestView(t, PostAdvisoriesSystems, "/", nil, nil)
var output AdvisoriesSystemsResponse
CheckResponse(t, w, http.StatusOK, &output)
assert.Equal(t, output.Data["RH-1"][0], SystemID("00000000-0000-0000-0000-000000000001"))
assert.Equal(t, output.Data["RH-3"][0], SystemID("00000000-0000-0000-0000-000000000001"))
}

func TestSystemsAdvisoriesViewTags(t *testing.T) {
w := doTestView(t, PostSystemsAdvisories, "/?filter[system_profile][sap_sids]=DEF", nil, nil)
var output SystemsAdvisoriesResponse
CheckResponse(t, w, http.StatusOK, &output)
assert.Equal(t, output.Data["00000000-0000-0000-0000-000000000001"][0], AdvisoryName("RH-1"))
assert.Equal(t, output.Data["00000000-0000-0000-0000-000000000001"][1], AdvisoryName("RH-3"))
}

func TestAdvisoriesSystemsViewTags(t *testing.T) {
w := doTestView(t, PostAdvisoriesSystems, "/?filter[system_profile][sap_sids]=DEF", nil, nil)
var output AdvisoriesSystemsResponse
CheckResponse(t, w, http.StatusOK, &output)
assert.Equal(t, output.Data["RH-1"][0], SystemID("00000000-0000-0000-0000-000000000001"))
assert.Equal(t, output.Data["RH-3"][0], SystemID("00000000-0000-0000-0000-000000000001"))
}
func TestSystemAdvisoriesViewOffsetLimit(t *testing.T) {
limit := 3
offset := 0
w := doTestView(t, PostSystemsAdvisories, &limit, &offset)
w := doTestView(t, PostSystemsAdvisories, "/", &limit, &offset)
var output SystemsAdvisoriesResponse
CheckResponse(t, w, http.StatusOK, &output)
assert.Equal(t, 2, len(output.Data))
Expand All @@ -61,15 +76,15 @@ func TestSystemAdvisoriesViewOffsetLimit(t *testing.T) {
func TestSystemAdvisoriesViewOffsetOverflow(t *testing.T) {
limit := 1
offset := 100
w := doTestView(t, PostSystemsAdvisories, &limit, &offset)
w := doTestView(t, PostSystemsAdvisories, "/", &limit, &offset)
var errResp utils.ErrorResponse
CheckResponse(t, w, http.StatusBadRequest, &errResp)
assert.Equal(t, InvalidOffsetMsg, errResp.Error)
}

func TestSystemAdvisoriesViewWrongOffset(t *testing.T) {
offset := 1000
w := doTestView(t, PostSystemsAdvisories, nil, &offset)
w := doTestView(t, PostSystemsAdvisories, "/", nil, &offset)
var errResp utils.ErrorResponse
CheckResponse(t, w, http.StatusBadRequest, &errResp)
assert.Equal(t, InvalidOffsetMsg, errResp.Error)
Expand All @@ -78,7 +93,7 @@ func TestSystemAdvisoriesViewWrongOffset(t *testing.T) {
func TestAvisorySystemsViewOffsetLimit(t *testing.T) {
limit := 3
offset := 0
w := doTestView(t, PostAdvisoriesSystems, &limit, &offset)
w := doTestView(t, PostAdvisoriesSystems, "/", &limit, &offset)
var output AdvisoriesSystemsResponse
CheckResponse(t, w, http.StatusOK, &output)
assert.Equal(t, 2, len(output.Data))
Expand All @@ -89,15 +104,15 @@ func TestAvisorySystemsViewOffsetLimit(t *testing.T) {
func TestAvisorySystemsViewOffsetOverflow(t *testing.T) {
limit := 1
offset := 100
w := doTestView(t, PostAdvisoriesSystems, &limit, &offset)
w := doTestView(t, PostAdvisoriesSystems, "/", &limit, &offset)
var errResp utils.ErrorResponse
CheckResponse(t, w, http.StatusBadRequest, &errResp)
assert.Equal(t, InvalidOffsetMsg, errResp.Error)
}

func TestAvisorySystemsViewWrongOffset(t *testing.T) {
offset := 1000
w := doTestView(t, PostAdvisoriesSystems, nil, &offset)
w := doTestView(t, PostAdvisoriesSystems, "/", nil, &offset)
var errResp utils.ErrorResponse
CheckResponse(t, w, http.StatusBadRequest, &errResp)
assert.Equal(t, InvalidOffsetMsg, errResp.Error)
Expand Down

0 comments on commit c21d328

Please sign in to comment.