Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force MySQL Go test to fail on GitHub workflow if the MySQL test database is not available #107

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
sudo /etc/init.d/mysql start
mysql -e "CREATE DATABASE IF NOT EXISTS $DB_DATABASE;" -u$DB_USER -p$DB_PASSWORD
- name: Test with Go
run: go test -v -race ./storage/mysql/...
run: go test -v -race ./storage/mysql/... -is_mysql_test_optional=false
19 changes: 14 additions & 5 deletions storage/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"k8s.io/klog/v2"
)

var mysqlURI = flag.String("mysql_uri", "root:root@tcp(localhost:3306)/test_tessera", "Connection string for a MySQL database")
var (
mysqlURI = flag.String("mysql_uri", "root:root@tcp(localhost:3306)/test_tessera", "Connection string for a MySQL database")
isMySQLTestOptional = flag.Bool("is_mysql_test_optional", true, "Boolean value to control whether the MySQL test is optional")
)

func TestMain(m *testing.M) {
klog.InitFlags(nil)
Expand All @@ -19,12 +22,18 @@ func TestMain(m *testing.M) {

db, err := sql.Open("mysql", *mysqlURI)
if err != nil {
klog.Errorf("MySQL not available, skipping all MySQL storage tests")
return
if *isMySQLTestOptional {
klog.Warning("MySQL not available, skipping all MySQL storage tests")
return
}
klog.Fatalf("Failed to open MySQL test db: %v", err)
}
if err := db.PingContext(ctx); err != nil {
klog.Errorf("MySQL not available, skipping all MySQL storage tests")
return
if *isMySQLTestOptional {
klog.Warning("MySQL not available, skipping all MySQL storage tests")
return
}
klog.Fatalf("Failed to ping MySQL test db: %v", err)
}
klog.Info("Successfully connected to MySQL test database")

Expand Down
Loading