Created
August 27, 2021 07:18
-
-
Save percybolmer/8e2622477df3a42dc5045192da40ecc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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