-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MySQL test to connect to the underlying test database
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package mysql_test | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"flag" | ||
"os" | ||
"testing" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
var mysqlURI = flag.String("mysql_uri", "root:root@tcp(db:3306)/test_tessera", "Connection string for a MySQL database") | ||
|
||
func TestMain(m *testing.M) { | ||
klog.InitFlags(nil) | ||
flag.Parse() | ||
ctx := context.Background() | ||
|
||
db, err := sql.Open("mysql", *mysqlURI) | ||
if err != nil { | ||
klog.Errorf("MySQL not available, skipping all MySQL storage tests") | ||
return | ||
} | ||
if err := db.PingContext(ctx); err != nil { | ||
klog.Errorf("MySQL not available, skipping all MySQL storage tests") | ||
return | ||
} | ||
klog.Info("Successfully connected to MySQL test database") | ||
|
||
os.Exit(m.Run()) | ||
} |