diff --git a/.github/workflows/build_dev.yml b/.github/workflows/build_dev.yml index 8df3ed975..07515c83d 100644 --- a/.github/workflows/build_dev.yml +++ b/.github/workflows/build_dev.yml @@ -13,7 +13,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.18.3' + go-version: '1.21' - name: Login to DockerHub uses: docker/login-action@v1 with: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 86a785518..9cf454db5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,12 +13,12 @@ jobs: steps: - uses: actions/setup-go@v2 with: - go-version: '1.18' + go-version: '1.21' - uses: actions/checkout@v2 with: fetch-depth: 0 - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: skip-go-installation: true - version: v1.50.1 + version: v1.54 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d308bda10..a75b956be 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.18.3' + go-version: '1.21' - name: Login to DockerHub uses: docker/login-action@v1 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e026f7ea4..f1fbea856 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.18' + go-version: '1.21' - name: install dependencies run: go mod tidy - name: test binaries @@ -74,7 +74,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.18' + go-version: '1.21' - name: install dependencies run: go mod tidy - name: install spicedb binary diff --git a/Dockerfile.dev b/Dockerfile.dev index 11752b4e7..166c2ff06 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM golang:1.18-alpine3.15 as builder +FROM golang:1.21-alpine3.19 as builder RUN apk add make @@ -11,7 +11,7 @@ COPY . . RUN make build -FROM alpine:3.16 +FROM alpine:3.19 COPY --from=builder /go/src/app/shield /usr/bin/ RUN apk update RUN apk add ca-certificates diff --git a/docs/docs/installation.md b/docs/docs/installation.md index 6331becd0..3a4569d45 100644 --- a/docs/docs/installation.md +++ b/docs/docs/installation.md @@ -51,7 +51,7 @@ $ docker run -p 8080:8080 \ Shield requires the following dependencies: -- Golang (version 1.18 or above) +- Golang (version 1.21 or above) - Git ### Build diff --git a/go.mod b/go.mod index 52d97088f..1fc979220 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/goto/shield -go 1.18 +go 1.21 require ( contrib.go.opencensus.io/exporter/prometheus v0.4.2 diff --git a/internal/api/v1beta1/action_test.go b/internal/api/v1beta1/action_test.go index de1813077..dc7f25c87 100644 --- a/internal/api/v1beta1/action_test.go +++ b/internal/api/v1beta1/action_test.go @@ -146,7 +146,7 @@ func TestCreateAction(t *testing.T) { { title: "should return internal error if action service return some error", setup: func(as *mocks.ActionService) { - as.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), action.Action{ + as.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), action.Action{ ID: testActionMap[testActionID].ID, Name: testActionMap[testActionID].Name, NamespaceID: testActionMap[testActionID].NamespaceID, @@ -164,7 +164,7 @@ func TestCreateAction(t *testing.T) { { title: "should return bad request error if namespace id is wrong", setup: func(as *mocks.ActionService) { - as.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), action.Action{ + as.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), action.Action{ ID: testActionMap[testActionID].ID, Name: testActionMap[testActionID].Name, NamespaceID: testActionMap[testActionID].NamespaceID, @@ -182,7 +182,7 @@ func TestCreateAction(t *testing.T) { { title: "should return bad request error if if id is empty", setup: func(as *mocks.ActionService) { - as.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), action.Action{ + as.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), action.Action{ Name: testActionMap[testActionID].Name, NamespaceID: testActionMap[testActionID].NamespaceID, }).Return(action.Action{}, action.ErrInvalidID) @@ -198,7 +198,7 @@ func TestCreateAction(t *testing.T) { { title: "should return bad request error if if name is empty", setup: func(as *mocks.ActionService) { - as.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), action.Action{ + as.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), action.Action{ ID: testActionMap[testActionID].ID, NamespaceID: testActionMap[testActionID].NamespaceID, }).Return(action.Action{}, action.ErrInvalidDetail) @@ -214,7 +214,7 @@ func TestCreateAction(t *testing.T) { { title: "should return success if action service return nil error", setup: func(as *mocks.ActionService) { - as.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), action.Action{ + as.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), action.Action{ ID: testActionMap[testActionID].ID, Name: testActionMap[testActionID].Name, NamespaceID: testActionMap[testActionID].NamespaceID, @@ -246,7 +246,7 @@ func TestCreateAction(t *testing.T) { tt.setup(mockActionSrv) } mockDep := Handler{actionService: mockActionSrv} - resp, err := mockDep.CreateAction(context.Background(), tt.req) + resp, err := mockDep.CreateAction(context.TODO(), tt.req) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.err, err) }) @@ -264,7 +264,7 @@ func TestHandler_GetAction(t *testing.T) { { name: "should return internal error if action service return some error", setup: func(as *mocks.ActionService) { - as.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testActionID).Return(action.Action{}, errors.New("some error")) + as.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testActionID).Return(action.Action{}, errors.New("some error")) }, request: &shieldv1beta1.GetActionRequest{ Id: testActionID, @@ -275,7 +275,7 @@ func TestHandler_GetAction(t *testing.T) { { name: "should return not found error if action id not exist", setup: func(as *mocks.ActionService) { - as.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testActionID).Return(action.Action{}, action.ErrNotExist) + as.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testActionID).Return(action.Action{}, action.ErrNotExist) }, request: &shieldv1beta1.GetActionRequest{ Id: testActionID, @@ -286,7 +286,7 @@ func TestHandler_GetAction(t *testing.T) { { name: "should return not found error if action id is empty", setup: func(as *mocks.ActionService) { - as.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(action.Action{}, action.ErrInvalidID) + as.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(action.Action{}, action.ErrInvalidID) }, request: &shieldv1beta1.GetActionRequest{}, want: nil, @@ -295,7 +295,7 @@ func TestHandler_GetAction(t *testing.T) { { name: "should return success if action service return nil error", setup: func(as *mocks.ActionService) { - as.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testActionID).Return(testActionMap[testActionID], nil) + as.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testActionID).Return(testActionMap[testActionID], nil) }, request: &shieldv1beta1.GetActionRequest{ Id: testActionID, @@ -318,7 +318,7 @@ func TestHandler_GetAction(t *testing.T) { tt.setup(mockActionSrv) } mockDep := Handler{actionService: mockActionSrv} - resp, err := mockDep.GetAction(context.Background(), tt.request) + resp, err := mockDep.GetAction(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -336,7 +336,7 @@ func TestHandler_UpdateAction(t *testing.T) { { name: "should return internal error if action service return some error", setup: func(as *mocks.ActionService) { - as.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testActionID, action.Action{ + as.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testActionID, action.Action{ ID: testActionID, Name: testActionMap[testActionID].Name, NamespaceID: testActionMap[testActionID].NamespaceID, @@ -355,7 +355,7 @@ func TestHandler_UpdateAction(t *testing.T) { { name: "should return not found error if action id not exist", setup: func(as *mocks.ActionService) { - as.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testActionID, action.Action{ + as.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testActionID, action.Action{ ID: testActionID, Name: testActionMap[testActionID].Name, NamespaceID: testActionMap[testActionID].NamespaceID}).Return(action.Action{}, action.ErrNotExist) @@ -374,7 +374,7 @@ func TestHandler_UpdateAction(t *testing.T) { { name: "should return not found error if action id is empty", setup: func(as *mocks.ActionService) { - as.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), "", action.Action{ + as.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), "", action.Action{ Name: testActionMap[testActionID].Name, NamespaceID: testActionMap[testActionID].NamespaceID}).Return(action.Action{}, action.ErrInvalidID) }, @@ -391,7 +391,7 @@ func TestHandler_UpdateAction(t *testing.T) { { name: "should return bad request error if namespace id not exist", setup: func(as *mocks.ActionService) { - as.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testActionMap[testActionID].ID, action.Action{ + as.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testActionMap[testActionID].ID, action.Action{ ID: testActionID, Name: testActionMap[testActionID].Name, NamespaceID: testActionMap[testActionID].NamespaceID}).Return(action.Action{}, namespace.ErrNotExist) @@ -410,7 +410,7 @@ func TestHandler_UpdateAction(t *testing.T) { { name: "should return bad request error if name is empty", setup: func(as *mocks.ActionService) { - as.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testActionMap[testActionID].ID, action.Action{ + as.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testActionMap[testActionID].ID, action.Action{ ID: testActionID, NamespaceID: testActionMap[testActionID].NamespaceID}).Return(action.Action{}, action.ErrInvalidDetail) }, @@ -427,7 +427,7 @@ func TestHandler_UpdateAction(t *testing.T) { { name: "should return success if action service return nil error", setup: func(as *mocks.ActionService) { - as.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testActionMap[testActionID].ID, action.Action{ + as.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testActionMap[testActionID].ID, action.Action{ ID: testActionID, Name: testActionMap[testActionID].Name, NamespaceID: testActionMap[testActionID].NamespaceID, @@ -459,7 +459,7 @@ func TestHandler_UpdateAction(t *testing.T) { tt.setup(mockActionSrv) } mockDep := Handler{actionService: mockActionSrv} - resp, err := mockDep.UpdateAction(context.Background(), tt.request) + resp, err := mockDep.UpdateAction(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) diff --git a/internal/api/v1beta1/group_test.go b/internal/api/v1beta1/group_test.go index f7da02c28..0c365c6a7 100644 --- a/internal/api/v1beta1/group_test.go +++ b/internal/api/v1beta1/group_test.go @@ -112,7 +112,7 @@ func TestHandler_ListGroups(t *testing.T) { { name: "should return empty groups if query param org_id is not uuid", setup: func(gs *mocks.GroupService) { - gs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx"), group.Filter{ + gs.EXPECT().List(mock.AnythingOfType("context.todoCtx"), group.Filter{ OrganizationID: "some-id", }).Return([]group.Group{}, nil) }, @@ -127,7 +127,7 @@ func TestHandler_ListGroups(t *testing.T) { { name: "should return empty groups if query param org_id is not exist", setup: func(gs *mocks.GroupService) { - gs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx"), group.Filter{ + gs.EXPECT().List(mock.AnythingOfType("context.todoCtx"), group.Filter{ OrganizationID: randomID, }).Return([]group.Group{}, nil) }, @@ -146,7 +146,7 @@ func TestHandler_ListGroups(t *testing.T) { for _, u := range testGroupMap { testGroupList = append(testGroupList, u) } - gs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx"), group.Filter{}).Return(testGroupList, nil) + gs.EXPECT().List(mock.AnythingOfType("context.todoCtx"), group.Filter{}).Return(testGroupList, nil) }, request: &shieldv1beta1.ListGroupsRequest{}, want: &shieldv1beta1.ListGroupsResponse{ @@ -175,7 +175,7 @@ func TestHandler_ListGroups(t *testing.T) { for _, u := range testGroupMap { testGroupList = append(testGroupList, u) } - gs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx"), group.Filter{ + gs.EXPECT().List(mock.AnythingOfType("context.todoCtx"), group.Filter{ OrganizationID: "9f256f86-31a3-11ec-8d3d-0242ac130003", }).Return(testGroupList, nil) }, @@ -211,7 +211,7 @@ func TestHandler_ListGroups(t *testing.T) { h := Handler{ groupService: mockGroupSvc, } - got, err := h.ListGroups(context.Background(), tt.request) + got, err := h.ListGroups(context.TODO(), tt.request) assert.EqualValues(t, got, tt.want) assert.EqualValues(t, err, tt.wantErr) }) @@ -232,7 +232,7 @@ func TestHandler_CreateGroup(t *testing.T) { { name: "should return unauthenticated error if auth email in context is empty and group service return invalid user email", setup: func(ctx context.Context, gs *mocks.GroupService) context.Context { - gs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), group.Group{ Name: "some group", Slug: "some-group", @@ -399,7 +399,7 @@ func TestHandler_CreateGroup(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { mockGroupSvc := new(mocks.GroupService) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { ctx = tt.setup(ctx, mockGroupSvc) } @@ -425,7 +425,7 @@ func TestHandler_GetGroup(t *testing.T) { { name: "should return internal error if group service return some error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), someGroupID).Return(group.Group{}, errors.New("some error")) + gs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), someGroupID).Return(group.Group{}, errors.New("some error")) }, request: &shieldv1beta1.GetGroupRequest{Id: someGroupID}, want: nil, @@ -434,7 +434,7 @@ func TestHandler_GetGroup(t *testing.T) { { name: "should return not found error if id is invalid", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(group.Group{}, group.ErrInvalidID) + gs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(group.Group{}, group.ErrInvalidID) }, request: &shieldv1beta1.GetGroupRequest{}, want: nil, @@ -443,7 +443,7 @@ func TestHandler_GetGroup(t *testing.T) { { name: "should return not found error if group not exist", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(group.Group{}, group.ErrNotExist) + gs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(group.Group{}, group.ErrNotExist) }, request: &shieldv1beta1.GetGroupRequest{}, want: nil, @@ -452,7 +452,7 @@ func TestHandler_GetGroup(t *testing.T) { { name: "should return success if group service return nil", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testGroupID).Return(testGroupMap[testGroupID], nil) + gs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testGroupID).Return(testGroupMap[testGroupID], nil) }, request: &shieldv1beta1.GetGroupRequest{Id: testGroupID}, want: &shieldv1beta1.GetGroupResponse{ @@ -482,7 +482,7 @@ func TestHandler_GetGroup(t *testing.T) { h := Handler{ groupService: mockGroupSvc, } - got, err := h.GetGroup(context.Background(), tt.request) + got, err := h.GetGroup(context.TODO(), tt.request) assert.EqualValues(t, got, tt.want) assert.EqualValues(t, err, tt.wantErr) }) @@ -503,7 +503,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return internal error if group service return some error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ ID: someGroupID, Name: "new group", Slug: "new-group", @@ -535,7 +535,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return not found error if group id is not uuid (slug) and does not exist", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ Name: "new group", Slug: "some-id", OrganizationID: someOrgID, @@ -557,7 +557,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return not found error if group id is uuid and does not exist", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ ID: someGroupID, Name: "new group", Slug: "new-group", @@ -580,7 +580,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return not found error if group id is empty", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ Name: "new group", Slug: "", // consider it by slug and make the slug empty OrganizationID: someOrgID, @@ -601,7 +601,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return already exist error if group service return error conflict", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ ID: someGroupID, Name: "new group", Slug: "new-group", @@ -624,7 +624,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return bad request error if org id does not exist", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ ID: someGroupID, Name: "new group", Slug: "new-group", @@ -647,7 +647,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return bad request error if org id is not uuid", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ ID: someGroupID, Name: "new group", Slug: "new-group", @@ -670,7 +670,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return bad request error if name is empty", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ ID: someGroupID, Slug: "new-group", OrganizationID: someOrgID, @@ -691,7 +691,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return bad request error if slug is empty", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ ID: someGroupID, Name: "new group", OrganizationID: someOrgID, @@ -712,7 +712,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return success if updated by id and group service return nil error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ ID: someGroupID, Name: "new group", Slug: "new-group", @@ -754,7 +754,7 @@ func TestHandler_UpdateGroup(t *testing.T) { { name: "should return success if updated by slug and group service return nil error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), group.Group{ + gs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), group.Group{ Name: "new group", Slug: "some-slug", OrganizationID: someOrgID, @@ -802,7 +802,7 @@ func TestHandler_UpdateGroup(t *testing.T) { h := Handler{ groupService: mockGroupSvc, } - got, err := h.UpdateGroup(context.Background(), tt.request) + got, err := h.UpdateGroup(context.TODO(), tt.request) assert.EqualValues(t, got, tt.want) assert.EqualValues(t, err, tt.wantErr) }) @@ -836,7 +836,7 @@ func TestHandler_ListGroupRelations(t *testing.T) { { name: "should return internal error if relation service return some error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().ListGroupRelations(mock.AnythingOfType("*context.emptyCtx"), "group-id", "", "").Return([]user.User{}, []group.Group{}, map[string][]string{}, map[string][]string{}, errors.New("some error")) + gs.EXPECT().ListGroupRelations(mock.AnythingOfType("context.todoCtx"), "group-id", "", "").Return([]user.User{}, []group.Group{}, map[string][]string{}, map[string][]string{}, errors.New("some error")) }, request: &shieldv1beta1.ListGroupRelationsRequest{ Id: "group-id", @@ -849,7 +849,7 @@ func TestHandler_ListGroupRelations(t *testing.T) { { name: "should return relations of subject_type-user and role-role1 if relation service return nil error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().ListGroupRelations(mock.AnythingOfType("*context.emptyCtx"), "group-id", schema.UserPrincipal, "role-1").Return(testUsersRole1, []group.Group{}, testUserIDRoleMapRole1, map[string][]string{}, nil) + gs.EXPECT().ListGroupRelations(mock.AnythingOfType("context.todoCtx"), "group-id", schema.UserPrincipal, "role-1").Return(testUsersRole1, []group.Group{}, testUserIDRoleMapRole1, map[string][]string{}, nil) }, request: &shieldv1beta1.ListGroupRelationsRequest{ Id: "group-id", @@ -879,7 +879,7 @@ func TestHandler_ListGroupRelations(t *testing.T) { { name: "should return relations of subject_type-user and role-role2 if relation service return nil error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().ListGroupRelations(mock.AnythingOfType("*context.emptyCtx"), "group-id", schema.UserPrincipal, "role-2").Return(testUsersRole2, []group.Group{}, testUserIDRoleMapRole2, map[string][]string{}, nil) + gs.EXPECT().ListGroupRelations(mock.AnythingOfType("context.todoCtx"), "group-id", schema.UserPrincipal, "role-2").Return(testUsersRole2, []group.Group{}, testUserIDRoleMapRole2, map[string][]string{}, nil) }, request: &shieldv1beta1.ListGroupRelationsRequest{ Id: "group-id", @@ -902,7 +902,7 @@ func TestHandler_ListGroupRelations(t *testing.T) { { name: "should return relations of subject_type-group and role-role2 if relation service return nil error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().ListGroupRelations(mock.AnythingOfType("*context.emptyCtx"), "group-id", schema.GroupPrincipal, "role-2").Return([]user.User{}, testGroupsRole2, map[string][]string{}, testGroupIDRoleMapRole2, nil) + gs.EXPECT().ListGroupRelations(mock.AnythingOfType("context.todoCtx"), "group-id", schema.GroupPrincipal, "role-2").Return([]user.User{}, testGroupsRole2, map[string][]string{}, testGroupIDRoleMapRole2, nil) }, request: &shieldv1beta1.ListGroupRelationsRequest{ Id: "group-id", @@ -926,7 +926,7 @@ func TestHandler_ListGroupRelations(t *testing.T) { { name: "should return relations both group and users for role-role2 if relation service return nil error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().ListGroupRelations(mock.AnythingOfType("*context.emptyCtx"), "group-id", "", "role-2").Return(testUsersRole2, testGroupsRole2, testUserIDRoleMapRole2, testGroupIDRoleMapRole2, nil) + gs.EXPECT().ListGroupRelations(mock.AnythingOfType("context.todoCtx"), "group-id", "", "role-2").Return(testUsersRole2, testGroupsRole2, testUserIDRoleMapRole2, testGroupIDRoleMapRole2, nil) }, request: &shieldv1beta1.ListGroupRelationsRequest{ Id: "group-id", @@ -956,7 +956,7 @@ func TestHandler_ListGroupRelations(t *testing.T) { { name: "should return relations both group and users with all roles if relation service return nil error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().ListGroupRelations(mock.AnythingOfType("*context.emptyCtx"), "group-id", "", "").Return(testUsersAnyRole, testGroupsAnyRole, testUserIDRoleMapAnyRole, testGroupIDRoleMapAnyRole, nil) + gs.EXPECT().ListGroupRelations(mock.AnythingOfType("context.todoCtx"), "group-id", "", "").Return(testUsersAnyRole, testGroupsAnyRole, testUserIDRoleMapAnyRole, testGroupIDRoleMapAnyRole, nil) }, request: &shieldv1beta1.ListGroupRelationsRequest{ Id: "group-id", @@ -1005,7 +1005,7 @@ func TestHandler_ListGroupRelations(t *testing.T) { tt.setup(mockGroupSrv) } mockDep := Handler{groupService: mockGroupSrv} - resp, err := mockDep.ListGroupRelations(context.Background(), tt.request) + resp, err := mockDep.ListGroupRelations(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) diff --git a/internal/api/v1beta1/namespace_test.go b/internal/api/v1beta1/namespace_test.go index ad951f041..1eeb1cb73 100644 --- a/internal/api/v1beta1/namespace_test.go +++ b/internal/api/v1beta1/namespace_test.go @@ -99,7 +99,7 @@ func TestListNamespaces(t *testing.T) { tt.setup(mockNamespaceSrv) } mockDep := Handler{namespaceService: mockNamespaceSrv} - resp, err := mockDep.ListNamespaces(context.Background(), tt.req) + resp, err := mockDep.ListNamespaces(context.TODO(), tt.req) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.err, err) @@ -118,7 +118,7 @@ func TestCreateNamespace(t *testing.T) { { title: "should return internal error if namespace service return some error", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), namespace.Namespace{ + ns.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), namespace.Namespace{ ID: "team", Name: "Team", }).Return(namespace.Namespace{}, errors.New("some error")) @@ -133,7 +133,7 @@ func TestCreateNamespace(t *testing.T) { { title: "should return already exist error if namespace service return err conflict", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), namespace.Namespace{ + ns.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), namespace.Namespace{ ID: "team", Name: "Team", }).Return(namespace.Namespace{}, namespace.ErrConflict) @@ -148,7 +148,7 @@ func TestCreateNamespace(t *testing.T) { { title: "should return bad request error if id is empty", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), namespace.Namespace{ + ns.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), namespace.Namespace{ Name: "Team", }).Return(namespace.Namespace{}, namespace.ErrInvalidID) }, @@ -161,7 +161,7 @@ func TestCreateNamespace(t *testing.T) { { title: "should return bad request error if name is empty", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), namespace.Namespace{ + ns.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), namespace.Namespace{ ID: "team", }).Return(namespace.Namespace{}, namespace.ErrInvalidDetail) }, @@ -201,7 +201,7 @@ func TestCreateNamespace(t *testing.T) { tt.setup(mockNamespaceSrv) } mockDep := Handler{namespaceService: mockNamespaceSrv} - resp, err := mockDep.CreateNamespace(context.Background(), tt.req) + resp, err := mockDep.CreateNamespace(context.TODO(), tt.req) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.err, err) }) @@ -219,7 +219,7 @@ func TestHandler_GetNamespace(t *testing.T) { { name: "should return internal error if namespace service return some error", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testNSID).Return(namespace.Namespace{}, errors.New("some error")) + ns.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testNSID).Return(namespace.Namespace{}, errors.New("some error")) }, request: &shieldv1beta1.GetNamespaceRequest{ Id: testNSID, @@ -230,7 +230,7 @@ func TestHandler_GetNamespace(t *testing.T) { { name: "should return not found error if namespace id is empty", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(namespace.Namespace{}, namespace.ErrInvalidID) + ns.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(namespace.Namespace{}, namespace.ErrInvalidID) }, request: &shieldv1beta1.GetNamespaceRequest{}, want: nil, @@ -239,7 +239,7 @@ func TestHandler_GetNamespace(t *testing.T) { { name: "should return not found error if namespace id not exist", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testNSID).Return(namespace.Namespace{}, namespace.ErrNotExist) + ns.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testNSID).Return(namespace.Namespace{}, namespace.ErrNotExist) }, request: &shieldv1beta1.GetNamespaceRequest{ Id: testNSID, @@ -250,7 +250,7 @@ func TestHandler_GetNamespace(t *testing.T) { { name: "should return success is namespace service return nil error", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testNSID).Return(namespace.Namespace{ + ns.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testNSID).Return(namespace.Namespace{ ID: testNSMap[testNSID].ID, Name: testNSMap[testNSID].Name, }, nil) @@ -276,7 +276,7 @@ func TestHandler_GetNamespace(t *testing.T) { tt.setup(mockNamespaceSrv) } mockDep := Handler{namespaceService: mockNamespaceSrv} - resp, err := mockDep.GetNamespace(context.Background(), tt.request) + resp, err := mockDep.GetNamespace(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -294,7 +294,7 @@ func TestHandler_UpdateNamespace(t *testing.T) { { name: "should return internal error if namespace service return some error", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), namespace.Namespace{ + ns.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), namespace.Namespace{ ID: testNSID, Name: testNSMap[testNSID].Name, }).Return(namespace.Namespace{}, errors.New("some error")) @@ -312,7 +312,7 @@ func TestHandler_UpdateNamespace(t *testing.T) { { name: "should return not found error if namespace id not exist", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), namespace.Namespace{ + ns.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), namespace.Namespace{ ID: testNSID, Name: testNSMap[testNSID].Name, }).Return(namespace.Namespace{}, namespace.ErrNotExist) @@ -330,7 +330,7 @@ func TestHandler_UpdateNamespace(t *testing.T) { { name: "should return already exist error if namespace service return err conflict", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), namespace.Namespace{ + ns.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), namespace.Namespace{ ID: testNSID, Name: testNSMap[testNSID].Name, }).Return(namespace.Namespace{}, namespace.ErrConflict) @@ -348,7 +348,7 @@ func TestHandler_UpdateNamespace(t *testing.T) { { name: "should return bad request error if namespace name is empty", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), namespace.Namespace{ + ns.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), namespace.Namespace{ ID: testNSID, }).Return(namespace.Namespace{}, namespace.ErrInvalidDetail) }, @@ -364,7 +364,7 @@ func TestHandler_UpdateNamespace(t *testing.T) { { name: "should return success if namespace service return nil error", setup: func(ns *mocks.NamespaceService) { - ns.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), namespace.Namespace{ + ns.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), namespace.Namespace{ ID: testNSID, Name: testNSMap[testNSID].Name, }).Return(namespace.Namespace{ @@ -397,7 +397,7 @@ func TestHandler_UpdateNamespace(t *testing.T) { tt.setup(mockNamespaceSrv) } mockDep := Handler{namespaceService: mockNamespaceSrv} - resp, err := mockDep.UpdateNamespace(context.Background(), tt.request) + resp, err := mockDep.UpdateNamespace(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) diff --git a/internal/api/v1beta1/org_test.go b/internal/api/v1beta1/org_test.go index 75825968f..c6fc26bb8 100644 --- a/internal/api/v1beta1/org_test.go +++ b/internal/api/v1beta1/org_test.go @@ -49,7 +49,7 @@ func TestListOrganizations(t *testing.T) { { title: "should return internal error if org service return some error", setup: func(os *mocks.OrganizationService) { - os.EXPECT().List(mock.AnythingOfType("*context.emptyCtx")).Return([]organization.Organization{}, errors.New("some error")) + os.EXPECT().List(mock.AnythingOfType("context.todoCtx")).Return([]organization.Organization{}, errors.New("some error")) }, want: nil, err: status.Errorf(codes.Internal, ErrInternalServer.Error()), @@ -60,7 +60,7 @@ func TestListOrganizations(t *testing.T) { for _, o := range testOrgMap { testOrgList = append(testOrgList, o) } - os.EXPECT().List(mock.AnythingOfType("*context.emptyCtx")).Return(testOrgList, nil) + os.EXPECT().List(mock.AnythingOfType("context.todoCtx")).Return(testOrgList, nil) }, want: &shieldv1beta1.ListOrganizationsResponse{Organizations: []*shieldv1beta1.Organization{ { @@ -89,7 +89,7 @@ func TestListOrganizations(t *testing.T) { if tt.setup != nil { tt.setup(mockOrgSrv) } - resp, err := mockDep.ListOrganizations(context.Background(), nil) + resp, err := mockDep.ListOrganizations(context.TODO(), nil) assert.EqualValues(t, resp, tt.want) assert.EqualValues(t, err, tt.err) }) @@ -108,7 +108,7 @@ func TestCreateOrganization(t *testing.T) { { title: "should return forbidden error if auth email in context is empty and org service return invalid user email", setup: func(ctx context.Context, os *mocks.OrganizationService) context.Context { - os.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), organization.Organization{ + os.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), organization.Organization{ Name: "some org", Slug: "some-org", Metadata: metadata.Metadata{}, @@ -231,7 +231,7 @@ func TestCreateOrganization(t *testing.T) { for _, tt := range table { t.Run(tt.title, func(t *testing.T) { mockOrgSrv := new(mocks.OrganizationService) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { ctx = tt.setup(ctx, mockOrgSrv) } @@ -256,7 +256,7 @@ func TestHandler_GetOrganization(t *testing.T) { { name: "should return internal error if org service return some error", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), someOrgID).Return(organization.Organization{}, errors.New("some error")) + os.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), someOrgID).Return(organization.Organization{}, errors.New("some error")) }, request: &shieldv1beta1.GetOrganizationRequest{ Id: someOrgID, @@ -267,7 +267,7 @@ func TestHandler_GetOrganization(t *testing.T) { { name: "should return not found error if org id is not uuid (slug) and org not exist", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), someOrgID).Return(organization.Organization{}, organization.ErrNotExist) + os.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), someOrgID).Return(organization.Organization{}, organization.ErrNotExist) }, request: &shieldv1beta1.GetOrganizationRequest{ Id: someOrgID, @@ -278,7 +278,7 @@ func TestHandler_GetOrganization(t *testing.T) { { name: "should return not found error if org id is invalid", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(organization.Organization{}, organization.ErrInvalidID) + os.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(organization.Organization{}, organization.ErrInvalidID) }, request: &shieldv1beta1.GetOrganizationRequest{}, want: nil, @@ -287,7 +287,7 @@ func TestHandler_GetOrganization(t *testing.T) { { name: "should return success if org service return nil error", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "9f256f86-31a3-11ec-8d3d-0242ac130003").Return(testOrgMap["9f256f86-31a3-11ec-8d3d-0242ac130003"], nil) + os.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "9f256f86-31a3-11ec-8d3d-0242ac130003").Return(testOrgMap["9f256f86-31a3-11ec-8d3d-0242ac130003"], nil) }, request: &shieldv1beta1.GetOrganizationRequest{ Id: "9f256f86-31a3-11ec-8d3d-0242ac130003", @@ -314,7 +314,7 @@ func TestHandler_GetOrganization(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { mockOrgSrv := new(mocks.OrganizationService) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { tt.setup(mockOrgSrv) } @@ -338,7 +338,7 @@ func TestHandler_UpdateOrganization(t *testing.T) { { name: "should return internal error if org service return some error", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), organization.Organization{ + os.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), organization.Organization{ ID: someOrgID, Name: "new org", Metadata: metadata.Metadata{ @@ -369,7 +369,7 @@ func TestHandler_UpdateOrganization(t *testing.T) { { name: "should return not found error if org id is not uuid (slug) and not exist", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), organization.Organization{ + os.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), organization.Organization{ ID: someOrgID, Name: "new org", Metadata: metadata.Metadata{ @@ -400,7 +400,7 @@ func TestHandler_UpdateOrganization(t *testing.T) { { name: "should return not found error if org id is empty", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), organization.Organization{ + os.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), organization.Organization{ Name: "new org", Slug: "", // consider it by slug and assign empty to slug Metadata: metadata.Metadata{ @@ -429,7 +429,7 @@ func TestHandler_UpdateOrganization(t *testing.T) { { name: "should return already exist error if org service return err conflict", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), organization.Organization{ + os.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), organization.Organization{ ID: someOrgID, Name: "new org", Metadata: metadata.Metadata{ @@ -460,7 +460,7 @@ func TestHandler_UpdateOrganization(t *testing.T) { { name: "should return success if org service is updated by id and return nil error", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), organization.Organization{ + os.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), organization.Organization{ ID: someOrgID, Name: "new org", Metadata: metadata.Metadata{ @@ -515,7 +515,7 @@ func TestHandler_UpdateOrganization(t *testing.T) { { name: "should return success if org service is updated by slug and return nil error", setup: func(os *mocks.OrganizationService) { - os.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), organization.Organization{ + os.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), organization.Organization{ Name: "new org", Slug: "some-slug", Metadata: metadata.Metadata{ @@ -570,7 +570,7 @@ func TestHandler_UpdateOrganization(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { mockOrgSrv := new(mocks.OrganizationService) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { tt.setup(mockOrgSrv) } @@ -594,7 +594,7 @@ func TestHandler_ListOrganizationAdmins(t *testing.T) { { name: "should return internal error if org service return some error", setup: func(os *mocks.OrganizationService) { - os.EXPECT().ListAdmins(mock.AnythingOfType("*context.emptyCtx"), someOrgID).Return([]user.User{}, errors.New("some error")) + os.EXPECT().ListAdmins(mock.AnythingOfType("context.todoCtx"), someOrgID).Return([]user.User{}, errors.New("some error")) }, request: &shieldv1beta1.ListOrganizationAdminsRequest{ Id: someOrgID, @@ -605,7 +605,7 @@ func TestHandler_ListOrganizationAdmins(t *testing.T) { { name: "should return not found error if org id is not exist", setup: func(os *mocks.OrganizationService) { - os.EXPECT().ListAdmins(mock.AnythingOfType("*context.emptyCtx"), someOrgID).Return([]user.User{}, organization.ErrNotExist) + os.EXPECT().ListAdmins(mock.AnythingOfType("context.todoCtx"), someOrgID).Return([]user.User{}, organization.ErrNotExist) }, request: &shieldv1beta1.ListOrganizationAdminsRequest{ Id: someOrgID, @@ -620,7 +620,7 @@ func TestHandler_ListOrganizationAdmins(t *testing.T) { for _, u := range testUserMap { testUserList = append(testUserList, u) } - os.EXPECT().ListAdmins(mock.AnythingOfType("*context.emptyCtx"), someOrgID).Return(testUserList, nil) + os.EXPECT().ListAdmins(mock.AnythingOfType("context.todoCtx"), someOrgID).Return(testUserList, nil) }, request: &shieldv1beta1.ListOrganizationAdminsRequest{ Id: someOrgID, @@ -649,7 +649,7 @@ func TestHandler_ListOrganizationAdmins(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { mockOrgSrv := new(mocks.OrganizationService) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { tt.setup(mockOrgSrv) } diff --git a/internal/api/v1beta1/permission_check_test.go b/internal/api/v1beta1/permission_check_test.go index 2611456b7..407eaee11 100644 --- a/internal/api/v1beta1/permission_check_test.go +++ b/internal/api/v1beta1/permission_check_test.go @@ -29,7 +29,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "Deprecated check single resource permission: should return internal error if relation service's CheckAuthz function returns some error", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, errors.New("some error")) @@ -45,7 +45,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "Deprecated check single resource permission: should return true when CheckAuthz function returns true bool", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(true, nil) @@ -63,7 +63,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "Deprecated check single resource permission: should return false when CheckAuthz function returns false bool", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, nil) @@ -81,7 +81,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "Deprecated check single resource permission: should return unauthenticated error if relation service's CheckAuthz function returns auth error", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, user.ErrInvalidEmail) @@ -97,7 +97,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "should return internal error if relation service's CheckAuthz function returns some error", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, errors.New("some error")) @@ -117,7 +117,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "should return unauthenticated error if relation service's CheckAuthz function returns auth error", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, user.ErrInvalidEmail) @@ -137,7 +137,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "should return validation error if the request has empty resource permission list", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, errors.New("some error")) @@ -151,7 +151,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "should return true when CheckAuthz function returns true bool", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(true, nil) @@ -180,7 +180,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "should return false when CheckAuthz function returns false bool", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, nil) @@ -209,11 +209,11 @@ func TestHandler_CheckResourcePermission(t *testing.T) { { name: "should return internal error if resource service's CheckAuthz returns some error even with multiple resource check failures", setup: func(res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, errors.New("some error")) - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.ViewPermission}).Return(false, errors.New("some error")).Twice() @@ -249,7 +249,7 @@ func TestHandler_CheckResourcePermission(t *testing.T) { } mockDep := Handler{resourceService: mockResourceSrv, checkAPILimit: 5} - resp, err := mockDep.CheckResourcePermission(context.Background(), tt.request) + resp, err := mockDep.CheckResourcePermission(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -528,7 +528,7 @@ func TestHandler_CheckResourceUserPermission(t *testing.T) { } mockDep := Handler{resourceService: mockResourceSrv, checkAPILimit: 5} - resp, err := mockDep.CheckResourceUserPermission(context.Background(), tt.request) + resp, err := mockDep.CheckResourceUserPermission(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) diff --git a/internal/api/v1beta1/policy_test.go b/internal/api/v1beta1/policy_test.go index 9424e72e0..cc29df43b 100644 --- a/internal/api/v1beta1/policy_test.go +++ b/internal/api/v1beta1/policy_test.go @@ -105,7 +105,7 @@ func TestListPolicies(t *testing.T) { tt.setup(mockPolicySrv) } mockDep := Handler{policyService: mockPolicySrv} - resp, err := mockDep.ListPolicies(context.Background(), tt.req) + resp, err := mockDep.ListPolicies(context.TODO(), tt.req) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.err, err) }) @@ -123,7 +123,7 @@ func TestCreatePolicy(t *testing.T) { { title: "should return internal error if policy service return some error", setup: func(ps *mocks.PolicyService) { - ps.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + ps.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), policy.Policy{ NamespaceID: "team", RoleID: "Admin", ActionID: "add-member", @@ -140,7 +140,7 @@ func TestCreatePolicy(t *testing.T) { { title: "should return bad request error if foreign reference not exist", setup: func(ps *mocks.PolicyService) { - ps.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + ps.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), policy.Policy{ NamespaceID: "team", RoleID: "Admin", ActionID: "add-member", @@ -157,7 +157,7 @@ func TestCreatePolicy(t *testing.T) { { title: "should return success if policy service return nil error", setup: func(ps *mocks.PolicyService) { - ps.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + ps.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), policy.Policy{ NamespaceID: "policy-1", RoleID: "reader", ActionID: "read", @@ -228,7 +228,7 @@ func TestCreatePolicy(t *testing.T) { tt.setup(mockPolicySrv) } mockDep := Handler{policyService: mockPolicySrv} - resp, err := mockDep.CreatePolicy(context.Background(), tt.req) + resp, err := mockDep.CreatePolicy(context.TODO(), tt.req) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.err, err) }) @@ -246,7 +246,7 @@ func TestHandler_GetPolicy(t *testing.T) { { name: "should return internal error if policy service return some error", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testPolicyID).Return(policy.Policy{}, errors.New("some error")) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testPolicyID).Return(policy.Policy{}, errors.New("some error")) }, request: &shieldv1beta1.GetPolicyRequest{ Id: testPolicyID, @@ -257,7 +257,7 @@ func TestHandler_GetPolicy(t *testing.T) { { name: "should return not found error if id is empty", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(policy.Policy{}, policy.ErrInvalidID) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(policy.Policy{}, policy.ErrInvalidID) }, request: &shieldv1beta1.GetPolicyRequest{}, want: nil, @@ -266,7 +266,7 @@ func TestHandler_GetPolicy(t *testing.T) { { name: "should return not found error if id is not uuid", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "some-id").Return(policy.Policy{}, policy.ErrInvalidUUID) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "some-id").Return(policy.Policy{}, policy.ErrInvalidUUID) }, request: &shieldv1beta1.GetPolicyRequest{ Id: "some-id", @@ -277,7 +277,7 @@ func TestHandler_GetPolicy(t *testing.T) { { name: "should return not found error if id not exist", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testPolicyID).Return(policy.Policy{}, policy.ErrNotExist) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testPolicyID).Return(policy.Policy{}, policy.ErrNotExist) }, request: &shieldv1beta1.GetPolicyRequest{ Id: testPolicyID, @@ -288,7 +288,7 @@ func TestHandler_GetPolicy(t *testing.T) { { name: "should return success if policy service return nil error", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testPolicyID).Return(testPolicyMap[testPolicyID], nil) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testPolicyID).Return(testPolicyMap[testPolicyID], nil) }, request: &shieldv1beta1.GetPolicyRequest{ Id: testPolicyID, @@ -347,7 +347,7 @@ func TestHandler_GetPolicy(t *testing.T) { tt.setup(mockPolicySrv) } mockDep := Handler{policyService: mockPolicySrv} - resp, err := mockDep.GetPolicy(context.Background(), tt.request) + resp, err := mockDep.GetPolicy(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -365,7 +365,7 @@ func TestHandler_UpdatePolicy(t *testing.T) { { name: "should return internal error if policy service return some error", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), policy.Policy{ ID: testPolicyMap[testPolicyID].ID, RoleID: testPolicyMap[testPolicyID].RoleID, NamespaceID: testPolicyMap[testPolicyID].NamespaceID, @@ -386,7 +386,7 @@ func TestHandler_UpdatePolicy(t *testing.T) { { name: "should return not found error if id is empty", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), policy.Policy{ RoleID: testPolicyMap[testPolicyID].RoleID, NamespaceID: testPolicyMap[testPolicyID].NamespaceID, ActionID: testPolicyMap[testPolicyID].ActionID, @@ -405,7 +405,7 @@ func TestHandler_UpdatePolicy(t *testing.T) { { name: "should return not found error if id is not exist", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), policy.Policy{ ID: testPolicyMap[testPolicyID].ID, RoleID: testPolicyMap[testPolicyID].RoleID, NamespaceID: testPolicyMap[testPolicyID].NamespaceID, @@ -426,7 +426,7 @@ func TestHandler_UpdatePolicy(t *testing.T) { { name: "should return not found error if id is not uuid", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), policy.Policy{ ID: "some-id", RoleID: testPolicyMap[testPolicyID].RoleID, NamespaceID: testPolicyMap[testPolicyID].NamespaceID, @@ -447,7 +447,7 @@ func TestHandler_UpdatePolicy(t *testing.T) { { name: "should return bad request error if field value not exist in foreign reference", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), policy.Policy{ ID: testPolicyMap[testPolicyID].ID, RoleID: testPolicyMap[testPolicyID].RoleID, NamespaceID: testPolicyMap[testPolicyID].NamespaceID, @@ -468,7 +468,7 @@ func TestHandler_UpdatePolicy(t *testing.T) { { name: "should return already exist error if policy service return err conflict", setup: func(rs *mocks.PolicyService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), policy.Policy{ ID: testPolicyMap[testPolicyID].ID, RoleID: testPolicyMap[testPolicyID].RoleID, NamespaceID: testPolicyMap[testPolicyID].NamespaceID, @@ -493,7 +493,7 @@ func TestHandler_UpdatePolicy(t *testing.T) { for _, p := range testPolicyMap { testPoliciesList = append(testPoliciesList, p) } - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), policy.Policy{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), policy.Policy{ ID: testPolicyMap[testPolicyID].ID, RoleID: testPolicyMap[testPolicyID].RoleID, NamespaceID: testPolicyMap[testPolicyID].NamespaceID, @@ -564,7 +564,7 @@ func TestHandler_UpdatePolicy(t *testing.T) { tt.setup(mockPolicySrv) } mockDep := Handler{policyService: mockPolicySrv} - resp, err := mockDep.UpdatePolicy(context.Background(), tt.request) + resp, err := mockDep.UpdatePolicy(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) diff --git a/internal/api/v1beta1/project_test.go b/internal/api/v1beta1/project_test.go index 05eb52ec8..2643f4f53 100644 --- a/internal/api/v1beta1/project_test.go +++ b/internal/api/v1beta1/project_test.go @@ -242,7 +242,7 @@ func TestCreateProject(t *testing.T) { for _, tt := range table { t.Run(tt.title, func(t *testing.T) { mockProjectSrv := new(mocks.ProjectService) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { ctx = tt.setup(ctx, mockProjectSrv) } @@ -266,7 +266,7 @@ func TestListProjects(t *testing.T) { title: "should return internal error if project service return some error", req: &shieldv1beta1.ListProjectsRequest{}, setup: func(ps *mocks.ProjectService) { - ps.EXPECT().List(mock.AnythingOfType("*context.emptyCtx")).Return([]project.Project{}, errors.New("some error")) + ps.EXPECT().List(mock.AnythingOfType("context.todoCtx")).Return([]project.Project{}, errors.New("some error")) }, want: nil, err: grpcInternalServerError, @@ -281,7 +281,7 @@ func TestListProjects(t *testing.T) { prjs = append(prjs, testProjectMap[projectID]) } - ps.EXPECT().List(mock.AnythingOfType("*context.emptyCtx")).Return(prjs, nil) + ps.EXPECT().List(mock.AnythingOfType("context.todoCtx")).Return(prjs, nil) }, want: &shieldv1beta1.ListProjectsResponse{Projects: []*shieldv1beta1.Project{ { @@ -322,7 +322,7 @@ func TestListProjects(t *testing.T) { tt.setup(mockProjectSrv) } mockDep := Handler{projectService: mockProjectSrv} - resp, err := mockDep.ListProjects(context.Background(), tt.req) + resp, err := mockDep.ListProjects(context.TODO(), tt.req) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.err, err) }) @@ -345,7 +345,7 @@ func TestGetProject(t *testing.T) { Id: someProjectID, }, setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), someProjectID).Return(project.Project{}, errors.New("some error")) + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), someProjectID).Return(project.Project{}, errors.New("some error")) }, err: grpcInternalServerError, }, @@ -355,7 +355,7 @@ func TestGetProject(t *testing.T) { Id: someProjectID, }, setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), someProjectID).Return(project.Project{}, project.ErrNotExist) + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), someProjectID).Return(project.Project{}, project.ErrNotExist) }, err: grpcProjectNotFoundErr, }, @@ -365,7 +365,7 @@ func TestGetProject(t *testing.T) { Id: "some-id", }, setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "some-id").Return(project.Project{}, project.ErrInvalidUUID) + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "some-id").Return(project.Project{}, project.ErrInvalidUUID) }, err: grpcProjectNotFoundErr, }, @@ -373,7 +373,7 @@ func TestGetProject(t *testing.T) { title: "should return project not found if project id is empty", req: &shieldv1beta1.GetProjectRequest{}, setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(project.Project{}, project.ErrInvalidUUID) + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(project.Project{}, project.ErrInvalidUUID) }, err: grpcProjectNotFoundErr, }, @@ -383,7 +383,7 @@ func TestGetProject(t *testing.T) { Id: someProjectID, }, setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), someProjectID).Return( + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), someProjectID).Return( testProjectMap[testProjectID], nil) }, want: &shieldv1beta1.GetProjectResponse{Project: &shieldv1beta1.Project{ @@ -410,7 +410,7 @@ func TestGetProject(t *testing.T) { tt.setup(mockProjectSrv) } mockDep := Handler{projectService: mockProjectSrv} - resp, err := mockDep.GetProject(context.Background(), tt.req) + resp, err := mockDep.GetProject(context.TODO(), tt.req) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.err, err) }) @@ -428,7 +428,7 @@ func TestHandler_UpdateProject(t *testing.T) { { name: "should return internal error if project service return some error", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testProjectMap[testProjectID]).Return(project.Project{}, errors.New("some error")) + ps.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testProjectMap[testProjectID]).Return(project.Project{}, errors.New("some error")) }, request: &shieldv1beta1.UpdateProjectRequest{ Id: testProjectID, @@ -449,7 +449,7 @@ func TestHandler_UpdateProject(t *testing.T) { { name: "should return not found error if org id is not uuid", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testProjectMap[testProjectID]).Return(project.Project{}, organization.ErrInvalidUUID) + ps.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testProjectMap[testProjectID]).Return(project.Project{}, organization.ErrInvalidUUID) }, request: &shieldv1beta1.UpdateProjectRequest{ Id: testProjectID, @@ -470,7 +470,7 @@ func TestHandler_UpdateProject(t *testing.T) { { name: "should return not found error if project not exist", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testProjectMap[testProjectID]).Return(project.Project{}, project.ErrNotExist) + ps.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testProjectMap[testProjectID]).Return(project.Project{}, project.ErrNotExist) }, request: &shieldv1beta1.UpdateProjectRequest{ Id: testProjectID, @@ -491,7 +491,7 @@ func TestHandler_UpdateProject(t *testing.T) { { name: "should return not found error if project not exist", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testProjectMap[testProjectID]).Return(project.Project{}, project.ErrNotExist) + ps.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testProjectMap[testProjectID]).Return(project.Project{}, project.ErrNotExist) }, request: &shieldv1beta1.UpdateProjectRequest{ Id: testProjectID, @@ -512,7 +512,7 @@ func TestHandler_UpdateProject(t *testing.T) { { name: "should return already exist error if project service return err conflict", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testProjectMap[testProjectID]).Return(project.Project{}, project.ErrConflict) + ps.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testProjectMap[testProjectID]).Return(project.Project{}, project.ErrConflict) }, request: &shieldv1beta1.UpdateProjectRequest{ Id: testProjectID, @@ -533,7 +533,7 @@ func TestHandler_UpdateProject(t *testing.T) { { name: "should return bad request error if update by id with empty name", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), project.Project{ + ps.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), project.Project{ ID: testProjectID, Slug: testProjectMap[testProjectID].Slug, Organization: testProjectMap[testProjectID].Organization, @@ -558,7 +558,7 @@ func TestHandler_UpdateProject(t *testing.T) { { name: "should return bad request error if update by id with empty slug", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), project.Project{ + ps.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), project.Project{ ID: testProjectID, Name: testProjectMap[testProjectID].Name, Organization: testProjectMap[testProjectID].Organization, @@ -583,7 +583,7 @@ func TestHandler_UpdateProject(t *testing.T) { { name: "should return not found error if project id empty", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), project.Project{ + ps.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), project.Project{ Name: testProjectMap[testProjectID].Name, Slug: "", // consider it to update by slug and assigned empty to slug Organization: testProjectMap[testProjectID].Organization, @@ -608,7 +608,7 @@ func TestHandler_UpdateProject(t *testing.T) { { name: "should return success if project service return nil", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testProjectMap[testProjectID]).Return(testProjectMap[testProjectID], nil) + ps.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testProjectMap[testProjectID]).Return(testProjectMap[testProjectID], nil) }, request: &shieldv1beta1.UpdateProjectRequest{ Id: testProjectID, @@ -648,7 +648,7 @@ func TestHandler_UpdateProject(t *testing.T) { tt.setup(mockProjectSrv) } mockDep := Handler{projectService: mockProjectSrv} - resp, err := mockDep.UpdateProject(context.Background(), tt.request) + resp, err := mockDep.UpdateProject(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -666,7 +666,7 @@ func TestHandler_ListProjectAdmins(t *testing.T) { { name: "should return internal error if project service return some error", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().ListAdmins(mock.AnythingOfType("*context.emptyCtx"), testProjectID).Return([]user.User{}, errors.New("some error")) + ps.EXPECT().ListAdmins(mock.AnythingOfType("context.todoCtx"), testProjectID).Return([]user.User{}, errors.New("some error")) }, request: &shieldv1beta1.ListProjectAdminsRequest{ Id: testProjectID, @@ -677,7 +677,7 @@ func TestHandler_ListProjectAdmins(t *testing.T) { { name: "should return not found error if org id is not exist", setup: func(ps *mocks.ProjectService) { - ps.EXPECT().ListAdmins(mock.AnythingOfType("*context.emptyCtx"), testProjectID).Return([]user.User{}, project.ErrNotExist) + ps.EXPECT().ListAdmins(mock.AnythingOfType("context.todoCtx"), testProjectID).Return([]user.User{}, project.ErrNotExist) }, request: &shieldv1beta1.ListProjectAdminsRequest{ Id: testProjectID, @@ -692,7 +692,7 @@ func TestHandler_ListProjectAdmins(t *testing.T) { for _, u := range testUserMap { testUserList = append(testUserList, u) } - ps.EXPECT().ListAdmins(mock.AnythingOfType("*context.emptyCtx"), testProjectID).Return(testUserList, nil) + ps.EXPECT().ListAdmins(mock.AnythingOfType("context.todoCtx"), testProjectID).Return(testUserList, nil) }, request: &shieldv1beta1.ListProjectAdminsRequest{ Id: testProjectID, @@ -725,7 +725,7 @@ func TestHandler_ListProjectAdmins(t *testing.T) { tt.setup(mockProjectSrv) } mockDep := Handler{projectService: mockProjectSrv} - resp, err := mockDep.ListProjectAdmins(context.Background(), tt.request) + resp, err := mockDep.ListProjectAdmins(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) diff --git a/internal/api/v1beta1/relation_test.go b/internal/api/v1beta1/relation_test.go index 828ff2d03..c62074b7c 100644 --- a/internal/api/v1beta1/relation_test.go +++ b/internal/api/v1beta1/relation_test.go @@ -50,7 +50,7 @@ func TestHandler_ListRelations(t *testing.T) { { name: "should return internal error if relation service return some error", setup: func(rs *mocks.RelationService) { - rs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx")).Return([]relation.RelationV2{}, errors.New("some error")) + rs.EXPECT().List(mock.AnythingOfType("context.todoCtx")).Return([]relation.RelationV2{}, errors.New("some error")) }, want: nil, wantErr: grpcInternalServerError, @@ -58,7 +58,7 @@ func TestHandler_ListRelations(t *testing.T) { { name: "should return relations if relation service return nil error", setup: func(rs *mocks.RelationService) { - rs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx")).Return([]relation.RelationV2{ + rs.EXPECT().List(mock.AnythingOfType("context.todoCtx")).Return([]relation.RelationV2{ testRelationV2, }, nil) }, @@ -77,7 +77,7 @@ func TestHandler_ListRelations(t *testing.T) { tt.setup(mockRelationSrv) } mockDep := Handler{relationService: mockRelationSrv} - resp, err := mockDep.ListRelations(context.Background(), &shieldv1beta1.ListRelationsRequest{}) + resp, err := mockDep.ListRelations(context.TODO(), &shieldv1beta1.ListRelationsRequest{}) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -95,7 +95,7 @@ func TestHandler_CreateRelation(t *testing.T) { { name: "should return internal server error if resource service's CheckAuthz function returns some error", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, errors.New("some error")) @@ -114,7 +114,7 @@ func TestHandler_CreateRelation(t *testing.T) { { name: "should return permision denied error if resource service's CheckAuthz function returns false", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, nil) @@ -133,12 +133,12 @@ func TestHandler_CreateRelation(t *testing.T) { { name: "should return internal error if relation service return some error", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(true, nil) - rs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, Namespace: testRelationV2.Subject.Namespace, @@ -164,12 +164,12 @@ func TestHandler_CreateRelation(t *testing.T) { { name: "should return bad request error if field value not exist in foreign reference", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(true, nil) - rs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, Namespace: testRelationV2.Subject.Namespace, @@ -195,12 +195,12 @@ func TestHandler_CreateRelation(t *testing.T) { { name: "should return success if relation service return nil", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(true, nil) - rs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, Namespace: testRelationV2.Subject.Namespace, @@ -236,7 +236,7 @@ func TestHandler_CreateRelation(t *testing.T) { } mockDep := Handler{relationService: mockRelationSrv, resourceService: mockResourceSrv, relationAdapter: relationAdapter} - resp, err := mockDep.CreateRelation(context.Background(), tt.request) + resp, err := mockDep.CreateRelation(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -254,7 +254,7 @@ func TestHandler_GetRelation(t *testing.T) { { name: "should return internal error if relation service return some error", setup: func(rs *mocks.RelationService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testRelationV2.ID).Return(relation.RelationV2{}, errors.New("some error")) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testRelationV2.ID).Return(relation.RelationV2{}, errors.New("some error")) }, request: &shieldv1beta1.GetRelationRequest{ Id: testRelationV2.ID, @@ -265,7 +265,7 @@ func TestHandler_GetRelation(t *testing.T) { { name: "should return not found error if id is empty", setup: func(rs *mocks.RelationService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(relation.RelationV2{}, relation.ErrInvalidID) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(relation.RelationV2{}, relation.ErrInvalidID) }, request: &shieldv1beta1.GetRelationRequest{}, want: nil, @@ -274,7 +274,7 @@ func TestHandler_GetRelation(t *testing.T) { { name: "should return not found error if id is not uuid", setup: func(rs *mocks.RelationService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "some-id").Return(relation.RelationV2{}, relation.ErrInvalidUUID) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "some-id").Return(relation.RelationV2{}, relation.ErrInvalidUUID) }, request: &shieldv1beta1.GetRelationRequest{ Id: "some-id", @@ -285,7 +285,7 @@ func TestHandler_GetRelation(t *testing.T) { { name: "should return not found error if id not exist", setup: func(rs *mocks.RelationService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testRelationV2.ID).Return(relation.RelationV2{}, relation.ErrNotExist) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testRelationV2.ID).Return(relation.RelationV2{}, relation.ErrNotExist) }, request: &shieldv1beta1.GetRelationRequest{ Id: testRelationV2.ID, @@ -296,7 +296,7 @@ func TestHandler_GetRelation(t *testing.T) { { name: "should return success if relation service return nil error", setup: func(rs *mocks.RelationService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testRelationV2.ID).Return(testRelationV2, nil) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testRelationV2.ID).Return(testRelationV2, nil) }, request: &shieldv1beta1.GetRelationRequest{ Id: testRelationV2.ID, @@ -314,7 +314,7 @@ func TestHandler_GetRelation(t *testing.T) { tt.setup(mockRelationSrv) } mockDep := Handler{relationService: mockRelationSrv} - resp, err := mockDep.GetRelation(context.Background(), tt.request) + resp, err := mockDep.GetRelation(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -332,7 +332,7 @@ func TestHandler_DeleteRelation(t *testing.T) { { name: "should return internal error if relation service return some error", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - rs.EXPECT().GetRelationByFields(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().GetRelationByFields(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, RoleID: testRelationV2.Subject.RoleID, @@ -353,7 +353,7 @@ func TestHandler_DeleteRelation(t *testing.T) { { name: "should return not found error if relation does not exist", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - rs.EXPECT().GetRelationByFields(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().GetRelationByFields(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, RoleID: testRelationV2.Subject.RoleID, @@ -374,7 +374,7 @@ func TestHandler_DeleteRelation(t *testing.T) { { name: "should return internal server error if resource service's CheckAuthz returns some error", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - rs.EXPECT().GetRelationByFields(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().GetRelationByFields(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, RoleID: testRelationV2.Subject.RoleID, @@ -394,7 +394,7 @@ func TestHandler_DeleteRelation(t *testing.T) { }, }, nil) - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, errors.New("some error")) @@ -410,7 +410,7 @@ func TestHandler_DeleteRelation(t *testing.T) { { name: "should return permission denied error if resource service returns false response while checking permission", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - rs.EXPECT().GetRelationByFields(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().GetRelationByFields(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, RoleID: testRelationV2.Subject.RoleID, @@ -430,7 +430,7 @@ func TestHandler_DeleteRelation(t *testing.T) { }, }, nil) - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(false, nil) @@ -446,7 +446,7 @@ func TestHandler_DeleteRelation(t *testing.T) { { name: "should return internal server error when relation service returns some error while deletion", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - rs.EXPECT().GetRelationByFields(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().GetRelationByFields(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, RoleID: testRelationV2.Subject.RoleID, @@ -466,12 +466,12 @@ func TestHandler_DeleteRelation(t *testing.T) { }, }, nil) - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(true, nil) - rs.EXPECT().DeleteV2(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().DeleteV2(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, RoleID: testRelationV2.Subject.RoleID, @@ -494,7 +494,7 @@ func TestHandler_DeleteRelation(t *testing.T) { { name: "should successfully delete when relation exist and user has permission to edit it", setup: func(rs *mocks.RelationService, res *mocks.ResourceService) { - rs.EXPECT().GetRelationByFields(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().GetRelationByFields(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, RoleID: testRelationV2.Subject.RoleID, @@ -514,12 +514,12 @@ func TestHandler_DeleteRelation(t *testing.T) { }, }, nil) - res.EXPECT().CheckAuthz(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + res.EXPECT().CheckAuthz(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testRelationV2.Object.ID, NamespaceID: testRelationV2.Object.NamespaceID, }, action.Action{ID: schema.EditPermission}).Return(true, nil) - rs.EXPECT().DeleteV2(mock.AnythingOfType("*context.emptyCtx"), relation.RelationV2{ + rs.EXPECT().DeleteV2(mock.AnythingOfType("context.todoCtx"), relation.RelationV2{ Subject: relation.Subject{ ID: testRelationV2.Subject.ID, RoleID: testRelationV2.Subject.RoleID, @@ -548,7 +548,7 @@ func TestHandler_DeleteRelation(t *testing.T) { tt.setup(mockRelationSrv, mockResourceSrv) } mockDep := Handler{relationService: mockRelationSrv, resourceService: mockResourceSrv} - resp, err := mockDep.DeleteRelation(context.Background(), tt.request) + resp, err := mockDep.DeleteRelation(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) diff --git a/internal/api/v1beta1/resource_test.go b/internal/api/v1beta1/resource_test.go index 0fcf4cb57..2a79c2c21 100644 --- a/internal/api/v1beta1/resource_test.go +++ b/internal/api/v1beta1/resource_test.go @@ -62,7 +62,7 @@ func TestHandler_ListResources(t *testing.T) { { name: "should return internal error if resource service return some error", setup: func(rs *mocks.ResourceService) { - rs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx"), resource.Filter{}).Return(resource.PagedResources{}, errors.New("some error")) + rs.EXPECT().List(mock.AnythingOfType("context.todoCtx"), resource.Filter{}).Return(resource.PagedResources{}, errors.New("some error")) }, request: &shieldv1beta1.ListResourcesRequest{}, want: nil, @@ -72,7 +72,7 @@ func TestHandler_ListResources(t *testing.T) { name: "should return resources if resource service return nil error", setup: func(rs *mocks.ResourceService) { testResourceList := []resource.Resource{testResource} - rs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx"), resource.Filter{}).Return( + rs.EXPECT().List(mock.AnythingOfType("context.todoCtx"), resource.Filter{}).Return( resource.PagedResources{ Count: int32(len(testResourceList)), Resources: testResourceList, @@ -99,7 +99,7 @@ func TestHandler_ListResources(t *testing.T) { tt.setup(mockResourceSrv) } mockDep := Handler{resourceService: mockResourceSrv} - resp, err := mockDep.ListResources(context.Background(), tt.request) + resp, err := mockDep.ListResources(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -118,9 +118,9 @@ func TestHandler_CreateResource(t *testing.T) { { name: "should return unauthenticated error if auth email in context is empty and org service return invalid user email", setup: func(ctx context.Context, rs *mocks.ResourceService, ps *mocks.ProjectService, rls *mocks.RelationService, _ *mocks.RelationTransformer) context.Context { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.ProjectID).Return(project.Project{}, user.ErrInvalidEmail) + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.ProjectID).Return(project.Project{}, user.ErrInvalidEmail) - rs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), resource.Resource{ + rs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), resource.Resource{ Name: testResource.Name, ProjectID: testResource.ProjectID, OrganizationID: testResource.OrganizationID, @@ -289,7 +289,7 @@ func TestHandler_CreateResource(t *testing.T) { mockProjectSrv := new(mocks.ProjectService) mockRelationSrv := new(mocks.RelationService) relationAdapter := new(mocks.RelationTransformer) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { ctx = tt.setup(ctx, mockResourceSrv, mockProjectSrv, mockRelationSrv, relationAdapter) } @@ -312,7 +312,7 @@ func TestHandler_GetResource(t *testing.T) { { name: "should return internal error if resource service return some error", setup: func(rs *mocks.ResourceService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.Idxa).Return(resource.Resource{}, errors.New("some error")) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.Idxa).Return(resource.Resource{}, errors.New("some error")) }, request: &shieldv1beta1.GetResourceRequest{ Id: testResource.Idxa, @@ -323,7 +323,7 @@ func TestHandler_GetResource(t *testing.T) { { name: "should return not found error if id is empty", setup: func(rs *mocks.ResourceService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(resource.Resource{}, resource.ErrInvalidID) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(resource.Resource{}, resource.ErrInvalidID) }, request: &shieldv1beta1.GetResourceRequest{}, want: nil, @@ -332,7 +332,7 @@ func TestHandler_GetResource(t *testing.T) { { name: "should return not found error if id is not uuid", setup: func(rs *mocks.ResourceService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "some-id").Return(resource.Resource{}, resource.ErrInvalidUUID) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "some-id").Return(resource.Resource{}, resource.ErrInvalidUUID) }, request: &shieldv1beta1.GetResourceRequest{ Id: "some-id", @@ -343,7 +343,7 @@ func TestHandler_GetResource(t *testing.T) { { name: "should return not found error if id not exist", setup: func(rs *mocks.ResourceService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.Idxa).Return(resource.Resource{}, resource.ErrNotExist) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.Idxa).Return(resource.Resource{}, resource.ErrNotExist) }, request: &shieldv1beta1.GetResourceRequest{ Id: testResource.Idxa, @@ -354,7 +354,7 @@ func TestHandler_GetResource(t *testing.T) { { name: "should return success if resource service return nil error", setup: func(rs *mocks.ResourceService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.Idxa).Return(testResource, nil) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.Idxa).Return(testResource, nil) }, request: &shieldv1beta1.GetResourceRequest{ Id: testResource.Idxa, @@ -372,7 +372,7 @@ func TestHandler_GetResource(t *testing.T) { tt.setup(mockResourceSrv) } mockDep := Handler{resourceService: mockResourceSrv} - resp, err := mockDep.GetResource(context.Background(), tt.request) + resp, err := mockDep.GetResource(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -390,7 +390,7 @@ func TestHandler_UpdateResource(t *testing.T) { { name: "should return internal error if project service return some error", setup: func(rs *mocks.ResourceService, ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.ProjectID).Return(project.Project{}, errors.New("some error")) + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.ProjectID).Return(project.Project{}, errors.New("some error")) }, request: &shieldv1beta1.UpdateResourceRequest{ Id: testResourceID, @@ -406,14 +406,14 @@ func TestHandler_UpdateResource(t *testing.T) { { name: "should return internal error if resource service return some error", setup: func(rs *mocks.ResourceService, ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.ProjectID).Return(project.Project{ + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.ProjectID).Return(project.Project{ ID: testResourceID, Organization: organization.Organization{ ID: testResource.OrganizationID, }, }, nil) - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testResourceID, resource.Resource{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testResourceID, resource.Resource{ Name: testResource.Name, ProjectID: testResource.ProjectID, OrganizationID: testResource.OrganizationID, @@ -434,14 +434,14 @@ func TestHandler_UpdateResource(t *testing.T) { { name: "should return not found error if id is empty", setup: func(rs *mocks.ResourceService, ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.ProjectID).Return(project.Project{ + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.ProjectID).Return(project.Project{ ID: testResourceID, Organization: organization.Organization{ ID: testResource.OrganizationID, }, }, nil) - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), "", resource.Resource{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), "", resource.Resource{ Name: testResource.Name, ProjectID: testResource.ProjectID, NamespaceID: testResource.NamespaceID, @@ -461,14 +461,14 @@ func TestHandler_UpdateResource(t *testing.T) { { name: "should return not found error if id is not exist", setup: func(rs *mocks.ResourceService, ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.ProjectID).Return(project.Project{ + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.ProjectID).Return(project.Project{ ID: testResourceID, Organization: organization.Organization{ ID: testResource.OrganizationID, }, }, nil) - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testResourceID, resource.Resource{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testResourceID, resource.Resource{ Name: testResource.Name, ProjectID: testResource.ProjectID, OrganizationID: testResource.OrganizationID, @@ -489,14 +489,14 @@ func TestHandler_UpdateResource(t *testing.T) { { name: "should return not found error if id is not uuid", setup: func(rs *mocks.ResourceService, ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.ProjectID).Return(project.Project{ + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.ProjectID).Return(project.Project{ ID: testResourceID, Organization: organization.Organization{ ID: testResource.OrganizationID, }, }, nil) - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), "some-id", resource.Resource{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), "some-id", resource.Resource{ Name: testResource.Name, ProjectID: testResource.ProjectID, OrganizationID: testResource.OrganizationID, @@ -517,14 +517,14 @@ func TestHandler_UpdateResource(t *testing.T) { { name: "should return bad request error if field value not exist in foreign reference", setup: func(rs *mocks.ResourceService, ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.ProjectID).Return(project.Project{ + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.ProjectID).Return(project.Project{ ID: testResourceID, Organization: organization.Organization{ ID: testResource.OrganizationID, }, }, nil) - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testResourceID, resource.Resource{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testResourceID, resource.Resource{ Name: testResource.Name, ProjectID: testResource.ProjectID, OrganizationID: testResource.OrganizationID, @@ -545,14 +545,14 @@ func TestHandler_UpdateResource(t *testing.T) { { name: "should return already exist error if resource service return err conflict", setup: func(rs *mocks.ResourceService, ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.ProjectID).Return(project.Project{ + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.ProjectID).Return(project.Project{ ID: testResourceID, Organization: organization.Organization{ ID: testResource.OrganizationID, }, }, nil) - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testResourceID, resource.Resource{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testResourceID, resource.Resource{ Name: testResource.Name, ProjectID: testResource.ProjectID, OrganizationID: testResource.OrganizationID, @@ -573,14 +573,14 @@ func TestHandler_UpdateResource(t *testing.T) { { name: "should return success if resource service return nil", setup: func(rs *mocks.ResourceService, ps *mocks.ProjectService) { - ps.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testResource.ProjectID).Return(project.Project{ + ps.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testResource.ProjectID).Return(project.Project{ ID: testResourceID, Organization: organization.Organization{ ID: testResource.OrganizationID, }, }, nil) - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), testResourceID, resource.Resource{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), testResourceID, resource.Resource{ Name: testResource.Name, ProjectID: testResource.ProjectID, NamespaceID: testResource.NamespaceID, @@ -609,7 +609,7 @@ func TestHandler_UpdateResource(t *testing.T) { tt.setup(mockResourceSrv, mockProjectSrv) } mockDep := Handler{resourceService: mockResourceSrv, projectService: mockProjectSrv} - resp, err := mockDep.UpdateResource(context.Background(), tt.request) + resp, err := mockDep.UpdateResource(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) diff --git a/internal/api/v1beta1/role_test.go b/internal/api/v1beta1/role_test.go index e6a7dd3cf..bf232c3e6 100644 --- a/internal/api/v1beta1/role_test.go +++ b/internal/api/v1beta1/role_test.go @@ -46,7 +46,7 @@ func TestHandler_ListRoles(t *testing.T) { { name: "should return internal error if role service return some error", setup: func(rs *mocks.RoleService) { - rs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx")).Return([]role.Role{}, errors.New("some error")) + rs.EXPECT().List(mock.AnythingOfType("context.todoCtx")).Return([]role.Role{}, errors.New("some error")) }, want: nil, wantErr: grpcInternalServerError, @@ -58,7 +58,7 @@ func TestHandler_ListRoles(t *testing.T) { for _, rl := range testRoleMap { testRolesList = append(testRolesList, rl) } - rs.EXPECT().List(mock.AnythingOfType("*context.emptyCtx")).Return(testRolesList, nil) + rs.EXPECT().List(mock.AnythingOfType("context.todoCtx")).Return(testRolesList, nil) }, want: &shieldv1beta1.ListRolesResponse{ Roles: []*shieldv1beta1.Role{ @@ -86,7 +86,7 @@ func TestHandler_ListRoles(t *testing.T) { tt.setup(mockRoleSrv) } mockDep := Handler{roleService: mockRoleSrv} - resp, err := mockDep.ListRoles(context.Background(), tt.request) + resp, err := mockDep.ListRoles(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -104,7 +104,7 @@ func TestHandler_CreateRole(t *testing.T) { { name: "should return internal error if role service return some error", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Name: testRoleMap[testRoleID].Name, Types: testRoleMap[testRoleID].Types, @@ -131,7 +131,7 @@ func TestHandler_CreateRole(t *testing.T) { { name: "should return bad request error if namespace id not exist", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Name: testRoleMap[testRoleID].Name, Types: testRoleMap[testRoleID].Types, @@ -158,7 +158,7 @@ func TestHandler_CreateRole(t *testing.T) { { name: "should return bad request error if name empty", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Types: testRoleMap[testRoleID].Types, NamespaceID: testRoleMap[testRoleID].NamespaceID, @@ -183,7 +183,7 @@ func TestHandler_CreateRole(t *testing.T) { { name: "should return bad request error if id empty", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), role.Role{ Name: testRoleMap[testRoleID].Name, Types: testRoleMap[testRoleID].Types, NamespaceID: testRoleMap[testRoleID].NamespaceID, @@ -207,7 +207,7 @@ func TestHandler_CreateRole(t *testing.T) { { name: "should return success if role service return nil error", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Create(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Name: testRoleMap[testRoleID].Name, Types: testRoleMap[testRoleID].Types, @@ -252,7 +252,7 @@ func TestHandler_CreateRole(t *testing.T) { tt.setup(mockRoleSrv) } mockDep := Handler{roleService: mockRoleSrv} - resp, err := mockDep.CreateRole(context.Background(), tt.request) + resp, err := mockDep.CreateRole(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -270,7 +270,7 @@ func TestHandler_GetRole(t *testing.T) { { name: "should return internal error if role service return some error", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testRoleID).Return(role.Role{}, errors.New("some error")) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testRoleID).Return(role.Role{}, errors.New("some error")) }, request: &shieldv1beta1.GetRoleRequest{ Id: testRoleID, @@ -281,7 +281,7 @@ func TestHandler_GetRole(t *testing.T) { { name: "should return not found error if id not exist", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testRoleID).Return(role.Role{}, role.ErrNotExist) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testRoleID).Return(role.Role{}, role.ErrNotExist) }, request: &shieldv1beta1.GetRoleRequest{ Id: testRoleID, @@ -292,7 +292,7 @@ func TestHandler_GetRole(t *testing.T) { { name: "should return not found error if id empty", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(role.Role{}, role.ErrInvalidID) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(role.Role{}, role.ErrInvalidID) }, request: &shieldv1beta1.GetRoleRequest{}, want: nil, @@ -301,7 +301,7 @@ func TestHandler_GetRole(t *testing.T) { { name: "should return success if role service return nil error", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), testRoleID).Return(testRoleMap[testRoleID], nil) + rs.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), testRoleID).Return(testRoleMap[testRoleID], nil) }, request: &shieldv1beta1.GetRoleRequest{ Id: testRoleID, @@ -330,7 +330,7 @@ func TestHandler_GetRole(t *testing.T) { tt.setup(mockRoleSrv) } mockDep := Handler{roleService: mockRoleSrv} - resp, err := mockDep.GetRole(context.Background(), tt.request) + resp, err := mockDep.GetRole(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) @@ -348,7 +348,7 @@ func TestHandler_UpdateRole(t *testing.T) { { name: "should return internal error if role service return some error", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Name: testRoleMap[testRoleID].Name, Types: testRoleMap[testRoleID].Types, @@ -375,7 +375,7 @@ func TestHandler_UpdateRole(t *testing.T) { { name: "should return not found error if id not exist", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Name: testRoleMap[testRoleID].Name, Types: testRoleMap[testRoleID].Types, @@ -402,7 +402,7 @@ func TestHandler_UpdateRole(t *testing.T) { { name: "should return not found error if id is empty", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Name: testRoleMap[testRoleID].Name, Types: testRoleMap[testRoleID].Types, @@ -429,7 +429,7 @@ func TestHandler_UpdateRole(t *testing.T) { { name: "should return bad request error if name is empty", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Types: testRoleMap[testRoleID].Types, NamespaceID: testRoleMap[testRoleID].NamespaceID, @@ -454,7 +454,7 @@ func TestHandler_UpdateRole(t *testing.T) { { name: "should return bad request error if namespace id not exist", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Name: testRoleMap[testRoleID].Name, Types: testRoleMap[testRoleID].Types, @@ -481,7 +481,7 @@ func TestHandler_UpdateRole(t *testing.T) { { name: "should return already exist error if role service return err conflict", setup: func(rs *mocks.RoleService) { - rs.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), role.Role{ + rs.EXPECT().Update(mock.AnythingOfType("context.todoCtx"), role.Role{ ID: testRoleMap[testRoleID].ID, Name: testRoleMap[testRoleID].Name, Types: testRoleMap[testRoleID].Types, @@ -513,7 +513,7 @@ func TestHandler_UpdateRole(t *testing.T) { tt.setup(mockRoleSrv) } mockDep := Handler{roleService: mockRoleSrv} - resp, err := mockDep.UpdateRole(context.Background(), tt.request) + resp, err := mockDep.UpdateRole(context.TODO(), tt.request) assert.EqualValues(t, tt.want, resp) assert.EqualValues(t, tt.wantErr, err) }) diff --git a/internal/api/v1beta1/user_test.go b/internal/api/v1beta1/user_test.go index dd04750b6..bc11b4bb5 100644 --- a/internal/api/v1beta1/user_test.go +++ b/internal/api/v1beta1/user_test.go @@ -110,7 +110,7 @@ func TestListUsers(t *testing.T) { } mockDep := Handler{userService: mockUserSrv} req := tt.req - resp, err := mockDep.ListUsers(context.Background(), req) + resp, err := mockDep.ListUsers(context.TODO(), req) assert.EqualValues(t, resp, tt.want) assert.EqualValues(t, err, tt.err) }) @@ -277,7 +277,7 @@ func TestCreateUser(t *testing.T) { var resp *shieldv1beta1.CreateUserResponse var err error - ctx := context.Background() + ctx := context.TODO() mockUserSrv := new(mocks.UserService) if tt.setup != nil { ctx = tt.setup(ctx, mockUserSrv) @@ -302,7 +302,7 @@ func TestGetUser(t *testing.T) { { title: "should return not found error if user does not exist", setup: func(us *mocks.UserService) { - us.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), randomID).Return(user.User{}, user.ErrNotExist) + us.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), randomID).Return(user.User{}, user.ErrNotExist) }, req: &shieldv1beta1.GetUserRequest{ Id: randomID, @@ -313,7 +313,7 @@ func TestGetUser(t *testing.T) { { title: "should return not found error if user id is not uuid", setup: func(us *mocks.UserService) { - us.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "some-id").Return(user.User{}, user.ErrInvalidUUID) + us.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "some-id").Return(user.User{}, user.ErrInvalidUUID) }, req: &shieldv1beta1.GetUserRequest{ Id: "some-id", @@ -324,7 +324,7 @@ func TestGetUser(t *testing.T) { { title: "should return not found error if user id is invalid", setup: func(us *mocks.UserService) { - us.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), "").Return(user.User{}, user.ErrInvalidID) + us.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), "").Return(user.User{}, user.ErrInvalidID) }, req: &shieldv1beta1.GetUserRequest{}, want: nil, @@ -333,7 +333,7 @@ func TestGetUser(t *testing.T) { { title: "should return user if user service return nil error", setup: func(us *mocks.UserService) { - us.EXPECT().Get(mock.AnythingOfType("*context.emptyCtx"), randomID).Return( + us.EXPECT().Get(mock.AnythingOfType("context.todoCtx"), randomID).Return( user.User{ ID: randomID, Name: "some user", @@ -371,7 +371,7 @@ func TestGetUser(t *testing.T) { tt.setup(mockUserSrv) } mockDep := Handler{userService: mockUserSrv} - resp, err := mockDep.GetUser(context.Background(), tt.req) + resp, err := mockDep.GetUser(context.TODO(), tt.req) assert.EqualValues(t, resp, tt.want) assert.EqualValues(t, err, tt.err) }) @@ -445,7 +445,7 @@ func TestGetCurrentUser(t *testing.T) { for _, tt := range table { t.Run(tt.title, func(t *testing.T) { mockUserSrv := new(mocks.UserService) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { ctx = tt.setup(ctx, mockUserSrv) } @@ -470,7 +470,7 @@ func TestUpdateUser(t *testing.T) { { title: "should return internal error if user service return some error", setup: func(us *mocks.UserService) { - us.EXPECT().UpdateByID(mock.AnythingOfType("*context.emptyCtx"), user.User{ + us.EXPECT().UpdateByID(mock.AnythingOfType("context.todoCtx"), user.User{ ID: someID, Name: "abc user", Email: "user@gotocompany.com", @@ -496,7 +496,7 @@ func TestUpdateUser(t *testing.T) { { title: "should return not found error if id is invalid", setup: func(us *mocks.UserService) { - us.EXPECT().UpdateByID(mock.AnythingOfType("*context.emptyCtx"), user.User{ + us.EXPECT().UpdateByID(mock.AnythingOfType("context.todoCtx"), user.User{ Name: "abc user", Email: "user@gotocompany.com", Metadata: metadata.Metadata{ @@ -520,7 +520,7 @@ func TestUpdateUser(t *testing.T) { { title: "should return already exist error if user service return error conflict", setup: func(us *mocks.UserService) { - us.EXPECT().UpdateByID(mock.AnythingOfType("*context.emptyCtx"), user.User{ + us.EXPECT().UpdateByID(mock.AnythingOfType("context.todoCtx"), user.User{ ID: someID, Name: "abc user", Email: "user@gotocompany.com", @@ -546,7 +546,7 @@ func TestUpdateUser(t *testing.T) { { title: "should return bad request error if email in request empty", setup: func(us *mocks.UserService) { - us.EXPECT().UpdateByID(mock.AnythingOfType("*context.emptyCtx"), user.User{ + us.EXPECT().UpdateByID(mock.AnythingOfType("context.todoCtx"), user.User{ ID: someID, Name: "abc user", Metadata: metadata.Metadata{ @@ -577,7 +577,7 @@ func TestUpdateUser(t *testing.T) { { title: "should return success if user service return nil error", setup: func(us *mocks.UserService) { - us.EXPECT().UpdateByID(mock.AnythingOfType("*context.emptyCtx"), user.User{ + us.EXPECT().UpdateByID(mock.AnythingOfType("context.todoCtx"), user.User{ ID: someID, Name: "abc user", Email: "user@gotocompany.com", @@ -624,7 +624,7 @@ func TestUpdateUser(t *testing.T) { { title: "should return success even though name is empty", setup: func(us *mocks.UserService) { - us.EXPECT().UpdateByID(mock.AnythingOfType("*context.emptyCtx"), user.User{ + us.EXPECT().UpdateByID(mock.AnythingOfType("context.todoCtx"), user.User{ ID: someID, Email: "user@gotocompany.com", Metadata: metadata.Metadata{ @@ -669,7 +669,7 @@ func TestUpdateUser(t *testing.T) { for _, tt := range table { t.Run(tt.title, func(t *testing.T) { mockUserSrv := new(mocks.UserService) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { tt.setup(mockUserSrv) } @@ -823,7 +823,7 @@ func TestUpdateCurrentUser(t *testing.T) { for _, tt := range table { t.Run(tt.title, func(t *testing.T) { mockUserSrv := new(mocks.UserService) - ctx := context.Background() + ctx := context.TODO() if tt.setup != nil { ctx = tt.setup(ctx, mockUserSrv) } @@ -848,7 +848,7 @@ func TestHandler_ListUserGroups(t *testing.T) { { name: "should return internal error if group service return some error", setup: func(gs *mocks.GroupService) { - gs.EXPECT().ListUserGroups(mock.AnythingOfType("*context.emptyCtx"), someUserID, someRoleID).Return([]group.Group{}, errors.New("some error")) + gs.EXPECT().ListUserGroups(mock.AnythingOfType("context.todoCtx"), someUserID, someRoleID).Return([]group.Group{}, errors.New("some error")) }, request: &shieldv1beta1.ListUserGroupsRequest{ Id: someUserID, @@ -860,7 +860,7 @@ func TestHandler_ListUserGroups(t *testing.T) { { name: "should return empty list if user does not exist", setup: func(gs *mocks.GroupService) { - gs.EXPECT().ListUserGroups(mock.AnythingOfType("*context.emptyCtx"), someUserID, someRoleID).Return([]group.Group{}, nil) + gs.EXPECT().ListUserGroups(mock.AnythingOfType("context.todoCtx"), someUserID, someRoleID).Return([]group.Group{}, nil) }, request: &shieldv1beta1.ListUserGroupsRequest{ Id: someUserID, @@ -878,7 +878,7 @@ func TestHandler_ListUserGroups(t *testing.T) { for _, g := range testGroupMap { testGroupList = append(testGroupList, g) } - gs.EXPECT().ListUserGroups(mock.AnythingOfType("*context.emptyCtx"), someUserID, someRoleID).Return(testGroupList, nil) + gs.EXPECT().ListUserGroups(mock.AnythingOfType("context.todoCtx"), someUserID, someRoleID).Return(testGroupList, nil) }, request: &shieldv1beta1.ListUserGroupsRequest{ Id: someUserID, @@ -913,7 +913,7 @@ func TestHandler_ListUserGroups(t *testing.T) { h := Handler{ groupService: mockGroupSvc, } - got, err := h.ListUserGroups(context.Background(), tt.request) + got, err := h.ListUserGroups(context.TODO(), tt.request) assert.EqualValues(t, got, tt.want) assert.EqualValues(t, err, tt.wantErr) }) @@ -962,7 +962,7 @@ func TestCreateMetadataKey(t *testing.T) { var resp *shieldv1beta1.CreateMetadataKeyResponse var err error - ctx := context.Background() + ctx := context.TODO() mockUserSrv := new(mocks.UserService) if tt.setup != nil { ctx = tt.setup(ctx, mockUserSrv)