MCPcopy Create free account
hub / github.com/daodst/chat / createRemoteDB

Function createRemoteDB

test/db.go:62–86  ·  view source on GitHub ↗
(t *testing.T, dbName, user, connStr string)

Source from the content-addressed store, hash-verified

60}
61
62func createRemoteDB(t *testing.T, dbName, user, connStr string) {
63 db, err := sql.Open("postgres", connStr+" dbname=postgres")
64 if err != nil {
65 fatalError(t, "failed to open postgres conn with connstr=%s : %s", connStr, err)
66 }
67 if err = db.Ping(); err != nil {
68 fatalError(t, "failed to open postgres conn with connstr=%s : %s", connStr, err)
69 }
70 _, err = db.Exec(fmt.Sprintf(`CREATE DATABASE %s;`, dbName))
71 if err != nil {
72 pqErr, ok := err.(*pq.Error)
73 if !ok {
74 t.Fatalf("failed to CREATE DATABASE: %s", err)
75 }
76 // we ignore duplicate database error as we expect this
77 if pqErr.Code != "42P04" {
78 t.Fatalf("failed to CREATE DATABASE with code=%s msg=%s", pqErr.Code, pqErr.Message)
79 }
80 }
81 _, err = db.Exec(fmt.Sprintf(`GRANT ALL PRIVILEGES ON DATABASE %s TO %s`, dbName, user))
82 if err != nil {
83 t.Fatalf("failed to GRANT: %s", err)
84 }
85 _ = db.Close()
86}
87
88func currentUser() string {
89 user, err := user.Current()

Callers 1

Calls 3

fatalErrorFunction · 0.85
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected