Skip to content

Commit

Permalink
Merge pull request #477 from uselagoon/refactor-mocks
Browse files Browse the repository at this point in the history
refactor mocks
  • Loading branch information
smlx authored Oct 15, 2024
2 parents 833f450 + 19ef890 commit a908924
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 63 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ jobs:
go-version: stable
- name: Calculate coverage
run: |
go test -v -covermode=atomic -coverprofile=cover.out.raw -coverpkg=./... ./...
# remove generated code from coverage calculation
grep -Ev 'internal/mock|_enumer.go' cover.out.raw > cover.out
go test -v -covermode=atomic -coverprofile=cover.out -coverpkg=./... ./...
- name: Generage coverage badge
uses: vladopajic/go-test-coverage@c7fe52e0f48e0fbed8c1812824c5346218443c70 # v2.10.2
with:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/dist
/cover.out
/cover.out.raw
/sbom.spdx.json
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ fuzz: mod-tidy generate

.PHONY: cover
cover: mod-tidy generate
go test -v -covermode=atomic -coverprofile=cover.out.raw -coverpkg=./... ./...
grep -Ev 'internal/mock|_enumer.go' cover.out.raw > cover.out
go test -v -covermode=atomic -coverprofile=cover.out -coverpkg=./... ./...
go tool cover -html=cover.out
2 changes: 1 addition & 1 deletion internal/lagoon/userrole.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package lagoon

//go:generate enumer -type=UserRole -sql -transform=lower
//go:generate enumer -type=UserRole -transform=lower

// UserRole is an enum of valid User roles.
type UserRole int
Expand Down
33 changes: 1 addition & 32 deletions internal/lagoon/userrole_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions internal/rbac/usercansshtoenvironment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/google/uuid"
"github.com/uselagoon/ssh-portal/internal/lagoon"
"github.com/uselagoon/ssh-portal/internal/rbac"
"github.com/uselagoon/ssh-portal/internal/rbac/mock"
"go.uber.org/mock/gomock"
)

Expand Down Expand Up @@ -336,12 +335,12 @@ func TestUserCanSSHDefaultRBAC(t *testing.T) {
// set up mocks
ctrl := gomock.NewController(tt)
defer ctrl.Finish()
kcService := mock.NewMockKeycloakService(ctrl)
kcService := NewMockKeycloakService(ctrl)
kcService.EXPECT().
UserRolesAndGroups(ctx, tc.userUUID).
Return(tc.realmRoles, tc.userGroupPaths, nil).
Times(2)
ldbService := mock.NewMockLagoonDBService(ctrl)
ldbService := NewMockLagoonDBService(ctrl)
if !tc.realmRoleShortCircuit {
kcService.EXPECT().
UserGroupIDRole(ctx, tc.userGroupPaths).
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions internal/sshserver/sessionhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/gliderlabs/ssh"
"github.com/uselagoon/ssh-portal/internal/mock"
"github.com/uselagoon/ssh-portal/internal/sshserver"
"go.uber.org/mock/gomock"
)
Expand Down Expand Up @@ -45,9 +44,9 @@ func TestExec(t *testing.T) {
t.Run(name, func(tt *testing.T) {
// set up mocks
ctrl := gomock.NewController(tt)
k8sService := mock.NewMockK8SAPIService(ctrl)
sshSession := mock.NewMockSession(ctrl)
sshContext := mock.NewMockContext(ctrl)
k8sService := NewMockK8SAPIService(ctrl)
sshSession := NewMockSession(ctrl)
sshContext := NewMockContext(ctrl)
// configure callback
callback := sshserver.SessionHandler(
log,
Expand Down Expand Up @@ -120,9 +119,9 @@ func TestLogs(t *testing.T) {
t.Run(name, func(tt *testing.T) {
// set up mocks
ctrl := gomock.NewController(tt)
k8sService := mock.NewMockK8SAPIService(ctrl)
sshSession := mock.NewMockSession(ctrl)
sshContext := mock.NewMockContext(ctrl)
k8sService := NewMockK8SAPIService(ctrl)
sshSession := NewMockSession(ctrl)
sshContext := NewMockContext(ctrl)
// configure callback
callback := sshserver.SessionHandler(
log,
Expand Down
8 changes: 4 additions & 4 deletions internal/mock/ssh.go → internal/sshserver/ssh_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a908924

Please sign in to comment.