Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: perf/go/db/db_test.go

Issue 608273002: Add versioning to perf SQL database (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Incorporating feedback 4 Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « perf/go/db/db.go ('k') | perf/go/ingest/main.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: perf/go/db/db_test.go
diff --git a/perf/go/db/db_test.go b/perf/go/db/db_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..1927a8856be418b4a90b3deb46e58af3a7605183
--- /dev/null
+++ b/perf/go/db/db_test.go
@@ -0,0 +1,58 @@
+package db
+
+import (
+ "fmt"
+ "os"
+ "testing"
+)
+
+import (
+ // Using 'require' which is like using 'assert' but causes tests to fail.
+ assert "github.com/stretchr/testify/require"
+)
+
+// Connection string to the local MySQL database for testing.
+const MYSQL_DB_OPEN = "root:%s@tcp(localhost:3306)/skia?parseTime=true"
+
+func TestSQLiteVersioning(t *testing.T) {
+ // Initialize without argument to test against SQLite3
+ Init("")
+ assert.False(t, isMySQL)
+ testDBVersioning(t)
+}
+
+func TestMySQLVersioning(t *testing.T) {
+ // Skip this test unless there is an environment variable with the root
+ // password for the local MySQL instance.
+ password := os.Getenv("MYSQL_TESTING_ROOTPW")
+ if password == "" {
+ t.Skip("Skipping versioning tests against MySQL. Set 'MYSQL_TESTING_ROOTPW' to enable tests.")
+ }
+
+ // Initialize to test against local MySQL db
+ Init(fmt.Sprintf(MYSQL_DB_OPEN, password))
+ assert.True(t, isMySQL)
+ testDBVersioning(t)
+}
+
+// Test wether the migration scripts execute.
+func testDBVersioning(t *testing.T) {
+ // get the DB version
+ dbVersion, err := DBVersion()
+ assert.Nil(t, err)
+ maxVersion := MaxDBVersion()
+
+ // downgrade to 0
+ err = Migrate(0)
+ assert.Nil(t, err)
+ dbVersion, err = DBVersion()
+ assert.Nil(t, err)
+ assert.Equal(t, 0, dbVersion)
+
+ // upgrade the the latest version
+ err = Migrate(maxVersion)
+ assert.Nil(t, err)
+ dbVersion, err = DBVersion()
+ assert.Nil(t, err)
+ assert.Equal(t, maxVersion, dbVersion)
+}
« no previous file with comments | « perf/go/db/db.go ('k') | perf/go/ingest/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698