Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created August 27, 2021 07:18
Show Gist options
  • Save percybolmer/8e2622477df3a42dc5045192da40ecc4 to your computer and use it in GitHub Desktop.
Save percybolmer/8e2622477df3a42dc5045192da40ecc4 to your computer and use it in GitHub Desktop.
package aggregate_test
import (
"testing"
"github.com/percybolmer/ddd-go/aggregate"
)
func TestCustomer_NewCustomer(t *testing.T) {
// Build our needed testcase data struct
type testCase struct {
test string
name string
expectedErr error
}
// Create new test cases
testCases := []testCase{
{
test: "Empty Name validation",
name: "",
expectedErr: aggregate.ErrInvalidPerson,
}, {
test: "Valid Name",
name: "Percy Bolmer",
expectedErr: nil,
},
}
for _, tc := range testCases {
// Run Tests
t.Run(tc.test, func(t *testing.T) {
// Create a new customer
_, err := aggregate.NewCustomer(tc.name)
// Check if the error matches the expected error
if err != tc.expectedErr {
t.Errorf("Expected error %v, got %v", tc.expectedErr, err)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment