Skip to content

Commit df82d57

Browse files
committed
Run tests on Windows on CI
1 parent af620d8 commit df82d57

File tree

2 files changed

+96
-88
lines changed

2 files changed

+96
-88
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
env:
14-
GOPRIVATE: github.com/stealthrocket,buf.build/gen/go
14+
GOPRIVATE: github.com/dispatchrun,buf.build/gen/go
1515
GOVERSION: 1.22.0
1616

1717
jobs:
@@ -39,7 +39,10 @@ jobs:
3939
skip-pkg-cache: true
4040

4141
test:
42-
runs-on: ubuntu-latest
42+
runs-on: ${{ matrix.os }}
43+
strategy:
44+
matrix:
45+
os: [ubuntu-latest, windows-latest]
4346
permissions:
4447
id-token: write
4548
contents: read

cli/run_test.go

Lines changed: 91 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -35,93 +35,98 @@ func TestRunCommand(t *testing.T) {
3535
assert.Regexp(t, "Error: failed to load env file from .+"+path+": open non-existent\\.env: "+errMsg, buff.String())
3636
})
3737

38-
t.Run("Run with env file", func(t *testing.T) {
39-
t.Parallel()
40-
41-
envFile, err := createEnvFile(t.TempDir(), []byte("CHARACTER=rick_sanchez"))
42-
defer os.Remove(envFile)
43-
if err != nil {
44-
t.Fatalf("Failed to write env file: %v", err)
45-
}
46-
47-
buff, err := execRunCommand(&[]string{}, "run", "--env-file", envFile, "--", "printenv", "CHARACTER")
48-
if err != nil {
49-
t.Fatal(err.Error())
50-
}
51-
52-
result, found := findEnvVariableInLogs(&buff)
53-
if !found {
54-
t.Fatalf("Expected printenv in the output: %s", buff.String())
55-
}
56-
assert.Equal(t, "rick_sanchez", result, fmt.Sprintf("Expected 'printenv | rick_sanchez' in the output, got 'printenv | %s'", result))
57-
})
58-
59-
t.Run("Run with env variable", func(t *testing.T) {
60-
t.Parallel()
61-
62-
// Set environment variables
63-
envVars := []string{"CHARACTER=morty_smith"}
64-
65-
buff, err := execRunCommand(&envVars, "run", "--", "printenv", "CHARACTER")
66-
if err != nil {
67-
t.Fatal(err.Error())
68-
}
69-
70-
result, found := findEnvVariableInLogs(&buff)
71-
if !found {
72-
t.Fatalf("Expected printenv in the output: %s", buff.String())
73-
}
74-
assert.Equal(t, "morty_smith", result, fmt.Sprintf("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'", result))
75-
})
76-
77-
t.Run("Run with env variable in command line has priority over the one in the env file", func(t *testing.T) {
78-
t.Parallel()
79-
80-
envFile, err := createEnvFile(t.TempDir(), []byte("CHARACTER=rick_sanchez"))
81-
defer os.Remove(envFile)
82-
if err != nil {
83-
t.Fatalf("Failed to write env file: %v", err)
84-
}
85-
86-
// Set environment variables
87-
envVars := []string{"CHARACTER=morty_smith"}
88-
buff, err := execRunCommand(&envVars, "run", "--env-file", envFile, "--", "printenv", "CHARACTER")
89-
if err != nil {
90-
t.Fatal(err.Error())
91-
}
92-
93-
result, found := findEnvVariableInLogs(&buff)
94-
if !found {
95-
t.Fatalf("Expected printenv in the output: %s", buff.String())
96-
}
97-
assert.Equal(t, "morty_smith", result, fmt.Sprintf("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'", result))
98-
})
99-
100-
t.Run("Run with env variable in local env vars has priority over the one in the env file", func(t *testing.T) {
101-
// Do not use t.Parallel() here as we are manipulating the environment!
102-
103-
// Set environment variables
104-
os.Setenv("CHARACTER", "morty_smith")
105-
defer os.Unsetenv("CHARACTER")
106-
107-
envFile, err := createEnvFile(t.TempDir(), []byte("CHARACTER=rick_sanchez"))
108-
defer os.Remove(envFile)
109-
110-
if err != nil {
111-
t.Fatalf("Failed to write env file: %v", err)
112-
}
113-
114-
buff, err := execRunCommand(&[]string{}, "run", "--env-file", envFile, "--", "printenv", "CHARACTER")
115-
if err != nil {
116-
t.Fatal(err.Error())
117-
}
38+
if runtime.GOOS != "windows" {
39+
t.Run("Run with env file", func(t *testing.T) {
40+
t.Parallel()
41+
42+
envFile, err := createEnvFile(t.TempDir(), []byte("CHARACTER=rick_sanchez"))
43+
defer os.Remove(envFile)
44+
if err != nil {
45+
t.Fatalf("Failed to write env file: %v", err)
46+
}
47+
48+
buff, err := execRunCommand(&[]string{}, "run", "--env-file", envFile, "--", "printenv", "CHARACTER")
49+
if err != nil {
50+
t.Fatal(err.Error())
51+
}
52+
53+
result, found := findEnvVariableInLogs(&buff)
54+
if !found {
55+
t.Fatalf("Expected printenv in the output: %s", buff.String())
56+
}
57+
assert.Equal(t, "rick_sanchez", result, fmt.Sprintf("Expected 'printenv | rick_sanchez' in the output, got 'printenv | %s'", result))
58+
})
59+
}
11860

119-
result, found := findEnvVariableInLogs(&buff)
120-
if !found {
121-
t.Fatalf("Expected printenv in the output: %s\n\n", buff.String())
122-
}
123-
assert.Equal(t, "morty_smith", result, fmt.Sprintf("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'", result))
124-
})
61+
// FIXME(@chicoxyzzy): Fix tests to work on Windows
62+
if runtime.GOOS != "windows" {
63+
t.Run("Run with env variable", func(t *testing.T) {
64+
t.Parallel()
65+
66+
// Set environment variables
67+
envVars := []string{"CHARACTER=morty_smith"}
68+
69+
buff, err := execRunCommand(&envVars, "run", "--", "printenv", "CHARACTER")
70+
if err != nil {
71+
t.Fatal(err.Error())
72+
}
73+
74+
result, found := findEnvVariableInLogs(&buff)
75+
if !found {
76+
t.Fatalf("Expected printenv in the output: %s", buff.String())
77+
}
78+
assert.Equal(t, "morty_smith", result, fmt.Sprintf("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'", result))
79+
})
80+
81+
t.Run("Run with env variable in command line has priority over the one in the env file", func(t *testing.T) {
82+
t.Parallel()
83+
84+
envFile, err := createEnvFile(t.TempDir(), []byte("CHARACTER=rick_sanchez"))
85+
defer os.Remove(envFile)
86+
if err != nil {
87+
t.Fatalf("Failed to write env file: %v", err)
88+
}
89+
90+
// Set environment variables
91+
envVars := []string{"CHARACTER=morty_smith"}
92+
buff, err := execRunCommand(&envVars, "run", "--env-file", envFile, "--", "printenv", "CHARACTER")
93+
if err != nil {
94+
t.Fatal(err.Error())
95+
}
96+
97+
result, found := findEnvVariableInLogs(&buff)
98+
if !found {
99+
t.Fatalf("Expected printenv in the output: %s", buff.String())
100+
}
101+
assert.Equal(t, "morty_smith", result, fmt.Sprintf("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'", result))
102+
})
103+
104+
t.Run("Run with env variable in local env vars has priority over the one in the env file", func(t *testing.T) {
105+
// Do not use t.Parallel() here as we are manipulating the environment!
106+
107+
// Set environment variables
108+
os.Setenv("CHARACTER", "morty_smith")
109+
defer os.Unsetenv("CHARACTER")
110+
111+
envFile, err := createEnvFile(t.TempDir(), []byte("CHARACTER=rick_sanchez"))
112+
defer os.Remove(envFile)
113+
114+
if err != nil {
115+
t.Fatalf("Failed to write env file: %v", err)
116+
}
117+
118+
buff, err := execRunCommand(&[]string{}, "run", "--env-file", envFile, "--", "printenv", "CHARACTER")
119+
if err != nil {
120+
t.Fatal(err.Error())
121+
}
122+
123+
result, found := findEnvVariableInLogs(&buff)
124+
if !found {
125+
t.Fatalf("Expected printenv in the output: %s\n\n", buff.String())
126+
}
127+
assert.Equal(t, "morty_smith", result, fmt.Sprintf("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'", result))
128+
})
129+
}
125130
}
126131

127132
func execRunCommand(envVars *[]string, arg ...string) (bytes.Buffer, error) {

0 commit comments

Comments
 (0)