1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
package testhelpers
import (
"testing"
"github.com/stretchr/testify/assert"
)
type Validatable interface {
ValidateAll() error
}
type InvalidTestcase struct {
ErrString string
Invalid Validatable
}
type ValidTestcase struct {
Name string
Valid Validatable
}
func AssertInvalid(t *testing.T, tests []InvalidTestcase) {
for _, tc := range tests {
t.Run(tc.ErrString, func(t *testing.T) {
err := tc.Invalid.ValidateAll()
assert.EqualError(t, err, tc.ErrString)
})
}
}
func AssertValid(t *testing.T, tests []ValidTestcase) {
for _, tc := range tests {
t.Run(tc.Name, func(t *testing.T) {
assert.NoError(t, tc.Valid.ValidateAll())
})
}
}
|