diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21ea801823..73a9b684dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,9 @@ jobs: # Required by: internal/utils/credentials/keyring_test.go - uses: t1m0thyj/unlock-keyring@v1 - run: | - go run gotest.tools/gotestsum -- -race -v -count=1 -coverprofile=coverage.out \ - `go list ./... | grep -Ev 'cmd|docs|examples|pkg/api|tools'` + pkgs=$(go list ./pkg/... | grep -Ev 'pkg/api' | paste -sd ',' -) + go run gotest.tools/gotestsum -- -race -v -count=1 ./... \ + -coverpkg="./cmd/...,./internal/...,${pkgs}" -coverprofile=coverage.out - uses: coverallsapp/github-action@v2 with: diff --git a/internal/logout/logout_test.go b/internal/logout/logout_test.go index 42f9f8ead1..943f25bed2 100644 --- a/internal/logout/logout_test.go +++ b/internal/logout/logout_test.go @@ -34,7 +34,7 @@ func TestLogoutCommand(t *testing.T) { }) t.Run("removes all Supabase CLI credentials", func(t *testing.T) { - t.Cleanup(credentials.MockInit()) + keyring.MockInit() require.NoError(t, credentials.StoreProvider.Set(utils.AccessTokenKey, token)) require.NoError(t, credentials.StoreProvider.Set("project1", "password1")) require.NoError(t, credentials.StoreProvider.Set("project2", "password2")) diff --git a/internal/utils/credentials/store_mock.go b/internal/utils/credentials/store_mock.go deleted file mode 100644 index 32715fc375..0000000000 --- a/internal/utils/credentials/store_mock.go +++ /dev/null @@ -1,68 +0,0 @@ -package credentials - -import ( - "github.com/zalando/go-keyring" -) - -type mockProvider struct { - mockStore map[string]map[string]string - mockError error -} - -// Get retrieves the password for a project from the mock store. -func (m *mockProvider) Get(project string) (string, error) { - if m.mockError != nil { - return "", m.mockError - } - if pass, ok := m.mockStore[namespace][project]; ok { - return pass, nil - } - return "", keyring.ErrNotFound -} - -// Set stores the password for a project in the mock store. -func (m *mockProvider) Set(project, password string) error { - if m.mockError != nil { - return m.mockError - } - if m.mockStore == nil { - m.mockStore = make(map[string]map[string]string) - } - if m.mockStore[namespace] == nil { - m.mockStore[namespace] = make(map[string]string) - } - m.mockStore[namespace][project] = password - return nil -} - -// Delete removes the password for a project from the mock store. -func (m *mockProvider) Delete(project string) error { - if m.mockError != nil { - return m.mockError - } - if _, ok := m.mockStore[namespace][project]; ok { - delete(m.mockStore[namespace], project) - return nil - } - return keyring.ErrNotFound -} - -// DeleteAll removes all passwords from the mock store. -func (m *mockProvider) DeleteAll() error { - if m.mockError != nil { - return m.mockError - } - delete(m.mockStore, namespace) - return nil -} - -func MockInit() func() { - oldStore := StoreProvider - teardown := func() { - StoreProvider = oldStore - } - StoreProvider = &mockProvider{ - mockStore: map[string]map[string]string{}, - } - return teardown -}