Skip to content

Commit 48bac0a

Browse files
committed
Fix race in codespaces delete test
1 parent a0f11b6 commit 48bac0a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cmd/ghcs/delete_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"errors"
77
"fmt"
88
"sort"
9+
"strings"
910
"testing"
1011
"time"
1112

13+
"github.com/MakeNowJust/heredoc"
1214
"github.com/cli/cli/v2/cmd/ghcs/output"
1315
"github.com/cli/cli/v2/internal/api"
1416
)
@@ -102,7 +104,10 @@ func TestDelete(t *testing.T) {
102104
deleteErr: errors.New("aborted by test"),
103105
wantErr: true,
104106
wantDeleted: []string{"hubot-robawt-abc", "monalisa-spoonknife-123"},
105-
wantStderr: "error deleting codespace \"hubot-robawt-abc\": aborted by test\nerror deleting codespace \"monalisa-spoonknife-123\": aborted by test\n",
107+
wantStderr: heredoc.Doc(`
108+
error deleting codespace "hubot-robawt-abc": aborted by test
109+
error deleting codespace "monalisa-spoonknife-123": aborted by test
110+
`),
106111
},
107112
{
108113
name: "with confirm",
@@ -221,7 +226,7 @@ func TestDelete(t *testing.T) {
221226
if out := stdout.String(); out != tt.wantStdout {
222227
t.Errorf("stdout = %q, want %q", out, tt.wantStdout)
223228
}
224-
if out := stderr.String(); out != tt.wantStderr {
229+
if out := sortLines(stderr.String()); out != tt.wantStderr {
225230
t.Errorf("stderr = %q, want %q", out, tt.wantStderr)
226231
}
227232
})
@@ -239,3 +244,14 @@ func sliceEquals(a, b []string) bool {
239244
}
240245
return true
241246
}
247+
248+
func sortLines(s string) string {
249+
trailing := ""
250+
if strings.HasSuffix(s, "\n") {
251+
s = strings.TrimSuffix(s, "\n")
252+
trailing = "\n"
253+
}
254+
lines := strings.Split(s, "\n")
255+
sort.Strings(lines)
256+
return strings.Join(lines, "\n") + trailing
257+
}

0 commit comments

Comments
 (0)