Skip to content

Commit

Permalink
fix(gh-action): add os matrix on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gkampitakis committed Dec 25, 2021
1 parent e754507 commit 10e7d12
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ jobs:
version: "latest"
test:
name: Run tests
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
go: [1.x]
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v2
- name: Setup go
uses: actions/setup-go@v2
Expand Down
23 changes: 12 additions & 11 deletions snaps/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package snaps
import (
"errors"
"os"
"path/filepath"
"sort"
"testing"
)
Expand Down Expand Up @@ -65,19 +66,19 @@ func setupTempParseFiles(t *testing.T) (map[string]map[string]int, string, strin
data []byte
}{
{
name: dir1 + "/test1.snap",
name: filepath.FromSlash(dir1 + "/test1.snap"),
data: []byte(mockSnap1),
},
{
name: dir2 + "/test2.snap",
name: filepath.FromSlash(dir2 + "/test2.snap"),
data: []byte(mockSnap2),
},
{
name: dir1 + "/obsolete1.snap",
name: filepath.FromSlash(dir1 + "/obsolete1.snap"),
data: []byte{},
},
{
name: dir2 + "/obsolete2.snap",
name: filepath.FromSlash(dir2 + "/obsolete2.snap"),
data: []byte{},
},
}
Expand Down Expand Up @@ -120,8 +121,8 @@ func TestParseFiles(t *testing.T) {
tests, dir1, dir2 := setupTempParseFiles(t)
obsolete, used := parseFiles(tests, false)

obsoleteExpected := []string{dir1 + "/obsolete1.snap", dir2 + "/obsolete2.snap"}
usedExpected := []string{dir1 + "/test1.snap", dir2 + "/test2.snap"}
obsoleteExpected := []string{filepath.FromSlash(dir1 + "/obsolete1.snap"), filepath.FromSlash(dir2 + "/obsolete2.snap")}
usedExpected := []string{filepath.FromSlash(dir1 + "/test1.snap"), filepath.FromSlash(dir2 + "/test2.snap")}

// Parse files uses maps so order of strings cannot be guaranteed
sort.Strings(obsoleteExpected)
Expand All @@ -138,11 +139,11 @@ func TestParseFiles(t *testing.T) {
tests, dir1, dir2 := setupTempParseFiles(t)
parseFiles(tests, shouldUpdate)

if _, err := os.Stat(dir1 + "/obsolete1.snap"); !errors.Is(err, os.ErrNotExist) {
if _, err := os.Stat(filepath.FromSlash(dir1 + "/obsolete1.snap")); !errors.Is(err, os.ErrNotExist) {
t.Error("obsolete obsolete1.snap not removed")
}

if _, err := os.Stat(dir2 + "/obsolete2.snap"); !errors.Is(err, os.ErrNotExist) {
if _, err := os.Stat(filepath.FromSlash(dir2 + "/obsolete2.snap")); !errors.Is(err, os.ErrNotExist) {
t.Error("obsolete obsolete2.snap not removed")
}
})
Expand Down Expand Up @@ -170,7 +171,7 @@ func TestOccurrences(t *testing.T) {
func TestParseSnaps(t *testing.T) {
t.Run("should report no obsolete tests", func(t *testing.T) {
tests, dir1, dir2 := setupTempParseFiles(t)
used := []string{dir1 + "/test1.snap", dir2 + "/test2.snap"}
used := []string{filepath.FromSlash(dir1 + "/test1.snap"), filepath.FromSlash(dir2 + "/test2.snap")}
shouldUpdate := false

obsolete, err := parseSnaps(tests, used, shouldUpdate)
Expand All @@ -181,7 +182,7 @@ func TestParseSnaps(t *testing.T) {

t.Run("should report two obsolete tests and not change content", func(t *testing.T) {
tests, dir1, dir2 := setupTempParseFiles(t)
used := []string{dir1 + "/test1.snap", dir2 + "/test2.snap"}
used := []string{filepath.FromSlash(dir1 + "/test1.snap"), filepath.FromSlash(dir2 + "/test2.snap")}
shouldUpdate := false

// Reducing test occurrence to 1 meaning the second test was removed ( testid - 2 )
Expand All @@ -203,7 +204,7 @@ func TestParseSnaps(t *testing.T) {

t.Run("should update the obsolete snap files", func(t *testing.T) {
tests, dir1, dir2 := setupTempParseFiles(t)
used := []string{dir1 + "/test1.snap", dir2 + "/test2.snap"}
used := []string{filepath.FromSlash(dir1 + "/test1.snap"), filepath.FromSlash(dir2 + "/test2.snap")}
shouldUpdate := true

delete(tests[used[0]], "TestDir1_3/TestSimple")
Expand Down
6 changes: 3 additions & 3 deletions snaps/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Equal(t *testing.T, expected interface{}, received interface{}) {
t.Helper()

if !reflect.DeepEqual(expected, received) {
t.Error(redText(fmt.Sprintf("[expected]: %v - [received]: %v", expected, received)))
t.Error(redText(fmt.Sprintf("\n[expected]: %v\n[received]: %v", expected, received)))
}
}

Expand Down Expand Up @@ -146,7 +146,7 @@ func TestConfigMethods(t *testing.T) {
t.Run("snapPathAndFile", func(t *testing.T) {
path, file := defaultConfig.snapPathAndFile()

Equal(t, true, strings.Contains(path, "/snaps/__snapshots__"))
Equal(t, true, strings.Contains(file, "/snaps/__snapshots__/config_test.snap"))
Equal(t, true, strings.Contains(path, filepath.FromSlash("/snaps/__snapshots__")))
Equal(t, true, strings.Contains(file, filepath.FromSlash("/snaps/__snapshots__/config_test.snap")))
})
}

0 comments on commit 10e7d12

Please sign in to comment.