diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2021-06-15 14:08:13 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-06-15 14:38:15 +0200 |
| commit | 990d3cbe39f4c5749bf753f60d6cc24b51b8de6b (patch) | |
| tree | 4af77c357d0f5dc8fbf8dfebb40c1b9b69591e8f /pkg | |
| parent | b4f7a5d8faac53cf82d269258248044791fca58b (diff) | |
pkg/host: fix globs test
It creates a temp dir in cwd, which is not guaranteed to be writable.
Create temp dir in temp instead.
Also don't assume Linux path separator, won't work on Windows.
Also actually check the result, current test would be happy
if glob always returns empty match as well.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/host/machine_info_linux_test.go | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/pkg/host/machine_info_linux_test.go b/pkg/host/machine_info_linux_test.go index 47a565d7e..fdb3f3011 100644 --- a/pkg/host/machine_info_linux_test.go +++ b/pkg/host/machine_info_linux_test.go @@ -7,11 +7,14 @@ import ( "bufio" "bytes" "fmt" + "io/ioutil" "os" + "path/filepath" "runtime" "strings" "testing" + "github.com/google/go-cmp/cmp" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/sys/targets" ) @@ -382,32 +385,37 @@ power management: } func TestGetGlobsInfo(t *testing.T) { - if err := osutil.MkdirAll("globstest/a/b/c/d"); err != nil { + dir, err := ioutil.TempDir("", "syz-host-globstest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(dir) + if err := osutil.MkdirAll(filepath.Join(dir, "a", "b", "c", "d")); err != nil { t.Fatal(err) } - if err := osutil.MkdirAll("globstest/a/b/c/e"); err != nil { + if err := osutil.MkdirAll(filepath.Join(dir, "a", "b", "c", "e")); err != nil { t.Fatal(err) } - if err := osutil.MkdirAll("globstest/a/c/d"); err != nil { + if err := osutil.MkdirAll(filepath.Join(dir, "a", "c", "d")); err != nil { t.Fatal(err) } - if err := osutil.MkdirAll("globstest/a/c/e"); err != nil { + if err := osutil.MkdirAll(filepath.Join(dir, "a", "c", "e")); err != nil { t.Fatal(err) } - defer os.RemoveAll("globstest") + glob := filepath.Join(dir, "a/**/*") + ":-" + filepath.Join(dir, "a/c/e") globs := map[string]bool{ - "globstest/a/**/*:-globstest/a/c/e": true, + glob: true, } infos, err := getGlobsInfo(globs) if err != nil { t.Fatal(err) } - for _, files := range infos { - for _, file := range files { - if file == "globstest/a/c/e" { - t.Fatal("failed to exclude globstest/a/c/e") - } - } + want := []string{ + filepath.Join(dir, "a/b/c"), + filepath.Join(dir, "a/c/d"), + } + if diff := cmp.Diff(infos[glob], want); diff != "" { + t.Fatal(diff) } } |
