MCPcopy Create free account
hub / github.com/Percona-Lab/mysql_random_data_load / GetMySQLConnection

Function GetMySQLConnection

testutils/testutils.go:41–72  ·  view source on GitHub ↗
(tb testing.TB)

Source from the content-addressed store, hash-verified

39}
40
41func GetMySQLConnection(tb testing.TB) *sql.DB {
42 if db != nil {
43 return db
44 }
45
46 dsn := os.Getenv("TEST_DSN")
47 if dsn == "" {
48 fmt.Printf("%s TEST_DSN environment variable is empty", caller())
49 tb.FailNow()
50 }
51
52 // Parse the DSN in the env var and ensure it has parseTime & multiStatements enabled
53 // MultiStatements is required for LoadQueriesFromFile
54 cfg, err := mysql.ParseDSN(dsn)
55 if err != nil {
56 fmt.Printf("%s cannot parse DSN %q: %s", caller(), dsn, err)
57 tb.FailNow()
58 }
59 if cfg.Params == nil {
60 cfg.Params = make(map[string]string)
61 }
62 cfg.ParseTime = true
63 cfg.MultiStatements = true
64 cfg.InterpolateParams = true
65
66 db, err := sql.Open("mysql", cfg.FormatDSN())
67 if err != nil {
68 fmt.Printf("%s cannot connect to the db: DSN: %s\n%s", caller(), dsn, err)
69 tb.FailNow()
70 }
71 return db
72}
73
74func UpdateSamples() bool {
75 us, _ := strconv.ParseBool(os.Getenv("UPDATE_SAMPLES"))

Callers 1

LoadQueriesFromFileFunction · 0.85

Calls 1

callerFunction · 0.85

Tested by

no test coverage detected