repogen/internal/spec/errors_test.go
2021-02-23 19:10:25 +07:00

50 lines
1.3 KiB
Go

package spec_test
import (
"testing"
"github.com/sunboyy/repogen/internal/code"
"github.com/sunboyy/repogen/internal/spec"
)
type ErrorTestCase struct {
Name string
Error error
ExpectedString string
}
func TestError(t *testing.T) {
testTable := []ErrorTestCase{
{
Name: "UnknownOperationError",
Error: spec.NewUnknownOperationError("Search"),
ExpectedString: "unknown operation 'Search'",
},
{
Name: "StructFieldNotFoundError",
Error: spec.NewStructFieldNotFoundError("Country"),
ExpectedString: "struct field 'Country' not found",
},
{
Name: "InvalidQueryError",
Error: spec.NewInvalidQueryError([]string{"By", "And"}),
ExpectedString: "invalid query 'ByAnd'",
},
{
Name: "IncompatibleComparatorError",
Error: spec.NewIncompatibleComparatorError(spec.ComparatorTrue, code.StructField{
Name: "Age",
Type: code.SimpleType("int"),
}),
ExpectedString: "cannot use comparator EQUAL_TRUE with struct field 'Age' of type 'int'",
},
}
for _, testCase := range testTable {
t.Run(testCase.Name, func(t *testing.T) {
if testCase.Error.Error() != testCase.ExpectedString {
t.Errorf("Expected = %v\nReceived = %v", testCase.ExpectedString, testCase.Error.Error())
}
})
}
}