diff --git a/container_test.go b/container_test.go index 86ca8b64..2dc091ea 100644 --- a/container_test.go +++ b/container_test.go @@ -25,8 +25,6 @@ import ( "reflect" "testing" - "go.uber.org/dig/vallie" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -546,32 +544,6 @@ func TestMultiObjectRegisterResolve(t *testing.T) { require.NotNil(t, third, "Child3 must have been registered") } -func Test_ZeroValueObjectValidationSuccess(t *testing.T) { - t.Parallel() - c := New() - - c.Provide(&Parent1{}) - err := c.Invoke(func(p1 *Parent1) { - er := vallie.Validate(p1) - require.NoError(t, er) - }) - require.Nil(t, err) -} - -func Test_ZeroValueObjectValidationError(t *testing.T) { - t.Parallel() - c := New() - - var zeroP12 *Parent12 - err := c.Invoke(func(p12 *Parent12) { - er := vallie.Validate(p12) - require.Error(t, er) - require.Contains(t, er.Error(), "zero value") - zeroP12 = p12 - }) - require.Nil(t, err) -} - func TestZeroValueOnInvoke(t *testing.T) { type missing struct{} type present struct{} diff --git a/vallie/vallie_test.go b/vallie/vallie_test.go new file mode 100644 index 00000000..df3586da --- /dev/null +++ b/vallie/vallie_test.go @@ -0,0 +1,35 @@ +package vallie + +import ( + "net/http" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestValidation(t *testing.T) { + type nothing struct{} + + tests := []struct { + desc string + input []interface{} + valid bool + }{ + {"empty input", []interface{}{}, true}, + {"nil pointer", []interface{}{(*nothing)(nil)}, false}, + {"zero value", []interface{}{nothing{}}, false}, + {"non-zero value", []interface{}{5}, true}, + {"mixed input", []interface{}{5, http.DefaultServeMux}, true}, + } + + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + assert.Equal( + t, + tt.valid, + Validate(tt.input...) == nil, + "unexpected validation result for %v", tt.input, + ) + }) + } +}