diff --git a/server/storage/database_test.go b/server/storage/database_test.go index 7177077d7c..6aed4a7152 100644 --- a/server/storage/database_test.go +++ b/server/storage/database_test.go @@ -31,7 +31,7 @@ func SampleUpdate(version int) MetaUpdate { } // SetUpSQLite creates a sqlite database for testing -func SetUpSQLite(dbDir string, t *testing.T, createTable bool) (*gorm.DB, *SQLStorage) { +func SetUpSQLite(t *testing.T, dbDir string, createTable bool) (*gorm.DB, *SQLStorage) { dbStore, err := NewSQLStorage("sqlite3", dbDir+"test_db") assert.NoError(t, err) @@ -59,7 +59,7 @@ func SetUpSQLite(dbDir string, t *testing.T, createTable bool) (*gorm.DB, *SQLSt // if no previous version existed. func TestSQLUpdateCurrentNew(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) // Adding a new TUF file should succeed @@ -80,7 +80,7 @@ func TestSQLUpdateCurrentNew(t *testing.T) { // new (higher) version of an existing TUF file func TestSQLUpdateCurrentNewVersion(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) // insert row @@ -108,7 +108,7 @@ func TestSQLUpdateCurrentNewVersion(t *testing.T) { // trying to update to an older version of a TUF file. func TestSQLUpdateCurrentOldVersionError(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) // insert row @@ -138,7 +138,7 @@ func TestSQLUpdateCurrentOldVersionError(t *testing.T) { // updates do not conflict with each. func TestSQLUpdateMany(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) err = dbStore.UpdateMany("testGUN", []MetaUpdate{ @@ -173,7 +173,7 @@ func TestSQLUpdateMany(t *testing.T) { // non-monotonic versions still succeeds. func TestSQLUpdateManyVersionOrder(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) err = dbStore.UpdateMany( @@ -199,7 +199,7 @@ func TestSQLUpdateManyVersionOrder(t *testing.T) { // updates fails. func TestSQLUpdateManyDuplicateRollback(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) update := SampleUpdate(0) @@ -221,7 +221,7 @@ func TestSQLUpdateManyDuplicateRollback(t *testing.T) { func TestSQLGetCurrent(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) byt, err := dbStore.GetCurrent("testGUN", "root") @@ -242,7 +242,7 @@ func TestSQLGetCurrent(t *testing.T) { func TestSQLDelete(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) tuf := SampleTUF(0) @@ -263,7 +263,7 @@ func TestSQLDelete(t *testing.T) { func TestSQLGetTimestampKeyNoKey(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) cipher, public, err := dbStore.GetTimestampKey("testGUN") @@ -288,7 +288,7 @@ func TestSQLGetTimestampKeyNoKey(t *testing.T) { func TestSQLSetTimestampKeyExists(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - gormDB, dbStore := SetUpSQLite(tempBaseDir, t, true) + gormDB, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) err = dbStore.SetTimestampKey("testGUN", "testCipher", []byte("1")) @@ -316,7 +316,7 @@ func TestSQLSetTimestampKeyExists(t *testing.T) { // both the tables are missing. func TestDBCheckHealthTableMissing(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - _, dbStore := SetUpSQLite(tempBaseDir, t, false) + _, dbStore := SetUpSQLite(t, tempBaseDir, false) defer os.RemoveAll(tempBaseDir) // No tables, health check fails @@ -338,7 +338,7 @@ func TestDBCheckHealthTableMissing(t *testing.T) { // health check fails. func TestDBCheckHealthDBConnectionFail(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - _, dbStore := SetUpSQLite(tempBaseDir, t, true) + _, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) err = dbStore.Close() @@ -352,7 +352,7 @@ func TestDBCheckHealthDBConnectionFail(t *testing.T) { // tables exist, the health check succeeds. func TestDBCheckHealthSucceeds(t *testing.T) { tempBaseDir, err := ioutil.TempDir("", "notary-test-") - _, dbStore := SetUpSQLite(tempBaseDir, t, true) + _, dbStore := SetUpSQLite(t, tempBaseDir, true) defer os.RemoveAll(tempBaseDir) err = dbStore.CheckHealth()