Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: skip non-applicable unit tests on Windows #651

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions internal/osutil/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
)

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

t.Run("write file with directory permission error", func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
}

tempDir := t.TempDir()
data := []byte("data")
// forbid writing to tempDir
Expand Down Expand Up @@ -80,6 +85,10 @@ func TestWriteFileWithPermission(t *testing.T) {
})

t.Run("write with directory permission error", func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
}

tempDir := t.TempDir()
data := []byte("data")
filename := filepath.Join(tempDir, "a", "file.txt")
Expand Down Expand Up @@ -124,6 +133,10 @@ func TestCopyToDir(t *testing.T) {
})

t.Run("source directory permission error", func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
}

tempDir := t.TempDir()
destDir := t.TempDir()
data := []byte("data")
Expand Down Expand Up @@ -151,6 +164,10 @@ func TestCopyToDir(t *testing.T) {
})

t.Run("source file permission error", func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
}

tempDir := t.TempDir()
destDir := t.TempDir()
data := []byte("data")
Expand All @@ -170,6 +187,10 @@ func TestCopyToDir(t *testing.T) {
})

t.Run("dest directory permission error", func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
}

tempDir := t.TempDir()
destTempDir := t.TempDir()
data := []byte("data")
Expand All @@ -189,6 +210,10 @@ func TestCopyToDir(t *testing.T) {
})

t.Run("dest directory permission error 2", func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
}

tempDir := t.TempDir()
destTempDir := t.TempDir()
data := []byte("data")
Expand All @@ -197,7 +222,7 @@ func TestCopyToDir(t *testing.T) {
if err := WriteFile(filename, data); err != nil {
t.Fatal(err)
}
// forbid dest directory operation
// forbid writing to destTempDir
if err := os.Chmod(destTempDir, 0000); err != nil {
t.Fatal(err)
}
Expand All @@ -207,7 +232,7 @@ func TestCopyToDir(t *testing.T) {
}
})

t.Run("valid file content", func(t *testing.T) {
t.Run("copy file and check content", func(t *testing.T) {
tempDir := t.TempDir()
data := []byte("data")
filename := filepath.Join(tempDir, "a", "file.txt")
Expand Down
7 changes: 7 additions & 0 deletions pkg/configutil/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package configutil
import (
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -71,6 +72,9 @@ func TestIsRegistryInsecureMissingConfig(t *testing.T) {
}

func TestIsRegistryInsecureConfigPermissionError(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
}
configDir := "./testdata"
// for restore dir
defer func(oldDir string) error {
Expand Down Expand Up @@ -121,6 +125,9 @@ func TestResolveKey(t *testing.T) {
})

t.Run("signingkeys.json without read permission", func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
}
dir.UserConfigDir = "./testdata/valid_signingkeys"
defer func() error {
// restore the permission
Expand Down