Skip to content

Commit

Permalink
fix: cli tests on Windows; add tests-on-windows workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored and chavacava committed Nov 15, 2024
1 parent 74e2417 commit ce69652
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
types: [opened, edited, synchronize, reopened]

jobs:
test:
name: Test
tests-on-unix:
name: Tests on Unix
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -23,3 +23,16 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Run tests
run: go test -race -shuffle=on ./...

tests-on-windows:
name: Tests on Windows
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Run tests
run: go test -race -shuffle=on ./...
25 changes: 13 additions & 12 deletions cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

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

"github.com/mitchellh/go-homedir"
Expand All @@ -22,19 +23,19 @@ func TestXDGConfigDirIsPreferredFirst(t *testing.T) {
AppFs = afero.NewMemMapFs()
})

xdgDirPath := "/tmp-iofs/xdg/config"
homeDirPath := "/tmp-iofs/home/tester"
xdgDirPath := filepath.FromSlash("/tmp-iofs/xdg/config")
homeDirPath := filepath.FromSlash("/tmp-iofs/home/tester")
AppFs.MkdirAll(xdgDirPath, 0755)
AppFs.MkdirAll(homeDirPath, 0755)

afero.WriteFile(AppFs, xdgDirPath+"/revive.toml", []byte("\n"), 0644)
afero.WriteFile(AppFs, filepath.Join(xdgDirPath, "revive.toml"), []byte("\n"), 0644)
t.Setenv("XDG_CONFIG_HOME", xdgDirPath)

afero.WriteFile(AppFs, homeDirPath+"/revive.toml", []byte("\n"), 0644)
afero.WriteFile(AppFs, filepath.Join(homeDirPath, "revive.toml"), []byte("\n"), 0644)
t.Setenv("HOME", homeDirPath)

got := buildDefaultConfigPath()
want := xdgDirPath + "/revive.toml"
want := filepath.Join(xdgDirPath, "revive.toml")

if got != want {
t.Errorf("got %q, wanted %q", got, want)
Expand All @@ -43,14 +44,14 @@ func TestXDGConfigDirIsPreferredFirst(t *testing.T) {

func TestHomeConfigDir(t *testing.T) {
t.Cleanup(func() { AppFs = afero.NewMemMapFs() })
homeDirPath := "/tmp-iofs/home/tester"
homeDirPath := filepath.FromSlash("/tmp-iofs/home/tester")
AppFs.MkdirAll(homeDirPath, 0755)

afero.WriteFile(AppFs, homeDirPath+"/revive.toml", []byte("\n"), 0644)
afero.WriteFile(AppFs, filepath.Join(homeDirPath, "revive.toml"), []byte("\n"), 0644)
t.Setenv("HOME", homeDirPath)

got := buildDefaultConfigPath()
want := homeDirPath + "/revive.toml"
want := filepath.Join(homeDirPath, "revive.toml")

if got != want {
t.Errorf("got %q, wanted %q", got, want)
Expand All @@ -59,14 +60,14 @@ func TestHomeConfigDir(t *testing.T) {

func TestXDGConfigDir(t *testing.T) {
t.Cleanup(func() { AppFs = afero.NewMemMapFs() })
xdgDirPath := "/tmp-iofs/xdg/config"
xdgDirPath := filepath.FromSlash("/tmp-iofs/xdg/config")
AppFs.MkdirAll(xdgDirPath, 0755)

afero.WriteFile(AppFs, xdgDirPath+"/revive.toml", []byte("\n"), 0644)
afero.WriteFile(AppFs, filepath.Join(xdgDirPath, "revive.toml"), []byte("\n"), 0644)
t.Setenv("XDG_CONFIG_HOME", xdgDirPath)

got := buildDefaultConfigPath()
want := xdgDirPath + "/revive.toml"
want := filepath.Join(xdgDirPath, "revive.toml")

if got != want {
t.Errorf("got %q, wanted %q", got, want)
Expand All @@ -75,7 +76,7 @@ func TestXDGConfigDir(t *testing.T) {

func TestXDGConfigDirNoFile(t *testing.T) {
t.Cleanup(func() { AppFs = afero.NewMemMapFs() })
xdgDirPath := "/tmp-iofs/xdg/config"
xdgDirPath := filepath.FromSlash("/tmp-iofs/xdg/config")
t.Setenv("XDG_CONFIG_HOME", xdgDirPath)

got := buildDefaultConfigPath()
Expand Down

0 comments on commit ce69652

Please sign in to comment.