-
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 Go test to GitHub workflows (#100)
* Add MySQL Go test to GitHub workflows * Update database user credential * Add MySQL test to connect to the underlying test database * Update MySQL URI to use localhost
- Loading branch information
Showing
2 changed files
with
61 additions
and
7 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 |
---|---|---|
@@ -1,18 +1,40 @@ | ||
on: [push, pull_request] | ||
name: Test Go | ||
|
||
on: [push, pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
go-version: [1.22.x] | ||
os: [ubuntu-latest] | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v3.1.0 | ||
- run: go test -v -race -covermode=atomic -coverprofile=coverage.out ./... | ||
- uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 | ||
|
||
test-mysql: | ||
env: | ||
DB_DATABASE: test_tessera | ||
DB_USER: root | ||
DB_PASSWORD: root | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v3.1.0 | ||
- run: go test -v -race -covermode=atomic -coverprofile=coverage.out ./... | ||
- uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 | ||
- name: Checkout code | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v3.1.0 | ||
- name: Start MySQL | ||
run: | | ||
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/... |
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(localhost: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()) | ||
} |