Skip to content

Commit

Permalink
chore: refactor mocks to remove internal/mock package
Browse files Browse the repository at this point in the history
This change simplifies mocks and coverage generation.
  • Loading branch information
smlx committed Oct 15, 2024
1 parent 833f450 commit 9b0e474
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 30 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

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 9b0e474

Please sign in to comment.