Skip to content

Commit

Permalink
Fix test failures on Windows
Browse files Browse the repository at this point in the history
And also enable the CI build for Windows.
  • Loading branch information
bep committed Jul 14, 2022
1 parent b6e5a62 commit ff9560d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/test.yml
Expand Up @@ -8,8 +8,7 @@ jobs:
strategy:
matrix:
go-version: [1.16.x,1.17.x,1.18.x]
# TODO(bep) fix windows-latest
platform: [ubuntu-latest, macos-latest]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
Expand All @@ -25,10 +24,10 @@ jobs:
shell: bash
- name: Checkout code
uses: actions/checkout@v1
#- name: Fmt
# if: matrix.platform != 'windows-latest' # :(
# run: "diff <(gofmt -d .) <(printf '')"
# shell: bash
- name: Fmt
if: matrix.platform != 'windows-latest' # :(
run: "diff <(gofmt -d .) <(printf '')"
shell: bash
- name: Vet
run: go vet ./...
#- name: Staticcheck
Expand Down
13 changes: 7 additions & 6 deletions iofs_test.go
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"io/fs"
"os"
"path/filepath"
"testing"
"testing/fstest"
"time"
Expand All @@ -20,39 +21,39 @@ func TestIOFS(t *testing.T) {
t.Run("use MemMapFs", func(t *testing.T) {
mmfs := NewMemMapFs()

err := mmfs.MkdirAll("dir1/dir2", os.ModePerm)
err := mmfs.MkdirAll(filepath.FromSlash("dir1/dir2"), os.ModePerm)
if err != nil {
t.Fatal("MkdirAll failed:", err)
}

f, err := mmfs.OpenFile("dir1/dir2/test.txt", os.O_RDWR|os.O_CREATE, os.ModePerm)
f, err := mmfs.OpenFile(filepath.FromSlash("dir1/dir2/test.txt"), os.O_RDWR|os.O_CREATE, os.ModePerm)
if err != nil {
t.Fatal("OpenFile (O_CREATE) failed:", err)
}

f.Close()

if err := fstest.TestFS(NewIOFS(mmfs), "dir1/dir2/test.txt"); err != nil {
if err := fstest.TestFS(NewIOFS(mmfs), filepath.FromSlash("dir1/dir2/test.txt")); err != nil {
t.Error(err)
}
})

t.Run("use OsFs", func(t *testing.T) {
osfs := NewBasePathFs(NewOsFs(), t.TempDir())

err := osfs.MkdirAll("dir1/dir2", os.ModePerm)
err := osfs.MkdirAll(filepath.FromSlash("dir1/dir2"), os.ModePerm)
if err != nil {
t.Fatal("MkdirAll failed:", err)
}

f, err := osfs.OpenFile("dir1/dir2/test.txt", os.O_RDWR|os.O_CREATE, os.ModePerm)
f, err := osfs.OpenFile(filepath.FromSlash("dir1/dir2/test.txt"), os.O_RDWR|os.O_CREATE, os.ModePerm)
if err != nil {
t.Fatal("OpenFile (O_CREATE) failed:", err)
}

f.Close()

if err := fstest.TestFS(NewIOFS(osfs), "dir1/dir2/test.txt"); err != nil {
if err := fstest.TestFS(NewIOFS(osfs), filepath.FromSlash("dir1/dir2/test.txt")); err != nil {
t.Error(err)
}
})
Expand Down

0 comments on commit ff9560d

Please sign in to comment.