Skip to content

Commit 6c0303b

Browse files
committed
Fix Windows CI test hangs
1 parent ada6438 commit 6c0303b

5 files changed

Lines changed: 44 additions & 11 deletions

File tree

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: go mod download
2929

3030
- name: Test
31-
run: go test ./...
31+
run: go test -v -count=1 -timeout=3m ./...
3232

3333
- name: Build
3434
run: go build -o openapi-changes.exe .

cmd/loaders_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ func TestLoadCommitsFromArgs_GitRefUsesLeftRightDispatch(t *testing.T) {
308308
}
309309

310310
func TestLoadCommitsFromArgs_LocalColonPathOutsideGitRepoStaysFileComparison(t *testing.T) {
311+
if os.PathSeparator == '\\' {
312+
t.Skip("colon filenames are not portable on Windows")
313+
}
314+
311315
dir := t.TempDir()
312316
chdirForTest(t, dir)
313317

@@ -325,6 +329,10 @@ func TestLoadCommitsFromArgs_LocalColonPathOutsideGitRepoStaysFileComparison(t *
325329
}
326330

327331
func TestLoadCommitsFromArgs_RepoHistoryColonPathUsesHistoryDispatch(t *testing.T) {
332+
if os.PathSeparator == '\\' {
333+
t.Skip("colon filenames are not portable on Windows")
334+
}
335+
328336
repoDir := createGitSpecRepoForFile(t, "v1:beta.yaml")
329337
chdirForTest(t, t.TempDir())
330338

cmd/markdown_report_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"path/filepath"
78
"strings"
89
"testing"
910
"time"
@@ -273,7 +274,7 @@ func TestMarkdownReportCommand_TooManyArgs(t *testing.T) {
273274
func TestMarkdownReportCommand_LeftRightFiles(t *testing.T) {
274275
cmd := testRootCmd(GetMarkdownReportCommand(),
275276
"--no-logo", "--no-color",
276-
"--report-file", "/dev/null",
277+
"--report-file", filepath.Join(t.TempDir(), "report.md"),
277278
"../sample-specs/petstorev3-original.json",
278279
"../sample-specs/petstorev3.json",
279280
)

cmd/paths_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestAbsoluteRepoPath(t *testing.T) {
1818
})
1919

2020
t.Run("returns absolute path", func(t *testing.T) {
21-
p := "/home/user/repo"
21+
p := t.TempDir()
2222

2323
have, err := absoluteRepoPath(p)
2424
assert.NoError(t, err)

cmd/summary_test.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,32 @@ func captureStdout(t *testing.T, fn func()) string {
2828
reader, writer, err := os.Pipe()
2929
require.NoError(t, err)
3030

31+
outputCh := make(chan struct {
32+
data []byte
33+
err error
34+
}, 1)
35+
go func() {
36+
data, readErr := io.ReadAll(reader)
37+
outputCh <- struct {
38+
data []byte
39+
err error
40+
}{data: data, err: readErr}
41+
}()
42+
3143
os.Stdout = writer
3244
t.Cleanup(func() {
3345
os.Stdout = oldStdout
3446
})
3547

3648
fn()
3749

50+
os.Stdout = oldStdout
3851
require.NoError(t, writer.Close())
39-
output, err := io.ReadAll(reader)
40-
require.NoError(t, err)
52+
output := <-outputCh
53+
require.NoError(t, output.err)
4154
require.NoError(t, reader.Close())
42-
os.Stdout = oldStdout
4355

44-
return string(output)
56+
return string(output.data)
4557
}
4658

4759
func captureStderr(t *testing.T, fn func()) string {
@@ -51,20 +63,32 @@ func captureStderr(t *testing.T, fn func()) string {
5163
reader, writer, err := os.Pipe()
5264
require.NoError(t, err)
5365

66+
outputCh := make(chan struct {
67+
data []byte
68+
err error
69+
}, 1)
70+
go func() {
71+
data, readErr := io.ReadAll(reader)
72+
outputCh <- struct {
73+
data []byte
74+
err error
75+
}{data: data, err: readErr}
76+
}()
77+
5478
os.Stderr = writer
5579
t.Cleanup(func() {
5680
os.Stderr = oldStderr
5781
})
5882

5983
fn()
6084

85+
os.Stderr = oldStderr
6186
require.NoError(t, writer.Close())
62-
output, err := io.ReadAll(reader)
63-
require.NoError(t, err)
87+
output := <-outputCh
88+
require.NoError(t, output.err)
6489
require.NoError(t, reader.Close())
65-
os.Stderr = oldStderr
6690

67-
return string(output)
91+
return string(output.data)
6892
}
6993

7094
func mustMakeDoctorOnlyCommitFromSpecs(t *testing.T, hash, left, right string) *model.Commit {

0 commit comments

Comments
 (0)