@@ -43,13 +43,13 @@ func TestErrorsStrictIgnoreNotes(t *testing.T) {
43
43
}
44
44
45
45
func TestMySQLErrIs (t * testing.T ) {
46
- infraErr := & MySQLError {1234 , "the server is on fire" }
47
- otherInfraErr := & MySQLError {1234 , "the datacenter is flooded" }
46
+ infraErr := & MySQLError {Number : 1234 , Message : "the server is on fire" }
47
+ otherInfraErr := & MySQLError {Number : 1234 , Message : "the datacenter is flooded" }
48
48
if ! errors .Is (infraErr , otherInfraErr ) {
49
49
t .Errorf ("expected errors to be the same: %+v %+v" , infraErr , otherInfraErr )
50
50
}
51
51
52
- differentCodeErr := & MySQLError {5678 , "the server is on fire" }
52
+ differentCodeErr := & MySQLError {Number : 5678 , Message : "the server is on fire" }
53
53
if errors .Is (infraErr , differentCodeErr ) {
54
54
t .Fatalf ("expected errors to be different: %+v %+v" , infraErr , differentCodeErr )
55
55
}
@@ -59,3 +59,22 @@ func TestMySQLErrIs(t *testing.T) {
59
59
t .Fatalf ("expected errors to be different: %+v %+v" , infraErr , nonMysqlErr )
60
60
}
61
61
}
62
+
63
+ func TestMySQLErrIsWithSQLState (t * testing.T ) {
64
+ toState := func (s string ) [5 ]byte {
65
+ var b [5 ]byte
66
+ copy (b [:], s )
67
+ return b
68
+ }
69
+
70
+ infraErr := & MySQLError {Number : 1234 , SQLState : toState ("HY000" ), Message : "the server is on fire" }
71
+ otherInfraErr := & MySQLError {Number : 1234 , SQLState : toState ("HY000" ), Message : "the datacenter is flooded" }
72
+ if ! infraErr .IsWithSQLState (otherInfraErr ) {
73
+ t .Errorf ("expected errors to be the same: %+v %+v" , infraErr , otherInfraErr )
74
+ }
75
+
76
+ differentStateErr := & MySQLError {Number : 1234 , SQLState : toState ("45000" ), Message : "the server is on fire" }
77
+ if infraErr .IsWithSQLState (differentStateErr ) {
78
+ t .Fatalf ("expected errors to be different: %+v %+v" , infraErr , differentStateErr )
79
+ }
80
+ }
0 commit comments