Chromium Code Reviews| 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) |
| +} |