Skip to content

Commit 70e545a

Browse files
committed
v0.0.32: fix service name to subdomain conversion
1 parent 6573afe commit 70e545a

14 files changed

+161
-64
lines changed

cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func ReportError(ctx context.Context, drv *ui.Driver, cmd *cobra.Command, args [
212212
if stack != "" {
213213
fmt.Fprintf(&body, "**Stack:**\n```\n%s\n```\n", normalizeStack(stack))
214214
}
215-
fmt.Fprintf(&body, "**Stdout:**\n```\n%s\n```\n", strings.TrimRight(string(drv.LastView), "\n"))
215+
fmt.Fprintf(&body, "**Stdout:**\n```\n%s\n```\n", strings.TrimRight(drv.ErrorView(), "\n"))
216216
q.Add("body", body.String())
217217

218218
reportErrorConfirmCh := make(chan struct{})

cli_test.go

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,46 @@ import (
55
"errors"
66
"fmt"
77
"runtime"
8+
"strings"
89
"testing"
910
"time"
1011

1112
"github.com/anchordotdev/cli"
1213
"github.com/anchordotdev/cli/ui"
1314
"github.com/anchordotdev/cli/ui/uitest"
15+
tea "github.com/charmbracelet/bubbletea"
16+
"github.com/charmbracelet/lipgloss"
1417
"github.com/charmbracelet/x/exp/teatest"
18+
"github.com/muesli/termenv"
1519
"github.com/spf13/cobra"
1620
"github.com/stretchr/testify/require"
1721
)
1822

23+
func setupCleanup(t *testing.T) {
24+
t.Helper()
25+
26+
colorProfile := lipgloss.ColorProfile()
27+
lipgloss.SetColorProfile(termenv.TrueColor)
28+
29+
cliOS, cliArch := cli.Version.Os, cli.Version.Arch
30+
cli.Version.Os, cli.Version.Arch = "goos", "goarch"
31+
32+
t.Cleanup(func() {
33+
lipgloss.SetColorProfile(colorProfile)
34+
35+
cli.Version.Os, cli.Version.Arch = cliOS, cliArch
36+
})
37+
}
38+
39+
func testTag() string {
40+
switch runtime.GOOS {
41+
case "darwin", "linux":
42+
return "unix"
43+
default:
44+
return runtime.GOOS
45+
}
46+
}
47+
1948
var CmdError = cli.NewCmd[ErrorCommand](nil, "error", func(cmd *cobra.Command) {})
2049

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

3160
func (c *ErrorCommand) run(ctx context.Context, drv *ui.Driver) error {
61+
drv.Activate(ctx, &TestHeader{Type: "error"})
62+
drv.Activate(ctx, &TestHint{Type: "error"})
63+
3264
return testErr
3365
}
3466

3567
func TestError(t *testing.T) {
68+
setupCleanup(t)
69+
3670
ctx, cancel := context.WithCancel(context.Background())
3771
defer cancel()
3872

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

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

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

73107
func (c *PanicCommand) run(ctx context.Context, drv *ui.Driver) error {
108+
drv.Activate(ctx, &TestHeader{Type: "panic"})
109+
drv.Activate(ctx, &TestHint{Type: "panic"})
74110
panic("test panic")
75111
}
76112

77113
func TestPanic(t *testing.T) {
114+
setupCleanup(t)
115+
78116
ctx, cancel := context.WithCancel(context.Background())
79117
defer cancel()
80118

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

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

89127
drv, tm := uitest.TestTUI(ctx, t)
@@ -101,3 +139,31 @@ func TestPanic(t *testing.T) {
101139
_ = cmd.UI().RunTUI(ctx, drv)
102140
})
103141
}
142+
143+
type TestHeader struct {
144+
Type string
145+
}
146+
147+
func (m *TestHeader) Init() tea.Cmd { return nil }
148+
149+
func (m *TestHeader) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil }
150+
151+
func (m *TestHeader) View() string {
152+
var b strings.Builder
153+
fmt.Fprintln(&b, ui.Header(fmt.Sprintf("Test %s %s", m.Type, ui.Whisper(fmt.Sprintf("`anchor test %s`", m.Type)))))
154+
return b.String()
155+
}
156+
157+
type TestHint struct {
158+
Type string
159+
}
160+
161+
func (m *TestHint) Init() tea.Cmd { return nil }
162+
163+
func (m *TestHint) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil }
164+
165+
func (m *TestHint) View() string {
166+
var b strings.Builder
167+
fmt.Fprintln(&b, ui.StepHint(fmt.Sprintf("Test %s Hint.", m.Type)))
168+
return b.String()
169+
}

lcl/setup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ func (c Setup) perform(ctx context.Context, drv *ui.Driver) error {
209209
}
210210

211211
var (
212-
parameterizeUnwantedRegex = regexp.MustCompile(`[^a-z0-9\-_]+`)
212+
// unlike ActiveSupport parameterize, we also drop underscore as it is invalid in subdomains
213+
parameterizeUnwantedRegex = regexp.MustCompile(`[^a-z0-9\-]+`)
213214
parameterizeDuplicateSeparatorRegex = regexp.MustCompile(`-{2,}`)
214215
parameterizeLeadingTrailingRegex = regexp.MustCompile(`^-|-$`)
215216
)

testdata/TestError/golden-darwin_arm64.golden

Lines changed: 0 additions & 10 deletions
This file was deleted.

testdata/TestError/golden-linux_amd64.golden

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
─── TestHeader ─────────────────────────────────────────────────────────────────
2+
# Test error `anchor test error`
3+
─── TestHint ───────────────────────────────────────────────────────────────────
4+
# Test error `anchor test error`
5+
 | Test error Hint.
6+
─── ReportError ────────────────────────────────────────────────────────────────
7+
# Test error `anchor test error`
8+
 | Test error Hint.
9+
# Error! test error ``
10+
 | We are sorry you encountered this error.
11+
! Press Enter to open an issue on Github.
12+
─── Browserless ────────────────────────────────────────────────────────────────
13+
# Test error `anchor test error`
14+
 | Test error Hint.
15+
# Error! test error ``
16+
 | We are sorry you encountered this error.
17+
! Press Enter to open an issue on Github.
18+
! Warning: Unable to open browser.
19+
! 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.

0 commit comments

Comments
 (0)