Skip to content

Commit

Permalink
Move validation tests to vallie package
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay Shah committed May 25, 2017
1 parent 0428135 commit 681170a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
28 changes: 0 additions & 28 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"reflect"
"testing"

"go.uber.org/dig/vallie"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -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{}
Expand Down
35 changes: 35 additions & 0 deletions vallie/vallie_test.go
Original file line number Diff line number Diff line change
@@ -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,
)
})
}
}

0 comments on commit 681170a

Please sign in to comment.