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

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: Incorporated feedback 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
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..5cb84ff824a158912515405501a625c1fc09426d
--- /dev/null
+++ b/perf/go/db/db_test.go
@@ -0,0 +1,49 @@
+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.
jcgregorio 2014/09/30 14:54:08 So I need a local MySQL instance to run this test?
stephana 2014/09/30 18:11:50 Yes. I have changed it so that it checks whether t
+const MYSQL_DB_OPEN = "root:%s@tcp(localhost:3306)/skia?parseTime=true"
+
+func TestDBVersioning(t *testing.T) {
+ // Initialize without argument to test against SQLite3
+ Init("")
+ assert.False(t, isMySQL)
+ testDBVersioning(t)
+
+ // Initialize to test against local MySQL db
+ Init(fmt.Sprintf(MYSQL_DB_OPEN, os.Getenv("MYSQL_TESTING_ROOTPW")))
+ 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)
+}
« perf/go/db/db.go ('K') | « perf/go/db/db.go ('k') | perf/go/migratedb/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698