diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3a29459..44f6f2c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -48,4 +48,4 @@ jobs: with: go-version: 1.21.x - name: Run Tests - run: make test-verbose + run: make test diff --git a/internal/test/test.go b/internal/test/test.go index 247dc61..1e4016d 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -17,37 +17,96 @@ type MockTestingT struct { MockError func(...any) MockLog func(...any) MockCleanup func(func()) + t *testing.T +} + +// NewMockTestingT returns a MockTestingT with common default values +func NewMockTestingT(t *testing.T) MockTestingT { + return MockTestingT{ + MockHelper: func() {}, + MockCleanup: func(f func()) { + f() + }, + MockName: func() string { + return "mock-name" + }, + t: t, + } } func (m MockTestingT) Error(args ...any) { + m.t.Helper() + + if m.MockError == nil { + m.t.Errorf("t.Error was not expected to be called") + return + } m.MockError(args...) } func (m MockTestingT) Helper() { + m.t.Helper() + m.MockHelper() } func (m MockTestingT) Skip(args ...any) { + m.t.Helper() + + if m.MockSkip == nil { + m.t.Errorf("t.Skip was not expected to be called") + return + } m.MockSkip(args...) } func (m MockTestingT) Skipf(format string, args ...any) { + m.t.Helper() + + if m.MockSkipf == nil { + m.t.Errorf("t.Skipf was not expected to be called") + return + } m.MockSkipf(format, args...) } func (m MockTestingT) SkipNow() { + m.t.Helper() + + if m.MockSkipNow == nil { + m.t.Errorf("t.SkipNow was not expected to be called") + return + } m.MockSkipNow() } func (m MockTestingT) Name() string { + m.t.Helper() + + if m.MockName == nil { + m.t.Errorf("t.Name was not expected to be called") + return "" + } return m.MockName() } func (m MockTestingT) Log(args ...any) { + m.t.Helper() + + if m.MockLog == nil { + m.t.Errorf("t.Log was not expected to be called") + return + } m.MockLog(args...) } func (m MockTestingT) Cleanup(f func()) { + m.t.Helper() + + if m.MockCleanup == nil { + m.t.Errorf("t.Cleanup was not expected to be called") + return + } m.MockCleanup(f) } @@ -67,12 +126,6 @@ func Contains(t *testing.T, s, substr string) { } } -// NotCalled is going to mark a test as failed if called -func NotCalled(t *testing.T) { - t.Helper() - t.Errorf("function was not expected to be called") -} - func CreateTempFile(t *testing.T, data string) string { dir := t.TempDir() path := filepath.Join(dir, "mock.file") diff --git a/snaps/matchJSON.go b/snaps/matchJSON.go index 90cf8e3..db07b94 100644 --- a/snaps/matchJSON.go +++ b/snaps/matchJSON.go @@ -64,7 +64,7 @@ func matchJSON(c *config, t testingT, input any, matchers ...match.JSONMatcher) t.Helper() snapPath, snapPathRel := snapshotPath(c) - testID := testsRegistry.getTestID(t.Name(), snapPath) + testID := testsRegistry.getTestID(snapPath, t.Name()) j, err := validateJSON(input) if err != nil { diff --git a/snaps/matchJSON_test.go b/snaps/matchJSON_test.go index 37add14..53d4cc6 100644 --- a/snaps/matchJSON_test.go +++ b/snaps/matchJSON_test.go @@ -48,16 +48,8 @@ func TestMatchJSON(t *testing.T) { t.Run(tc.name, func(t *testing.T) { snapPath := setupSnapshot(t, jsonFilename, false) - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.NotCalled(t) - }, - MockLog: func(args ...any) { test.Equal(t, addedMsg, args[0].(string)) }, - } + mockT := test.NewMockTestingT(t) + mockT.MockLog = func(args ...any) { test.Equal(t, addedMsg, args[0].(string)) } MatchJSON(mockT, tc.input) @@ -96,18 +88,9 @@ func TestMatchJSON(t *testing.T) { t.Run(tc.name, func(t *testing.T) { setupSnapshot(t, jsonFilename, false) - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.Equal(t, tc.err, (args[0].(error)).Error()) - }, - MockLog: func(args ...any) { - // this is called when snapshot is written successfully - test.NotCalled(t) - }, + mockT := test.NewMockTestingT(t) + mockT.MockError = func(args ...any) { + test.Equal(t, tc.err, (args[0].(error)).Error()) } MatchJSON(mockT, tc.input) @@ -119,16 +102,8 @@ func TestMatchJSON(t *testing.T) { t.Run("should apply matchers in order", func(t *testing.T) { setupSnapshot(t, jsonFilename, false) - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.NotCalled(t) - }, - MockLog: func(args ...any) { test.Equal(t, addedMsg, args[0].(string)) }, - } + mockT := test.NewMockTestingT(t) + mockT.MockLog = func(args ...any) { test.Equal(t, addedMsg, args[0].(string)) } c1 := func(val any) (any, error) { return map[string]any{"key2": nil}, nil @@ -152,20 +127,14 @@ func TestMatchJSON(t *testing.T) { t.Run("should aggregate errors from matchers", func(t *testing.T) { setupSnapshot(t, jsonFilename, false) - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.Equal(t, - "\x1b[31;1m\n✕ match.Custom(\"age\") - mock error"+ - "\x1b[0m\x1b[31;1m\n✕ match.Any(\"missing.key.1\") - path does not exist"+ - "\x1b[0m\x1b[31;1m\n✕ match.Any(\"missing.key.2\") - path does not exist\x1b[0m", - args[0], - ) - }, - MockLog: func(args ...any) { test.NotCalled(t) }, + mockT := test.NewMockTestingT(t) + mockT.MockError = func(args ...any) { + test.Equal(t, + "\x1b[31;1m\n✕ match.Custom(\"age\") - mock error"+ + "\x1b[0m\x1b[31;1m\n✕ match.Any(\"missing.key.1\") - path does not exist"+ + "\x1b[0m\x1b[31;1m\n✕ match.Any(\"missing.key.2\") - path does not exist\x1b[0m", + args[0], + ) } c := func(val any) (any, error) { @@ -183,17 +152,9 @@ func TestMatchJSON(t *testing.T) { t.Run("if it's running on ci should skip creating snapshot", func(t *testing.T) { setupSnapshot(t, jsonFilename, true) - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.Equal(t, errSnapNotFound, args[0].(error)) - }, - MockLog: func(args ...any) { - test.NotCalled(t) - }, + mockT := test.NewMockTestingT(t) + mockT.MockError = func(args ...any) { + test.Equal(t, errSnapNotFound, args[0].(error)) } MatchJSON(mockT, "{}") @@ -208,20 +169,12 @@ func TestMatchJSON(t *testing.T) { func(received any) { test.Equal(t, addedMsg, received.(string)) }, func(received any) { test.Equal(t, updatedMsg, received.(string)) }, } - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.NotCalled(t) - }, - MockLog: func(args ...any) { - printerExpectedCalls[0](args[0]) + mockT := test.NewMockTestingT(t) + mockT.MockLog = func(args ...any) { + printerExpectedCalls[0](args[0]) - // shift - printerExpectedCalls = printerExpectedCalls[1:] - }, + // shift + printerExpectedCalls = printerExpectedCalls[1:] } // First call for creating the snapshot diff --git a/snaps/matchSnapshot.go b/snaps/matchSnapshot.go index 3d5b6bf..a410d8c 100644 --- a/snaps/matchSnapshot.go +++ b/snaps/matchSnapshot.go @@ -55,7 +55,7 @@ func matchSnapshot(c *config, t testingT, values ...any) { } snapPath, snapPathRel := snapshotPath(c) - testID := testsRegistry.getTestID(t.Name(), snapPath) + testID := testsRegistry.getTestID(snapPath, t.Name()) snapshot := takeSnapshot(values) prevSnapshot, line, err := getPrevSnapshot(testID, snapPath) if errors.Is(err, errSnapNotFound) { diff --git a/snaps/matchSnapshot_test.go b/snaps/matchSnapshot_test.go index bcc8cde..4877a69 100644 --- a/snaps/matchSnapshot_test.go +++ b/snaps/matchSnapshot_test.go @@ -62,17 +62,8 @@ func setupSnapshot(t *testing.T, file string, ci bool, update ...bool) string { func TestMatchSnapshot(t *testing.T) { t.Run("should create snapshot", func(t *testing.T) { snapPath := setupSnapshot(t, fileName, false) - - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.NotCalled(t) - }, - MockLog: func(args ...any) { test.Equal(t, addedMsg, args[0].(string)) }, - } + mockT := test.NewMockTestingT(t) + mockT.MockLog = func(args ...any) { test.Equal(t, addedMsg, args[0].(string)) } MatchSnapshot(mockT, 10, "hello world") @@ -87,17 +78,9 @@ func TestMatchSnapshot(t *testing.T) { t.Run("if it's running on ci should skip", func(t *testing.T) { setupSnapshot(t, fileName, true) - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.Equal(t, errSnapNotFound, args[0].(error)) - }, - MockLog: func(args ...any) { - test.NotCalled(t) - }, + mockT := test.NewMockTestingT(t) + mockT.MockError = func(args ...any) { + test.Equal(t, errSnapNotFound, args[0].(error)) } MatchSnapshot(mockT, 10, "hello world") @@ -110,30 +93,25 @@ func TestMatchSnapshot(t *testing.T) { printerExpectedCalls := []func(received any){ func(received any) { test.Equal(t, addedMsg, received.(string)) }, - func(received any) { test.NotCalled(t) }, + func(received any) { t.Error("should not be called 2nd time") }, } - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - expected := "\n\x1b[38;5;52m\x1b[48;5;225m- Snapshot - 2\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + - "+ Received + 2\x1b[0m\n\n\x1b[38;5;52m\x1b[48;5;225m- int(10)\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m" + - "- hello world\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m+ int(100)\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + - "+ bye world\x1b[0m\n\n\x1b[2mat " + filepath.FromSlash( - "../__snapshots__/matchSnapshot_test.snap:2", - ) + - "\n\x1b[0m" - - test.Equal(t, expected, args[0].(string)) - }, - MockLog: func(args ...any) { - printerExpectedCalls[0](args[0]) + mockT := test.NewMockTestingT(t) + mockT.MockError = func(args ...any) { + expected := "\n\x1b[38;5;52m\x1b[48;5;225m- Snapshot - 2\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + + "+ Received + 2\x1b[0m\n\n\x1b[38;5;52m\x1b[48;5;225m- int(10)\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m" + + "- hello world\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m+ int(100)\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + + "+ bye world\x1b[0m\n\n\x1b[2mat " + filepath.FromSlash( + "../__snapshots__/matchSnapshot_test.snap:2", + ) + + "\n\x1b[0m" + + test.Equal(t, expected, args[0].(string)) + } + mockT.MockLog = func(args ...any) { + printerExpectedCalls[0](args[0]) - // shift - printerExpectedCalls = printerExpectedCalls[1:] - }, + // shift + printerExpectedCalls = printerExpectedCalls[1:] } // First call for creating the snapshot @@ -155,21 +133,14 @@ func TestMatchSnapshot(t *testing.T) { printerExpectedCalls := []func(received any){ func(received any) { test.Equal(t, addedMsg, received.(string)) }, func(received any) { test.Equal(t, updatedMsg, received.(string)) }, + func(received any) { t.Error("should not be called 3rd time") }, } - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.NotCalled(t) - }, - MockLog: func(args ...any) { - printerExpectedCalls[0](args[0]) - - // shift - printerExpectedCalls = printerExpectedCalls[1:] - }, + mockT := test.NewMockTestingT(t) + mockT.MockLog = func(args ...any) { + printerExpectedCalls[0](args[0]) + + // shift + printerExpectedCalls = printerExpectedCalls[1:] } // First call for creating the snapshot @@ -196,21 +167,14 @@ func TestMatchSnapshot(t *testing.T) { printerExpectedCalls := []func(received any){ func(received any) { test.Equal(t, addedMsg, received.(string)) }, func(received any) { test.Equal(t, updatedMsg, received.(string)) }, + func(received any) { t.Error("should not be called 3rd time") }, } - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - test.NotCalled(t) - }, - MockLog: func(args ...any) { - printerExpectedCalls[0](args[0]) - - // shift - printerExpectedCalls = printerExpectedCalls[1:] - }, + mockT := test.NewMockTestingT(t) + mockT.MockLog = func(args ...any) { + printerExpectedCalls[0](args[0]) + + // shift + printerExpectedCalls = printerExpectedCalls[1:] } s := WithConfig(Update(true)) @@ -234,15 +198,13 @@ func TestMatchSnapshot(t *testing.T) { }) t.Run("should print warning if no params provided", func(t *testing.T) { - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockLog: func(args ...any) { - test.Equal( - t, - colors.Sprint(colors.Yellow, "[warning] MatchSnapshot call without params\n"), - args[0].(string), - ) - }, + mockT := test.NewMockTestingT(t) + mockT.MockLog = func(args ...any) { + test.Equal( + t, + colors.Sprint(colors.Yellow, "[warning] MatchSnapshot call without params\n"), + args[0].(string), + ) } MatchSnapshot(mockT) @@ -253,31 +215,26 @@ func TestMatchSnapshot(t *testing.T) { printerExpectedCalls := []func(received any){ func(received any) { test.Equal(t, addedMsg, received.(string)) }, - func(received any) { test.NotCalled(t) }, + func(received any) { t.Error("should not be called 2nd time") }, } - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockName: func() string { - return "mock-name" - }, - MockError: func(args ...any) { - expected := "\n\x1b[38;5;52m\x1b[48;5;225m- Snapshot - 3\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + - "+ Received + 3\x1b[0m\n\n\x1b[38;5;52m\x1b[48;5;225m- int(10)\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m" + - "- hello world----\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m- ---\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + - "+ int(100)\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m+ bye world----\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + - "+ --\x1b[0m\n\n\x1b[2mat " + filepath.FromSlash( - "../__snapshots__/matchSnapshot_test.snap:2", - ) + - "\n\x1b[0m" - - test.Equal(t, expected, args[0].(string)) - }, - MockLog: func(args ...any) { - printerExpectedCalls[0](args[0]) + mockT := test.NewMockTestingT(t) + mockT.MockError = func(args ...any) { + expected := "\n\x1b[38;5;52m\x1b[48;5;225m- Snapshot - 3\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + + "+ Received + 3\x1b[0m\n\n\x1b[38;5;52m\x1b[48;5;225m- int(10)\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m" + + "- hello world----\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m- ---\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + + "+ int(100)\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m+ bye world----\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" + + "+ --\x1b[0m\n\n\x1b[2mat " + filepath.FromSlash( + "../__snapshots__/matchSnapshot_test.snap:2", + ) + + "\n\x1b[0m" + + test.Equal(t, expected, args[0].(string)) + } + mockT.MockLog = func(args ...any) { + printerExpectedCalls[0](args[0]) - // shift - printerExpectedCalls = printerExpectedCalls[1:] - }, + // shift + printerExpectedCalls = printerExpectedCalls[1:] } // First call for creating the snapshot ( adding ending chars inside the diff ) diff --git a/snaps/skip_test.go b/snaps/skip_test.go index 58301d1..eff1c99 100644 --- a/snaps/skip_test.go +++ b/snaps/skip_test.go @@ -3,6 +3,7 @@ package snaps import ( "os" "sync" + "sync/atomic" "testing" "github.com/gkampitakis/go-snaps/internal/test" @@ -15,21 +16,18 @@ func TestSkip(t *testing.T) { }) skipArgs := []any{1, 2, 3, 4, 5} - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockSkip: func(args ...any) { - test.Equal(t, skipArgs, args) - }, - MockName: func() string { - return "mock-test" - }, - MockLog: func(args ...any) { - test.Equal(t, skippedMsg, args[0].(string)) - }, + mockT := test.NewMockTestingT(t) + mockT.MockSkip = func(args ...any) { + test.Equal(t, skipArgs, args) } + mockT.MockLog = func(args ...any) { + test.Equal(t, skippedMsg, args[0].(string)) + } + mockT.MockSkip = func(...any) {} + Skip(mockT, 1, 2, 3, 4, 5) - test.Equal(t, []string{"mock-test"}, skippedTests.values) + test.Equal(t, []string{"mock-name"}, skippedTests.values) }) t.Run("should call Skipf", func(t *testing.T) { @@ -37,22 +35,19 @@ func TestSkip(t *testing.T) { skippedTests = newSyncSlice() }) - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockSkipf: func(format string, args ...any) { - test.Equal(t, "mock", format) - test.Equal(t, []any{1, 2, 3, 4, 5}, args) - }, - MockName: func() string { - return "mock-test" - }, - MockLog: func(args ...any) { - test.Equal(t, skippedMsg, args[0].(string)) - }, + mockT := test.NewMockTestingT(t) + mockT.MockSkipf = func(format string, args ...any) { + test.Equal(t, "mock", format) + test.Equal(t, []any{1, 2, 3, 4, 5}, args) + } + mockT.MockLog = func(args ...any) { + test.Equal(t, skippedMsg, args[0].(string)) } + mockT.MockSkipf = func(string, ...any) {} + Skipf(mockT, "mock", 1, 2, 3, 4, 5) - test.Equal(t, []string{"mock-test"}, skippedTests.values) + test.Equal(t, []string{"mock-name"}, skippedTests.values) }) t.Run("should call SkipNow", func(t *testing.T) { @@ -60,37 +55,30 @@ func TestSkip(t *testing.T) { skippedTests = newSyncSlice() }) - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockSkipNow: func() {}, - MockName: func() string { - return "mock-test" - }, - MockLog: func(args ...any) { - test.Equal(t, skippedMsg, args[0].(string)) - }, + mockT := test.NewMockTestingT(t) + mockT.MockLog = func(args ...any) { + test.Equal(t, skippedMsg, args[0].(string)) } + mockT.MockSkipNow = func() {} + SkipNow(mockT) - test.Equal(t, []string{"mock-test"}, skippedTests.values) + test.Equal(t, []string{"mock-name"}, skippedTests.values) }) t.Run("should be concurrent safe", func(t *testing.T) { t.Cleanup(func() { skippedTests = newSyncSlice() }) + calledCount := atomic.Int64{} - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockSkipNow: func() {}, - MockName: func() string { - return "mock-test" - }, - MockLog: func(args ...any) { - test.Equal(t, skippedMsg, args[0].(string)) - }, + mockT := test.NewMockTestingT(t) + mockT.MockLog = func(args ...any) { + test.Equal(t, skippedMsg, args[0].(string)) + } + mockT.MockSkipNow = func() { + calledCount.Add(1) } - wg := sync.WaitGroup{} for i := 0; i < 1000; i++ { @@ -105,6 +93,7 @@ func TestSkip(t *testing.T) { wg.Wait() test.Equal(t, 1000, len(skippedTests.values)) + test.Equal(t, 1000, calledCount.Load()) }) t.Run("testSkipped", func(t *testing.T) { @@ -132,16 +121,15 @@ func TestSkip(t *testing.T) { }) runOnly := "" - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockSkipNow: func() {}, - MockName: func() string { - return "TestMock/Skip" - }, - MockLog: func(args ...any) { - test.Equal(t, skippedMsg, args[0].(string)) - }, + mockT := test.NewMockTestingT(t) + mockT.MockName = func() string { + return "TestMock/Skip" } + mockT.MockLog = func(args ...any) { + test.Equal(t, skippedMsg, args[0].(string)) + } + mockT.MockSkipNow = func() {} + // This is for populating skippedTests.values and following the normal flow SkipNow(mockT) @@ -160,16 +148,15 @@ func TestSkip(t *testing.T) { }) runOnly := "" - mockT := test.MockTestingT{ - MockHelper: func() {}, - MockSkipNow: func() {}, - MockName: func() string { - return "Test" - }, - MockLog: func(args ...any) { - test.Equal(t, skippedMsg, args[0].(string)) - }, + mockT := test.NewMockTestingT(t) + mockT.MockName = func() string { + return "Test" } + mockT.MockLog = func(args ...any) { + test.Equal(t, skippedMsg, args[0].(string)) + } + mockT.MockSkipNow = func() {} + // This is for populating skippedTests.values and following the normal flow SkipNow(mockT) diff --git a/snaps/snapshot.go b/snaps/snapshot.go index 7ecaceb..1a17bb4 100644 --- a/snaps/snapshot.go +++ b/snaps/snapshot.go @@ -92,18 +92,18 @@ type syncRegistry struct { // Returns the id of the test in the snapshot // Form [ - ] -func (s *syncRegistry) getTestID(tName, snapPath string) string { +func (s *syncRegistry) getTestID(snapPath, testName string) string { s.Lock() if _, exists := s.values[snapPath]; !exists { s.values[snapPath] = make(map[string]int) } - s.values[snapPath][tName]++ - c := s.values[snapPath][tName] + s.values[snapPath][testName]++ + c := s.values[snapPath][testName] s.Unlock() - return fmt.Sprintf("[%s - %d]", tName, c) + return fmt.Sprintf("[%s - %d]", testName, c) } func newRegistry() *syncRegistry { diff --git a/snaps/snapshot_test.go b/snaps/snapshot_test.go index d1a6707..c45610d 100644 --- a/snaps/snapshot_test.go +++ b/snaps/snapshot_test.go @@ -8,7 +8,7 @@ import ( "github.com/gkampitakis/go-snaps/internal/test" ) -func TestTestID(t *testing.T) { +func TestSyncRegistry(t *testing.T) { t.Run("should increment id on each call [concurrent safe]", func(t *testing.T) { wg := sync.WaitGroup{} registry := newRegistry() @@ -17,15 +17,15 @@ func TestTestID(t *testing.T) { wg.Add(1) go func() { - registry.getTestID("test", "/file") + registry.getTestID("/file", "test") wg.Done() }() } wg.Wait() - test.Equal(t, "[test - 6]", registry.getTestID("test", "/file")) - test.Equal(t, "[test-v2 - 1]", registry.getTestID("test-v2", "/file")) + test.Equal(t, "[test - 6]", registry.getTestID("/file", "test")) + test.Equal(t, "[test-v2 - 1]", registry.getTestID("/file", "test-v2")) }) }