ex6api_error_test.go 528 B

1234567891011121314151617181920
  1. package main
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestDbParseString(t *testing.T) {
  7. expected_message := "duplicate entry"
  8. expected_code := int64(1062)
  9. error_string := fmt.Sprintf("Error %d: %s", expected_code, expected_message)
  10. actual_message, actual_code := dbParseEror(error_string)
  11. if actual_message != expected_message {
  12. t.Errorf("Message: expected [%s], got [%s].\n", expected_message, actual_message)
  13. }
  14. if actual_code != expected_code {
  15. t.Errorf("Code: expected %d, got %d.\n", expected_code, actual_code)
  16. }
  17. }