Skip to content

Commit 5516199

Browse files
authored
test: skip non-applicable unit tests on Windows (notaryproject#651)
skip some unit test cases because Windows handles file permissions differently from Unix-based systems, and therefore, using file permissions like 0000, 0600, 0644, or 0700 in tests may not work as expected on Windows. Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
1 parent 4589c83 commit 5516199

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

internal/osutil/file_test.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io/ioutil"
66
"os"
77
"path/filepath"
8+
"runtime"
89
"testing"
910
)
1011

@@ -29,6 +30,10 @@ func TestWriteFile(t *testing.T) {
2930
})
3031

3132
t.Run("write file with directory permission error", func(t *testing.T) {
33+
if runtime.GOOS == "windows" {
34+
t.Skip("skipping test on Windows")
35+
}
36+
3237
tempDir := t.TempDir()
3338
data := []byte("data")
3439
// forbid writing to tempDir
@@ -80,6 +85,10 @@ func TestWriteFileWithPermission(t *testing.T) {
8085
})
8186

8287
t.Run("write with directory permission error", func(t *testing.T) {
88+
if runtime.GOOS == "windows" {
89+
t.Skip("skipping test on Windows")
90+
}
91+
8392
tempDir := t.TempDir()
8493
data := []byte("data")
8594
filename := filepath.Join(tempDir, "a", "file.txt")
@@ -124,6 +133,10 @@ func TestCopyToDir(t *testing.T) {
124133
})
125134

126135
t.Run("source directory permission error", func(t *testing.T) {
136+
if runtime.GOOS == "windows" {
137+
t.Skip("skipping test on Windows")
138+
}
139+
127140
tempDir := t.TempDir()
128141
destDir := t.TempDir()
129142
data := []byte("data")
@@ -151,6 +164,10 @@ func TestCopyToDir(t *testing.T) {
151164
})
152165

153166
t.Run("source file permission error", func(t *testing.T) {
167+
if runtime.GOOS == "windows" {
168+
t.Skip("skipping test on Windows")
169+
}
170+
154171
tempDir := t.TempDir()
155172
destDir := t.TempDir()
156173
data := []byte("data")
@@ -170,6 +187,10 @@ func TestCopyToDir(t *testing.T) {
170187
})
171188

172189
t.Run("dest directory permission error", func(t *testing.T) {
190+
if runtime.GOOS == "windows" {
191+
t.Skip("skipping test on Windows")
192+
}
193+
173194
tempDir := t.TempDir()
174195
destTempDir := t.TempDir()
175196
data := []byte("data")
@@ -189,6 +210,10 @@ func TestCopyToDir(t *testing.T) {
189210
})
190211

191212
t.Run("dest directory permission error 2", func(t *testing.T) {
213+
if runtime.GOOS == "windows" {
214+
t.Skip("skipping test on Windows")
215+
}
216+
192217
tempDir := t.TempDir()
193218
destTempDir := t.TempDir()
194219
data := []byte("data")
@@ -197,7 +222,7 @@ func TestCopyToDir(t *testing.T) {
197222
if err := WriteFile(filename, data); err != nil {
198223
t.Fatal(err)
199224
}
200-
// forbid dest directory operation
225+
// forbid writing to destTempDir
201226
if err := os.Chmod(destTempDir, 0000); err != nil {
202227
t.Fatal(err)
203228
}
@@ -207,7 +232,7 @@ func TestCopyToDir(t *testing.T) {
207232
}
208233
})
209234

210-
t.Run("valid file content", func(t *testing.T) {
235+
t.Run("copy file and check content", func(t *testing.T) {
211236
tempDir := t.TempDir()
212237
data := []byte("data")
213238
filename := filepath.Join(tempDir, "a", "file.txt")

pkg/configutil/util_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package configutil
33
import (
44
"os"
55
"path/filepath"
6+
"runtime"
67
"strings"
78
"sync"
89
"testing"
@@ -71,6 +72,9 @@ func TestIsRegistryInsecureMissingConfig(t *testing.T) {
7172
}
7273

7374
func TestIsRegistryInsecureConfigPermissionError(t *testing.T) {
75+
if runtime.GOOS == "windows" {
76+
t.Skip("skipping test on Windows")
77+
}
7478
configDir := "./testdata"
7579
// for restore dir
7680
defer func(oldDir string) error {
@@ -121,6 +125,9 @@ func TestResolveKey(t *testing.T) {
121125
})
122126

123127
t.Run("signingkeys.json without read permission", func(t *testing.T) {
128+
if runtime.GOOS == "windows" {
129+
t.Skip("skipping test on Windows")
130+
}
124131
dir.UserConfigDir = "./testdata/valid_signingkeys"
125132
defer func() error {
126133
// restore the permission

0 commit comments

Comments
 (0)