-
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.
feat: Remove stretchr/testify dependency (#20)
## Motivation We should strive to make `govy` as pure of a library as possible, with little to no 3rd party dependencies. Since Go does not support a concept of developer dependencies, we should start by removing [testify](https://github.com/stretchr/testify), which is the heaviest 3rd party dependency for govy. This way we're not forcing other projects to include the library in their module's dependency tree. ## Release Notes Govy no longer relies on `stretchr/testify` library for unit testing, thus limiting its module's dependency tree size significantly.
- Loading branch information
1 parent
73dd5a3
commit c0e1d36
Showing
28 changed files
with
274 additions
and
135 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
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
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 |
---|---|---|
@@ -1,23 +1,15 @@ | ||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= | ||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= | ||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= | ||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= | ||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | ||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= | ||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= | ||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= | ||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= | ||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= | ||
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= | ||
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457 h1:zf5N6UOrA487eEFacMePxjXAJctxKmyjKUsjA11Uzuk= | ||
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0= | ||
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= | ||
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= | ||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= | ||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= | ||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= | ||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= |
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,158 @@ | ||
package assert | ||
|
||
import ( | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// Require fails the test if the provided boolean is false. | ||
// It should be used in conjunction with assert functions. | ||
// Example: | ||
// | ||
// testutils.Require(t, testutils.AssertError(t, err)) | ||
func Require(t *testing.T, isPassing bool) { | ||
t.Helper() | ||
if !isPassing { | ||
t.FailNow() | ||
} | ||
} | ||
|
||
// Equal fails the test if the expected and actual values are not equal. | ||
func Equal(t *testing.T, expected, actual interface{}) bool { | ||
t.Helper() | ||
if !areEqual(expected, actual) { | ||
return fail(t, "Expected %v, got %v", expected, actual) | ||
} | ||
return true | ||
} | ||
|
||
// True fails the test if the actual value is not true. | ||
func True(t *testing.T, actual bool) bool { | ||
t.Helper() | ||
if !actual { | ||
return fail(t, "Should be true") | ||
} | ||
return true | ||
} | ||
|
||
// Len fails the test if the object is not of the expected length. | ||
func Len(t *testing.T, object interface{}, length int) bool { | ||
t.Helper() | ||
if actual := getLen(object); actual != length { | ||
return fail(t, "Expected length %d, got %d", length, actual) | ||
} | ||
return true | ||
} | ||
|
||
// IsType fails the test if the object is not of the expected type. | ||
// The expected type is specified using a type parameter. | ||
func IsType[T any](t *testing.T, object interface{}) bool { | ||
t.Helper() | ||
switch object.(type) { | ||
case T: | ||
return true | ||
default: | ||
return fail(t, "Expected type %T, got %T", *new(T), object) | ||
} | ||
} | ||
|
||
// Error fails the test if the error is nil. | ||
func Error(t *testing.T, err error) bool { | ||
t.Helper() | ||
if err == nil { | ||
return fail(t, "An error is expected but got nil.") | ||
} | ||
return true | ||
} | ||
|
||
// NoError fails the test if the error is not nil. | ||
func NoError(t *testing.T, err error) bool { | ||
t.Helper() | ||
if err != nil { | ||
return fail(t, "Unexpected error:\n%+v", err) | ||
} | ||
return true | ||
} | ||
|
||
// EqualError fails the test if the expected error is not equal to the actual error message. | ||
func EqualError(t *testing.T, expected error, actual string) bool { | ||
t.Helper() | ||
if !Error(t, expected) { | ||
return false | ||
} | ||
if expected.Error() != actual { | ||
return fail(t, "Expected error message %q, got %q", expected.Error(), actual) | ||
} | ||
return true | ||
} | ||
|
||
// ErrorContains fails the test if the expected error does not contain the provided string. | ||
func ErrorContains(t *testing.T, expected error, contains string) bool { | ||
t.Helper() | ||
if !Error(t, expected) { | ||
return false | ||
} | ||
if !strings.Contains(expected.Error(), contains) { | ||
return fail(t, "Expected error message to contain %q, got %q", contains, expected.Error()) | ||
} | ||
return true | ||
} | ||
|
||
// ElementsMatch fails the test if the expected and actual slices do not have the same elements. | ||
func ElementsMatch[T comparable](t *testing.T, expected, actual []T) bool { | ||
t.Helper() | ||
if len(expected) != len(actual) { | ||
return fail(t, "Slices are not equal in length, expected: %d, got: %d", len(expected), len(actual)) | ||
} | ||
|
||
actualVisited := make([]bool, len(actual)) | ||
for _, e := range expected { | ||
found := false | ||
for j, a := range actual { | ||
if actualVisited[j] { | ||
continue | ||
} | ||
if areEqual(e, a) { | ||
actualVisited[j] = true | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
return fail(t, "Expected element %v not found in actual slice", e) | ||
} | ||
} | ||
for i := range actual { | ||
if !actualVisited[i] { | ||
return fail(t, "Unexpected element %v found in actual slice", actual[i]) | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func areEqual(expected, actual interface{}) bool { | ||
if expected == nil || actual == nil { | ||
return expected == actual | ||
} | ||
if !reflect.DeepEqual(expected, actual) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func getLen(v interface{}) int { | ||
rv := reflect.ValueOf(v) | ||
switch rv.Kind() { | ||
case reflect.Slice, reflect.Map, reflect.String: | ||
return rv.Len() | ||
default: | ||
return -1 | ||
} | ||
} | ||
|
||
func fail(t *testing.T, msg string, a ...interface{}) bool { | ||
t.Helper() | ||
t.Errorf(msg, a...) | ||
return false | ||
} |
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,3 @@ | ||
// Package assert provides utility functions for testing | ||
// which help assert certain conditions are met. | ||
package assert |
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
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
Oops, something went wrong.