-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: test testdir finiding more thorughly and setup codecov config
- Loading branch information
1 parent
d8cb35c
commit ae99ad0
Showing
6 changed files
with
89 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
target: auto | ||
threshold: "2%" | ||
paths: "!examples/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/areknoster/hypert" | ||
) | ||
|
||
type mockT struct { | ||
errMsg string | ||
hypert.T | ||
} | ||
|
||
func (m *mockT) Errorf(format string, args ...any) { | ||
m.errMsg = fmt.Sprintf(format, args...) | ||
} | ||
|
||
func (m *mockT) Helper() {} | ||
|
||
func (m *mockT) Name() string { | ||
return "mockT" | ||
} | ||
|
||
func (m *mockT) Fatalf(format string, args ...any) { | ||
m.errMsg = fmt.Sprintf(format, args...) | ||
} | ||
|
||
func TestDefaultTestDataDir(t *testing.T) { | ||
t.Run("happy path", func(t *testing.T) { | ||
path := hypert.DefaultTestDataDir(t) | ||
expected := filepath.Join(filepath.Dir(currentFilePath()), "testdata", t.Name()) | ||
if path != expected { | ||
t.Fatalf("failed to get testdata path, got: %s, expected: %s", path, expected) | ||
} | ||
}) | ||
|
||
t.Run("when wrapped a few times it works fine", func(t *testing.T) { | ||
mockT := &mockT{} | ||
path := WrapTestDataDir(mockT, 1) | ||
expected := filepath.Join(filepath.Dir(currentFilePath()), "testdata", mockT.Name()) | ||
if path != expected { | ||
t.Fatalf("failed to get testdata path, got: %s, expected: %s", path, expected) | ||
} | ||
}) | ||
t.Run("when wrapped a lot it finally fails", func(t *testing.T) { | ||
mockT := &mockT{} | ||
_ = WrapTestDataDir(mockT, 21) | ||
if mockT.errMsg == "" { | ||
t.Fatalf("expected error, got none") | ||
} | ||
}) | ||
} | ||
|
||
func currentFilePath() string { | ||
_, file, _, ok := runtime.Caller(0) | ||
if !ok { | ||
panic("failed to get current file path") | ||
} | ||
return file | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package internal | ||
|
||
import ( | ||
"github.com/areknoster/hypert" | ||
) | ||
|
||
func WrapTestDataDir(t hypert.T, wraps int) string { | ||
wrap := func(prev func(t hypert.T) string) func(t hypert.T) string { | ||
return func(t hypert.T) string { | ||
return prev(t) | ||
} | ||
} | ||
wrapped := hypert.DefaultTestDataDir | ||
for i := 0; i < wraps; i++ { | ||
wrapped = wrap(wrapped) | ||
} | ||
return wrapped(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.