repogen/internal/mongo/errors_test.go

59 lines
1.4 KiB
Go
Raw Normal View History

2021-02-14 04:48:09 +00:00
package mongo_test
import (
"testing"
"github.com/sunboyy/repogen/internal/mongo"
2021-03-31 11:44:31 +00:00
"github.com/sunboyy/repogen/internal/spec"
2021-02-14 04:48:09 +00:00
)
type ErrorTestCase struct {
Name string
Error error
ExpectedString string
}
type StubUpdate struct {
}
func (update StubUpdate) Name() string {
return "Stub"
}
func (update StubUpdate) NumberOfArguments() int {
return 1
}
2021-02-14 04:48:09 +00:00
func TestError(t *testing.T) {
testTable := []ErrorTestCase{
{
Name: "OperationNotSupportedError",
Error: mongo.NewOperationNotSupportedError("Stub"),
ExpectedString: "operation 'Stub' not supported",
},
{
Name: "BsonTagNotFoundError",
Error: mongo.NewBsonTagNotFoundError("AccessToken"),
ExpectedString: "bson tag of field 'AccessToken' not found",
},
{
Name: "UpdateTypeNotSupportedError",
Error: mongo.NewUpdateTypeNotSupportedError(StubUpdate{}),
ExpectedString: "update type Stub not supported",
},
2021-03-31 11:44:31 +00:00
{
Name: "UpdateOperatorNotSupportedError",
Error: mongo.NewUpdateOperatorNotSupportedError(spec.UpdateOperator("STUB")),
ExpectedString: "update operator STUB not supported",
},
2021-02-14 04:48:09 +00:00
}
for _, testCase := range testTable {
t.Run(testCase.Name, func(t *testing.T) {
if testCase.Error.Error() != testCase.ExpectedString {
2021-03-31 11:44:31 +00:00
t.Errorf("Expected = %+v\nReceived = %+v", testCase.ExpectedString, testCase.Error.Error())
2021-02-14 04:48:09 +00:00
}
})
}
}