Skip to content

Commit

Permalink
chore: update test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Dec 7, 2024
1 parent eb0e5d6 commit 91562bb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ jobs:
# Required by: internal/utils/credentials/keyring_test.go
- uses: t1m0thyj/unlock-keyring@v1
- run: |
go run gotest.tools/gotestsum -- ./... -race -v -count=1 \
-coverpkg ./cmd/...,./internal/... -coverprofile=coverage.out
go run gotest.tools/gotestsum -- -race -v -count=1 -coverprofile=coverage.out \
`go list ./... | grep -Ev 'cmd|docs|examples|pkg/api|tools'`
- uses: shogo82148/actions-goveralls@v1
- uses: coverallsapp/github-action@v2
with:
path-to-profile: coverage.out
file: coverage.out
format: golang

lint:
name: Lint
Expand Down
12 changes: 1 addition & 11 deletions internal/utils/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package utils

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/supabase/cli/v2/internal/testing/fstest"
)

Expand Down Expand Up @@ -34,15 +32,7 @@ func TestPromptYesNo(t *testing.T) {

func TestPromptText(t *testing.T) {
t.Run("defaults on timeout", func(t *testing.T) {
// Setup stdin
r, _, err := os.Pipe()
require.NoError(t, err)
// Replace stdin
oldStdin := os.Stdin
defer func() {
os.Stdin = oldStdin
}()
os.Stdin = r
t.Cleanup(fstest.MockStdin(t, ""))
c := NewConsole()
// Run test
val, err := c.PromptText(context.Background(), "test")
Expand Down
5 changes: 3 additions & 2 deletions internal/utils/flags/project_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"

tea "github.com/charmbracelet/bubbletea"
"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/spf13/viper"
Expand All @@ -26,7 +27,7 @@ func ParseProjectRef(ctx context.Context, fsys afero.Fs) error {
return errors.New(utils.ErrNotLinked)
}

func PromptProjectRef(ctx context.Context, title string) error {
func PromptProjectRef(ctx context.Context, title string, opts ...tea.ProgramOption) error {
resp, err := utils.GetSupabase().V1ListAllProjectsWithResponse(ctx)
if err != nil {
return errors.Errorf("failed to retrieve projects: %w", err)
Expand All @@ -41,7 +42,7 @@ func PromptProjectRef(ctx context.Context, title string) error {
Details: fmt.Sprintf("name: %s, org: %s, region: %s", project.Name, project.OrganizationId, project.Region),
}
}
choice, err := utils.PromptChoice(ctx, title, items)
choice, err := utils.PromptChoice(ctx, title, items, opts...)
if err != nil {
return err
}
Expand Down
7 changes: 5 additions & 2 deletions internal/utils/flags/project_ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"net/http"
"os"
"strings"
"testing"

tea "github.com/charmbracelet/bubbletea"
"github.com/go-errors/errors"
"github.com/h2non/gock"
"github.com/spf13/afero"
Expand Down Expand Up @@ -69,6 +71,7 @@ func TestProjectPrompt(t *testing.T) {
t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))

t.Run("validates prompt input", func(t *testing.T) {
input := tea.WithInput(strings.NewReader("\r"))
// Setup mock api
defer gock.OffAll()
gock.New(utils.DefaultApiHost).
Expand All @@ -80,9 +83,9 @@ func TestProjectPrompt(t *testing.T) {
OrganizationId: "test-org",
}})
// Run test
err := PromptProjectRef(context.Background(), "")
err := PromptProjectRef(context.Background(), "", input)
// Check error
assert.ErrorContains(t, err, "failed to prompt choice:")
assert.NoError(t, err)
assert.Empty(t, apitest.ListUnmatchedRequests())
})

Expand Down
4 changes: 2 additions & 2 deletions internal/utils/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (m model) View() string {
}

// Prompt user to choose from a list of items, returns the chosen index.
func PromptChoice(ctx context.Context, title string, items []PromptItem) (PromptItem, error) {
func PromptChoice(ctx context.Context, title string, items []PromptItem, opts ...tea.ProgramOption) (PromptItem, error) {
// Create list items
var listItems []list.Item
for _, v := range items {
Expand All @@ -126,7 +126,7 @@ func PromptChoice(ctx context.Context, title string, items []PromptItem) (Prompt
// Create our model
ctx, cancel := context.WithCancel(ctx)
initial := model{cancel: cancel, list: l}
prog := tea.NewProgram(initial)
prog := tea.NewProgram(initial, opts...)
state, err := prog.Run()
if err != nil {
return initial.choice, errors.Errorf("failed to prompt choice: %w", err)
Expand Down

0 comments on commit 91562bb

Please sign in to comment.