Skip to content

Commit

Permalink
Add MySQL test to connect to the underlying test database
Browse files Browse the repository at this point in the history
  • Loading branch information
roger2hk committed Aug 1, 2024
1 parent e5890ea commit b97224c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions storage/mysql/mysql_test.go
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())
}

0 comments on commit b97224c

Please sign in to comment.