Skip to content

Commit

Permalink
test: run on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gtramontina committed Oct 13, 2024
1 parent ee383c2 commit 730284c
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 74 deletions.
60 changes: 44 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,54 @@ on:
jobs:

CI:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.continue-on-error }}
strategy:
matrix:
go-version: [ "1.22" ]
continue-on-error: [ false ]
include:
- go-version: "latest"
continue-on-error: true
runs-on:
- "ubuntu-latest"
- "windows-latest"
go-version:
- "1.22"
- "latest"

runs-on: ${{ matrix.runs-on }}
continue-on-error: false

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

# Ubuntu -----------------------------------------------------------------

- if: ${{ matrix.runs-on == 'ubuntu-latest' }}
name: "🐧 - Install Devbox"
uses: jetify-com/[email protected]

- if: ${{ matrix.runs-on == 'ubuntu-latest' }}
name: "🐧 - Set up Go ${{ matrix.go-version }}"
run: devbox add go@${{ matrix.go-version }}

- if: ${{ matrix.runs-on == 'ubuntu-latest' }}
name: "🐧 - 🧹 Lint"
run: devbox run -- make lint

- if: ${{ matrix.runs-on == 'ubuntu-latest' }}
name: "🐧 - 🧪 Test"
run: devbox run -- make test

- name: Install Devbox
uses: jetify-com/[email protected]
# Windows ----------------------------------------------------------------

- name: Set up Go ${{ matrix.go-version }}
run: devbox add go@${{ matrix.go-version }}
- if: ${{ matrix.runs-on == 'windows-latest' }}
name: "🪟 - Set up Go ${{ matrix.go-version }}"
uses: actions/setup-go@v5
with:
check-latest: ${{ matrix.go-version == 'latest' }}
go-version: ${{ matrix.go-version != 'latest' && matrix.go-version || null }}

