@@ -63,6 +63,8 @@ func (d *fakeDriver) Open(dsn string) (driver.Conn, error) {
63
63
* FakeConnQueryer
64
64
* FakeConnSessionResetter
65
65
}{}, nil
66
+ case "NonConnBeginTx" :
67
+ return & FakeConnUnsupported {}, nil
66
68
}
67
69
68
70
return nil , errors .New ("Fake driver not implemented" )
@@ -80,6 +82,9 @@ func (*FakeConnBasic) Close() error {
80
82
func (* FakeConnBasic ) Begin () (driver.Tx , error ) {
81
83
return nil , errors .New ("Not implemented" )
82
84
}
85
+ func (* FakeConnBasic ) BeginTx (context.Context , driver.TxOptions ) (driver.Tx , error ) {
86
+ return nil , errors .New ("Not implemented" )
87
+ }
83
88
84
89
type FakeConnExecer struct {}
85
90
@@ -111,6 +116,20 @@ func (*FakeConnSessionResetter) ResetSession(ctx context.Context) error {
111
116
return errors .New ("Not implemented" )
112
117
}
113
118
119
+ // FakeConnUnsupported implements a database/sql.driver.Conn but doesn't implement
120
+ // driver.ConnBeginTx.
121
+ type FakeConnUnsupported struct {}
122
+
123
+ func (* FakeConnUnsupported ) Prepare (query string ) (driver.Stmt , error ) {
124
+ return nil , errors .New ("Not implemented" )
125
+ }
126
+ func (* FakeConnUnsupported ) Close () error {
127
+ return errors .New ("Not implemented" )
128
+ }
129
+ func (* FakeConnUnsupported ) Begin () (driver.Tx , error ) {
130
+ return nil , errors .New ("Not implemented" )
131
+ }
132
+
114
133
func TestInterfaces (t * testing.T ) {
115
134
drv := Wrap (& fakeDriver {}, & testHooks {})
116
135
@@ -123,3 +142,9 @@ func TestInterfaces(t *testing.T) {
123
142
}
124
143
}
125
144
}
145
+
146
+ func TestUnsupportedDrivers (t * testing.T ) {
147
+ drv := Wrap (& fakeDriver {}, & testHooks {})
148
+ _ , err := drv .Open ("NonConnBeginTx" )
149
+ require .EqualError (t , err , "driver must implement driver.ConnBeginTx" )
150
+ }
0 commit comments