MCPcopy Create free account
hub / github.com/cinar/indicator / TestCloseDatabaseWithError

Function TestCloseDatabaseWithError

helper/database_test.go:45–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestCloseDatabaseWithError(t *testing.T) {
46 db, _ := sql.Open("mock", "success")
47 db.Ping() // Trigger connection
48
49 err := errors.New("some error")
50 res := helper.CloseDatabaseWithError(db, err)
51 if res != err {
52 t.Fatalf("expected %v, got %v", err, res)
53 }
54
55 db, _ = sql.Open("mock", "fail")
56 db.Ping() // Trigger connection
57
58 res = helper.CloseDatabaseWithError(db, err)
59 if res != err {
60 t.Fatalf("expected %v, got %v", err, res)
61 }
62
63 db, _ = sql.Open("mock", "fail")
64 db.Ping() // Trigger connection
65
66 res = helper.CloseDatabaseWithError(db, nil)
67 if res == nil || res.Error() != "unable to close database: close failed" {
68 t.Fatalf("expected close error, got %v", res)
69 }
70}
71
72func TestCloseDatabaseRows(t *testing.T) {
73 // CloseDatabaseRows only logs if it fails, and doesn't return anything.

Callers

nothing calls this directly

Calls 2

CloseDatabaseWithErrorFunction · 0.92
OpenMethod · 0.45

Tested by

no test coverage detected