git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/validate/error_test.go (about) 1 package validate 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestErrorsToString(t *testing.T) { 9 t.Parallel() 10 customErr := &Error{Name: "Custom Error Name", Err: fmt.Errorf("stdlib error")} 11 customErrWithCustomErrorMessage := &Error{Name: "Custom Error Name 2", Err: fmt.Errorf("Bad stuff happened"), CustomErrorMessageExists: true} 12 13 var tests = []struct { 14 param1 Errors 15 expected string 16 }{ 17 {Errors{}, ""}, 18 {Errors{fmt.Errorf("Error 1")}, "Error 1"}, 19 {Errors{fmt.Errorf("Error 1"), fmt.Errorf("Error 2")}, "Error 1;Error 2"}, 20 {Errors{customErr, fmt.Errorf("Error 2")}, "Custom Error Name: stdlib error;Error 2"}, 21 {Errors{fmt.Errorf("Error 123"), customErrWithCustomErrorMessage}, "Bad stuff happened;Error 123"}, 22 } 23 for _, test := range tests { 24 actual := test.param1.Error() 25 if actual != test.expected { 26 t.Errorf("Expected Error() to return '%v', got '%v'", test.expected, actual) 27 } 28 } 29 }