You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/11/26 01:46:00 UTC
[GitHub] [apisix-dashboard] ShiningRush commented on a change in pull request #859: feat: add a unit test for consumer and remove implicit init
ShiningRush commented on a change in pull request #859:
URL: https://github.com/apache/apisix-dashboard/pull/859#discussion_r530727111
##########
File path: api/internal/handler/consumer/consumer_test.go
##########
@@ -30,6 +34,53 @@ import (
"github.com/apisix/manager-api/internal/core/store"
)
+func TestHandler_Get(t *testing.T) {
+ tests := []struct {
+ caseDesc string
+ giveInput *GetInput
+ giveRet interface{}
+ giveErr error
+ wantErr error
+ wantGetKey string
+ wantRet interface{}
+ }{
+ {
+ caseDesc: "normal",
+ giveInput: &GetInput{Username: "test"},
+ wantGetKey: "test",
+ giveRet: "hello",
+ wantRet: "hello",
+ },
+ {
+ caseDesc: "failed",
+ giveInput: &GetInput{Username: "failed key"},
+ wantGetKey: "failed key",
+ giveErr: fmt.Errorf("get failed"),
+ wantErr: fmt.Errorf("get failed"),
+ wantRet: &data.SpecCodeResponse{
+ StatusCode: http.StatusInternalServerError,
+ },
+ },
+ }
+
+ for _, tc := range tests {
+ getCalled := true
+ mStore := &store.MockInterface{}
+ mStore.On("Get", mock.Anything).Run(func(args mock.Arguments) {
+ getCalled = true
+ assert.Equal(t, tc.wantGetKey, args.Get(0), tc.caseDesc)
+ }).Return(tc.giveRet, tc.giveErr)
+
+ h := Handler{consumerStore: mStore}
+ ctx := droplet.NewContext()
+ ctx.SetInput(tc.giveInput)
+ ret, err := h.Get(ctx)
+ assert.True(t, getCalled, tc.caseDesc)
+ assert.Equal(t, tc.wantRet, ret, tc.caseDesc)
+ assert.Equal(t, tc.wantErr, err, tc.caseDesc)
+ }
+}
+
Review comment:
OK, I will do it this week
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org