MCPcopy
hub / github.com/go-gorm/gorm / TestWithSingleConnection

Function TestWithSingleConnection

tests/connection_test.go:10–36  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestWithSingleConnection(t *testing.T) {
11 expectedName := "test"
12 var actualName string
13
14 setSQL, getSQL := getSetSQL(DB.Dialector.Name())
15 if len(setSQL) == 0 || len(getSQL) == 0 {
16 return
17 }
18
19 err := DB.Connection(func(tx *gorm.DB) error {
20 if err := tx.Exec(setSQL, expectedName).Error; err != nil {
21 return err
22 }
23
24 if err := tx.Raw(getSQL).Scan(&actualName).Error; err != nil {
25 return err
26 }
27 return nil
28 })
29 if err != nil {
30 t.Errorf("WithSingleConnection should work, but got err %v", err)
31 }
32
33 if actualName != expectedName {
34 t.Errorf("WithSingleConnection() method should get correct value, expect: %v, got %v", expectedName, actualName)
35 }
36}
37
38func getSetSQL(driverName string) (string, string) {
39 switch driverName {

Callers

nothing calls this directly

Calls 6

getSetSQLFunction · 0.85
ConnectionMethod · 0.80
NameMethod · 0.65
ExecMethod · 0.65
ScanMethod · 0.65
RawMethod · 0.65

Tested by

no test coverage detected