Skip to content

Commit

Permalink
v0.0.32: fix service name to subdomain conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
benburkert committed May 6, 2024
1 parent 6573afe commit 70e545a
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 64 deletions.
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func ReportError(ctx context.Context, drv *ui.Driver, cmd *cobra.Command, args [
if stack != "" {
fmt.Fprintf(&body, "**Stack:**\n```\n%s\n```\n", normalizeStack(stack))
}
fmt.Fprintf(&body, "**Stdout:**\n```\n%s\n```\n", strings.TrimRight(string(drv.LastView), "\n"))
fmt.Fprintf(&body, "**Stdout:**\n```\n%s\n```\n", strings.TrimRight(drv.ErrorView(), "\n"))
q.Add("body", body.String())

reportErrorConfirmCh := make(chan struct{})
Expand Down
70 changes: 68 additions & 2 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,46 @@ import (
"errors"
"fmt"
"runtime"
"strings"
"testing"
"time"

"github.com/anchordotdev/cli"
"github.com/anchordotdev/cli/ui"
"github.com/anchordotdev/cli/ui/uitest"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/exp/teatest"
"github.com/muesli/termenv"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
)

func setupCleanup(t *testing.T) {
t.Helper()

colorProfile := lipgloss.ColorProfile()
lipgloss.SetColorProfile(termenv.TrueColor)

cliOS, cliArch := cli.Version.Os, cli.Version.Arch
cli.Version.Os, cli.Version.Arch = "goos", "goarch"

t.Cleanup(func() {
lipgloss.SetColorProfile(colorProfile)

cli.Version.Os, cli.Version.Arch = cliOS, cliArch
})
}

func testTag() string {
switch runtime.GOOS {
case "darwin", "linux":
return "unix"
default:
return runtime.GOOS
}
}

var CmdError = cli.NewCmd[ErrorCommand](nil, "error", func(cmd *cobra.Command) {})

type ErrorCommand struct{}
Expand All @@ -29,10 +58,15 @@ func (c ErrorCommand) UI() cli.UI {
var testErr = errors.New("test error")

func (c *ErrorCommand) run(ctx context.Context, drv *ui.Driver) error {
drv.Activate(ctx, &TestHeader{Type: "error"})
drv.Activate(ctx, &TestHint{Type: "error"})

return testErr
}

func TestError(t *testing.T) {
setupCleanup(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand All @@ -41,7 +75,7 @@ func TestError(t *testing.T) {
cfg.Test.Browserless = true
ctx = cli.ContextWithConfig(ctx, &cfg)

t.Run(fmt.Sprintf("golden-%s_%s", runtime.GOOS, runtime.GOARCH), func(t *testing.T) {
t.Run(fmt.Sprintf("golden-%s", testTag()), func(t *testing.T) {
var returnedError error

drv, tm := uitest.TestTUI(ctx, t)
Expand Down Expand Up @@ -71,10 +105,14 @@ func (c PanicCommand) UI() cli.UI {
}

func (c *PanicCommand) run(ctx context.Context, drv *ui.Driver) error {
drv.Activate(ctx, &TestHeader{Type: "panic"})
drv.Activate(ctx, &TestHint{Type: "panic"})
panic("test panic")
}

func TestPanic(t *testing.T) {
setupCleanup(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand All @@ -83,7 +121,7 @@ func TestPanic(t *testing.T) {
cfg.Test.Browserless = true
ctx = cli.ContextWithConfig(ctx, &cfg)

t.Run(fmt.Sprintf("golden-%s_%s", runtime.GOOS, runtime.GOARCH), func(t *testing.T) {
t.Run(fmt.Sprintf("golden-%s", testTag()), func(t *testing.T) {
var returnedError error

drv, tm := uitest.TestTUI(ctx, t)
Expand All @@ -101,3 +139,31 @@ func TestPanic(t *testing.T) {
_ = cmd.UI().RunTUI(ctx, drv)
})
}

type TestHeader struct {
Type string
}

func (m *TestHeader) Init() tea.Cmd { return nil }

func (m *TestHeader) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil }

func (m *TestHeader) View() string {
var b strings.Builder
fmt.Fprintln(&b, ui.Header(fmt.Sprintf("Test %s %s", m.Type, ui.Whisper(fmt.Sprintf("`anchor test %s`", m.Type)))))
return b.String()
}

type TestHint struct {
Type string
}

func (m *TestHint) Init() tea.Cmd { return nil }

func (m *TestHint) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil }

func (m *TestHint) View() string {
var b strings.Builder
fmt.Fprintln(&b, ui.StepHint(fmt.Sprintf("Test %s Hint.", m.Type)))
return b.String()
}
3 changes: 2 additions & 1 deletion lcl/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ func (c Setup) perform(ctx context.Context, drv *ui.Driver) error {
}

var (
parameterizeUnwantedRegex = regexp.MustCompile(`[^a-z0-9\-_]+`)
// unlike ActiveSupport parameterize, we also drop underscore as it is invalid in subdomains
parameterizeUnwantedRegex = regexp.MustCompile(`[^a-z0-9\-]+`)
parameterizeDuplicateSeparatorRegex = regexp.MustCompile(`-{2,}`)
parameterizeLeadingTrailingRegex = regexp.MustCompile(`^-|-$`)
)
Expand Down
10 changes: 0 additions & 10 deletions testdata/TestError/golden-darwin_arm64.golden

This file was deleted.

10 changes: 0 additions & 10 deletions testdata/TestError/golden-linux_amd64.golden

This file was deleted.

19 changes: 19 additions & 0 deletions testdata/TestError/golden-unix.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
─── TestHeader ─────────────────────────────────────────────────────────────────
# Test error `anchor test error`
─── TestHint ───────────────────────────────────────────────────────────────────
# Test error `anchor test error`
 | Test error Hint.
─── ReportError ────────────────────────────────────────────────────────────────
# Test error `anchor test error`
 | Test error Hint.
# Error! test error ``
 | We are sorry you encountered this error.
! Press Enter to open an issue on Github.
─── Browserless ────────────────────────────────────────────────────────────────
# Test error `anchor test error`
 | Test error Hint.
# Error! test error ``
 | We are sorry you encountered this error.
! Press Enter to open an issue on Github.
! Warning: Unable to open browser.
! Open this in a browser to continue: https://github.com/anchordotdev/cli/issues/new?body=%2A%2AAre+there+any+additional+details+you+would+like+to+share%3F%2A%2A%0A%0A---%0A%0A%2A%2ACommand%3A%2A%2A+%60%60%0A%2A%2AVersion%3A%2A%2A+%60dev+%28goos%2Fgoarch%29+Commit%3A+none+BuildDate%3A+unknown%60%0A%2A%2AArguments%3A%2A%2A+%60%5B%5D%60%0A%2A%2AFlags%3A%2A%2A+%60%5B%5D%60%0A%2A%2AStdout%3A%2A%2A%0A%60%60%60%0A%23+Test+error+%60anchor+test+error%60%0A++++%7C+Test+error+Hint.%0A%60%60%60%0A&title=Error%3A+test+error.
Loading

0 comments on commit 70e545a

Please sign in to comment.