Skip to content

Commit

Permalink
fix: flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Apr 29, 2024
1 parent c4ff893 commit eff8924
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/app/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type testLogger struct {
func (l *testLogger) Write(b []byte) (int, error) {
l.t.Helper()

l.t.Log(string(b))
//l.t.Log(string(b))
return len(b), nil
}

Expand Down
11 changes: 11 additions & 0 deletions internal/app/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app

import (
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
)

func init() {
// Disable color in tests (see https://charm.sh/blog/teatest/)
lipgloss.SetColorProfile(termenv.Ascii)
}
6 changes: 3 additions & 3 deletions internal/app/module_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func TestModuleList(t *testing.T) {
"modules/c",
}
waitFor(t, tm, func(s string) bool {
t.Log(s)
for _, w := range want {
if !strings.Contains(s, w) {
return false
Expand Down Expand Up @@ -52,8 +51,9 @@ func TestModuleList(t *testing.T) {
tm.Type("p")
// Expect all 3 modules to be in planned state
waitFor(t, tm, func(s string) bool {
t.Log(s)
return matchPattern(t, `(?s)(planned.*)[3]`, s)
return matchPattern(t, `modules/a.*default.*planned`, s) &&
matchPattern(t, `modules/b.*default.*planned`, s) &&
matchPattern(t, `modules/c.*default.*planned`, s)
})

// Select all modules and apply
Expand Down
3 changes: 2 additions & 1 deletion internal/app/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

tea "github.com/charmbracelet/bubbletea"
"github.com/leg100/pug/internal"
)

func TestModule(t *testing.T) {
Expand Down Expand Up @@ -88,7 +89,6 @@ func TestModule_ReloadWorkspaces(t *testing.T) {

// Expect message to inform user that reload has finished.
waitFor(t, tm, func(s string) bool {
t.Log(s)
return strings.Contains(s, "completed reload-workspaces task successfully")
})
}
Expand Down Expand Up @@ -122,6 +122,7 @@ func TestModule_Destroy(t *testing.T) {

// Expect umpteen resources to be proposed for deletion
waitFor(t, tm, func(s string) bool {
s = internal.StripAnsi(s)
return strings.Contains(s, "+0~0-10")
})
}
5 changes: 4 additions & 1 deletion internal/app/workspace_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ func TestWorkspaceList_ApplyCurrentRun(t *testing.T) {

// Expect all four workspaces' current run to enter the applied state
waitFor(t, tm, func(s string) bool {
return matchPattern(t, `(?s)default.*applied.*dev.*applied.*default.*applied.*default.*applied`, s)
return matchPattern(t, `modules/a.*default.*applied`, s) &&
matchPattern(t, `modules/a.*dev.*applied`, s) &&
matchPattern(t, `modules/b.*default.*applied`, s) &&
matchPattern(t, `modules/c.*default.*applied`, s)
})
}
4 changes: 2 additions & 2 deletions internal/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestTask_stdout(t *testing.T) {
f := factory{
counter: internal.Int(0),
program: "../testdata/task",
program: "./testdata/task",
publisher: &fakePublisher[*Task]{},
}
task, err := f.newTask(CreateOptions{})
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestTask_stdout(t *testing.T) {
func TestTask_cancel(t *testing.T) {
f := factory{
counter: internal.Int(0),
program: "../testdata/killme",
program: "./testdata/killme",
publisher: &fakePublisher[*Task]{},
}
task, err := f.newTask(CreateOptions{})
Expand Down
File renamed without changes.
File renamed without changes.
Empty file removed internal/testdata/afile
Empty file.

0 comments on commit eff8924

Please sign in to comment.