This repository has been archived by the owner on May 31, 2022. It is now read-only.
forked from skeema/tengo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
71 lines (64 loc) · 2.24 KB
/
errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package tengo
import (
"errors"
"fmt"
"testing"
)
func (s TengoIntegrationSuite) TestIsDatabaseError(t *testing.T) {
err1 := errors.New("non-db error")
if IsDatabaseError(err1) {
t.Errorf("IsDatabaseError unexpectedly returned true for non-database error type=%T", err1)
}
_, err2 := s.d.Connect("doesnt_exist", "")
if !IsDatabaseError(err2) {
t.Errorf("IsDatabaseError unexpectedly returned false for error of type=%T", err2)
}
}
func (s TengoIntegrationSuite) TestIsSyntaxError(t *testing.T) {
err := errors.New("non-db error")
if IsSyntaxError(err) {
t.Errorf("IsSyntaxError unexpectedly returned true for non-database error type=%T", err)
}
db, err := s.d.ConnectionPool("testing", "")
if err != nil {
t.Fatalf("Unable to get connection")
}
_, err = db.Exec("ALTER TAABBEL actor ENGINE=InnoDB")
if err == nil {
t.Error("Bad syntax still returned nil error unexpectedly")
} else if !IsSyntaxError(err) {
t.Errorf("Error of type %T %+v unexpectedly not considered syntax error", err, err)
}
_, err = db.Exec("ALTER TABLE doesnt_exist ENGINE=InnoDB")
if err == nil {
t.Error("Bad alter still returned nil error unexpectedly")
} else if IsSyntaxError(err) {
t.Errorf("Error of type %T %+v unexpectedly considered syntax error", err, err)
}
}
func (s TengoIntegrationSuite) TestIsAccessError(t *testing.T) {
err := errors.New("non-db error")
if IsAccessError(err) {
t.Errorf("IsAccessError unexpectedly returned true for non-database error type=%T", err)
}
// Hack username in DSN to no longer be correct
inst := s.d.Instance
inst.BaseDSN = fmt.Sprintf("badname%s", inst.BaseDSN)
_, err = inst.ConnectionPool("", "")
if err == nil {
t.Error("ConnectionPool unexpectedly returned nil error")
} else if !IsAccessError(err) {
t.Errorf("Error of type %T %+v unexpectedly not considered access error", err, err)
}
inst.BaseDSN = inst.BaseDSN[7:]
db, err := inst.ConnectionPool("testing", "")
if err != nil {
t.Errorf("ConnectionPool unexpectedly returned error: %s", err)
}
_, err = db.Exec("ALTER TABLE doesnt_exist ENGINE=InnoDB")
if err == nil {
t.Error("Bad alter still returned nil error unexpectedly")
} else if IsAccessError(err) {
t.Errorf("Error of type %T %+v unexpectedly considered access error", err, err)
}
}