(tb testing.TB)
| 39 | } |
| 40 | |
| 41 | func 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 | |
| 74 | func UpdateSamples() bool { |
| 75 | us, _ := strconv.ParseBool(os.Getenv("UPDATE_SAMPLES")) |
no test coverage detected