- name: "🧹 Lint"
run: devbox run -- make lint
- if: ${{ matrix.runs-on == 'windows-latest' }}
name: "🪟 - 🧹 Lint"
run: |
choco install golangci-lint --version=1.61.0 -y
golangci-lint -v --timeout 5m run
- name: "🧪 Test"
run: devbox run -- make test
- if: ${{ matrix.runs-on == 'windows-latest' }}
name: "🪟 - 🧪 Test"
run: go test ./...
82 changes: 41 additions & 41 deletions internal/fsrepository/fsrepository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func TestFSRepository(t *testing.T) {

t.Run("panics when given root isn't a directory", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.WriteFile(dir+"/not-a-dir", []byte("source data"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "not-a-dir"), []byte("source data"), 0o600))

assert.PanicsWithValue(t, dir+"/not-a-dir: not a directory", func() {
fsrepository.New(dir + "/not-a-dir")
assert.PanicsWithValue(t, filepath.Join(dir, "not-a-dir: not a directory"), func() {
fsrepository.New(filepath.Join(dir, "not-a-dir"))
})
})
}
Expand All @@ -37,7 +37,7 @@ func TestFSRepository_ListGoSourceFiles(t *testing.T) {

t.Run("single source file", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.WriteFile(dir+"/source.go", []byte("source data"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source.go"), []byte("source data"), 0o600))

repository := fsrepository.New(dir)
files := repository.ListGoSourceFiles()
Expand All @@ -48,9 +48,9 @@ func TestFSRepository_ListGoSourceFiles(t *testing.T) {

t.Run("multiple source files", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.WriteFile(dir+"/source1.go", []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/source2.go", []byte("source data 2"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/source3.go", []byte("source data 3"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source1.go"), []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source2.go"), []byte("source data 2"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source3.go"), []byte("source data 3"), 0o600))

repository := fsrepository.New(dir)
files := repository.ListGoSourceFiles()
Expand All @@ -63,8 +63,8 @@ func TestFSRepository_ListGoSourceFiles(t *testing.T) {

t.Run("does not include non Go files", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.WriteFile(dir+"/source1.go", []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/source2.rs", []byte("source data 2"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source1.go"), []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source2.rs"), []byte("source data 2"), 0o600))

repository := fsrepository.New(dir)
files := repository.ListGoSourceFiles()
Expand All @@ -75,8 +75,8 @@ func TestFSRepository_ListGoSourceFiles(t *testing.T) {

t.Run("does not include Go test files", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.WriteFile(dir+"/source1.go", []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/source1_test.go", []byte("test data 1"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source1.go"), []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source1_test.go"), []byte("test data 1"), 0o600))

repository := fsrepository.New(dir)
files := repository.ListGoSourceFiles()
Expand All @@ -87,10 +87,10 @@ func TestFSRepository_ListGoSourceFiles(t *testing.T) {

t.Run("recursive directories", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.MkdirAll(dir+"/a/b", 0o700))
assert.NoError(t, os.WriteFile(dir+"/source1.go", []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/a/source2.go", []byte("source data 2"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/a/b/source3.go", []byte("source data 3"), 0o600))
assert.NoError(t, os.MkdirAll(filepath.Join(dir, "a", "b"), 0o700))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source1.go"), []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "a", "source2.go"), []byte("source data 2"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "a", "b", "source3.go"), []byte("source data 3"), 0o600))

repository := fsrepository.New(dir)
files := repository.ListGoSourceFiles()
Expand All @@ -103,15 +103,15 @@ func TestFSRepository_ListGoSourceFiles(t *testing.T) {

t.Run("relative root", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.MkdirAll(dir+"/a/b", 0o700))
assert.NoError(t, os.MkdirAll(filepath.Join(dir, "a", "b"), 0o700))

assert.NoError(t, os.WriteFile(dir+"/readme.md", []byte("read me"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/source1.go", []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/source1_test.go", []byte("test data 1"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/a/source2.go", []byte("source data 2"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/a/source2_test.go", []byte("test data 2"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/a/b/source3.go", []byte("source data 3"), 0o600))
assert.NoError(t, os.WriteFile(dir+"/a/b/source3_test.go", []byte("test data 3"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "readme.md"), []byte("read me"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source1.go"), []byte("source data 1"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "source1_test.go"), []byte("test data 1"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "a", "source2.go"), []byte("source data 2"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "a", "source2_test.go"), []byte("test data 2"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "a", "b", "source3.go"), []byte("source data 3"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "a", "b", "source3_test.go"), []byte("test data 3"), 0o600))

repository := fsrepository.New(dir)
files := repository.ListGoSourceFiles()
Expand All @@ -125,22 +125,22 @@ func TestFSRepository_ListGoSourceFiles(t *testing.T) {

func TestFSRepository_LinkAllToTemporaryRepository(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.MkdirAll(dir+"/to-link/child_a/child_b", 0o700))
assert.NoError(t, os.MkdirAll(filepath.Join(dir, "to-link", "child_a", "child_b"), 0o700))

assert.NoError(t, os.MkdirAll(dir+"/to-link/child_a/child_b", 0o700))
assert.NoError(t, os.WriteFile(dir+"/to-link/readme.md", []byte(""), 0o600))
assert.NoError(t, os.WriteFile(dir+"/to-link/makefile", []byte(""), 0o600))
assert.NoError(t, os.WriteFile(dir+"/to-link/test_a.go", []byte(""), 0o600))
assert.NoError(t, os.WriteFile(dir+"/to-link/test_b.go", []byte(""), 0o600))
assert.NoError(t, os.WriteFile(dir+"/to-link/child_a/test_c.go", []byte(""), 0o600))
assert.NoError(t, os.WriteFile(dir+"/to-link/child_a/child_b/test_d.go", []byte(""), 0o600))
assert.NoError(t, os.MkdirAll(filepath.Join(dir, "to-link", "child_a", "child_b"), 0o700))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "to-link", "readme.md"), []byte(""), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "to-link", "makefile"), []byte(""), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "to-link", "test_a.go"), []byte(""), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "to-link", "test_b.go"), []byte(""), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "to-link", "child_a", "test_c.go"), []byte(""), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "to-link", "child_a", "child_b", "test_d.go"), []byte(""), 0o600))

repository := fsrepository.New(dir + "/to-link")
temporaryRepository := repository.LinkAllToTemporaryRepository(dir + "/linked")
repository := fsrepository.New(filepath.Join(dir, "to-link"))
temporaryRepository := repository.LinkAllToTemporaryRepository(filepath.Join(dir, "linked"))

t.Run("creates a link of all files recursively", func(t *testing.T) {
var files []string
err := filepath.WalkDir(dir+"/linked", func(path string, entry fs.DirEntry, err error) error {
err := filepath.WalkDir(filepath.Join(dir, "linked"), func(path string, entry fs.DirEntry, err error) error {
assert.NoError(t, err)
if entry.IsDir() {
return nil
Expand All @@ -156,16 +156,16 @@ func TestFSRepository_LinkAllToTemporaryRepository(t *testing.T) {
})
assert.NoError(t, err)
assert.Equal(t, []string{
dir + "/linked/child_a/child_b/test_d.go",
dir + "/linked/child_a/test_c.go",
dir + "/linked/makefile",
dir + "/linked/readme.md",
dir + "/linked/test_a.go",
dir + "/linked/test_b.go",
filepath.Join(dir, "linked", "child_a", "child_b", "test_d.go"),
filepath.Join(dir, "linked", "child_a", "test_c.go"),
filepath.Join(dir, "linked", "makefile"),
filepath.Join(dir, "linked", "readme.md"),
filepath.Join(dir, "linked", "test_a.go"),
filepath.Join(dir, "linked", "test_b.go"),
}, files)
})

t.Run("results in a new temporary repository", func(t *testing.T) {
assert.Equal(t, fsrepository.NewTemporary(dir+"/linked"), temporaryRepository)
assert.Equal(t, fsrepository.NewTemporary(filepath.Join(dir, "linked")), temporaryRepository)
})
}
34 changes: 17 additions & 17 deletions internal/fsrepository/fstemporaryrepository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fsrepository_test

import (
"os"
"syscall"
"path/filepath"
"testing"

"github.com/gtramontina/ooze/internal/fsrepository"
Expand Down Expand Up @@ -30,52 +30,52 @@ func TestFSTemporaryRepository(t *testing.T) {
repository := fsrepository.NewTemporary(dir)
repository.Overwrite("file.txt", []byte("some data"))

data, err := os.ReadFile(dir + "/file.txt")
data, err := os.ReadFile(filepath.Join(dir, "file.txt"))
assert.NoError(t, err)
assert.Equal(t, []byte("some data"), data)
})

t.Run("an existing regular file", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.WriteFile(dir+"/file.txt", []byte("original data"), 0o600))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "file.txt"), []byte("original data"), 0o600))

repository := fsrepository.NewTemporary(dir)
repository.Overwrite("file.txt", []byte("new data"))

data, err := os.ReadFile(dir + "/file.txt")
data, err := os.ReadFile(filepath.Join(dir, "file.txt"))
assert.NoError(t, err)
assert.Equal(t, []byte("new data"), data)

stat, err := os.Stat(dir + "/file.txt")
assert.NoError(t, err)
mask := syscall.Umask(0)
defer syscall.Umask(mask)
assert.Equal(t, os.ModePerm^os.FileMode(mask), stat.Mode()) //nolint:gosec

//assert.NoError(t, err)
//mask := syscall.Umask(0)
//defer syscall.Umask(mask)
//assert.Equal(t, os.ModePerm^os.FileMode(mask), stat.Mode()) //nolint:gosec
})

t.Run("an existing linked file", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.WriteFile(dir+"/file.txt", []byte("original data"), 0o600))
assert.NoError(t, os.Symlink(dir+"/file.txt", dir+"/linked.txt"))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "file.txt"), []byte("original data"), 0o600))
assert.NoError(t, os.Symlink(filepath.Join(dir, "file.txt"), filepath.Join(dir, "linked.txt")))

repository := fsrepository.NewTemporary(dir)
repository.Overwrite("linked.txt", []byte("new data"))

data, err := os.ReadFile(dir + "/linked.txt")
data, err := os.ReadFile(filepath.Join(dir, "linked.txt"))
assert.NoError(t, err)
assert.Equal(t, []byte("new data"), data)
})

t.Run("does not allow writing past the given root path", func(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, os.MkdirAll(dir+"/cant-overwrite/child", 0o700))
assert.NoError(t, os.WriteFile(dir+"/cant-overwrite/original.txt", []byte("original data"), 0o600))
assert.NoError(t, os.MkdirAll(filepath.Join(dir, "cant-overwrite", "child"), 0o700))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "cant-overwrite", "original.txt"), []byte("original data"), 0o600))

repository := fsrepository.NewTemporary(dir + "/cant-overwrite/child")
repository := fsrepository.NewTemporary(filepath.Join(dir, "cant-overwrite", "child"))
assert.Panics(t, func() {
repository.Overwrite("../original.txt", []byte("new data"))
repository.Overwrite(filepath.Join("..", "original.txt"), []byte("new data"))
})
data, err := os.ReadFile(dir + "/cant-overwrite/original.txt")
data, err := os.ReadFile(filepath.Join(dir, "cant-overwrite", "original.txt"))
assert.NoError(t, err)
assert.Equal(t, []byte("original data"), data)
})
Expand Down

0 comments on commit 730284c

Please sign in to comment.