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

Side by Side Diff: golden/go/expstorage/expstorage_test.go

Issue 813443002: Overhaul database package (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Fix newline in password Created 6 years 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 unified diff | Download patch
OLDNEW
1 package expstorage 1 package expstorage
2 2
3 import ( 3 import (
4 "testing" 4 "testing"
5 ) 5 )
6 6
7 import ( 7 import (
8 // Using 'require' which is like using 'assert' but causes tests to fail . 8 // Using 'require' which is like using 'assert' but causes tests to fail .
9 assert "github.com/stretchr/testify/require" 9 assert "github.com/stretchr/testify/require"
10 10
11 "skia.googlesource.com/buildbot.git/go/database" 11 "skia.googlesource.com/buildbot.git/go/database"
12 "skia.googlesource.com/buildbot.git/go/database/testutil" 12 "skia.googlesource.com/buildbot.git/go/database/testutil"
13 "skia.googlesource.com/buildbot.git/golden/go/db" 13 "skia.googlesource.com/buildbot.git/golden/go/db"
14 "skia.googlesource.com/buildbot.git/golden/go/types" 14 "skia.googlesource.com/buildbot.git/golden/go/types"
15 ) 15 )
16 16
17 func TestExpectationStores(t *testing.T) { 17 func TestMySQLExpectationsStore(t *testing.T) {
18 » // Test the memory store. 18 » // Set up the test database.
19 » memStore := NewMemExpectationsStore() 19 » testDb := testutil.SetupMySQLTestDatabase(t, db.MigrationSteps())
20 » testExpectationStore(t, memStore) 20 » defer testDb.Close()
21 21
22 » // Initialize the DB to use a local SQLite instances. 22 » conf := testutil.LocalTestDatabaseConfig(db.MigrationSteps())
23 » vdb := database.NewVersionedDB(&database.DatabaseConfig{
24 » » SQLiteFilePath: "correctness.db",
25 » » MigrationSteps: db.MigrationSteps(),
26 » })
27 » sqlStore := NewSQLExpectationStore(vdb)
28 » testExpectationStore(t, sqlStore)
29 }
30
31 func TestMySQLExpecatationsStore(t *testing.T) {
32 » // Set up the database and make sure it's at the right version.
33 » conf := &database.DatabaseConfig{
34 » » MySQLString: testutil.GetTestMySQLConnStr(t, "root", "correct ness"),
35 » » MigrationSteps: db.MigrationSteps(),
36 » }
37
38 » // Lock to serialize DB tests
39 » lockVdb := testutil.GetMySQlLock(t, conf)
40 » defer func() {
41 » » testutil.ReleaseMySQLLock(t, lockVdb)
42 » » lockVdb.Close()
43 » }()
44
45 » rootVdb := database.NewVersionedDB(conf)
46 » rootVdb.Migrate(rootVdb.MaxDBVersion())
47 » defer func() {
48 » » rootVdb.Migrate(0)
49 » }()
50
51 » conf.MySQLString = testutil.GetTestMySQLConnStr(t, "readwrite", "correct ness")
52 vdb := database.NewVersionedDB(conf) 23 vdb := database.NewVersionedDB(conf)
jcgregorio 2014/12/19 20:27:06 Why not make MySQLTestDatabase rootVdb public and
borenet 2014/12/19 20:39:15 That would work, but the test would be running as
53 24
54 // Test the MySQL backed store 25 // Test the MySQL backed store
55 sqlStore := NewSQLExpectationStore(vdb) 26 sqlStore := NewSQLExpectationStore(vdb)
56 testExpectationStore(t, sqlStore) 27 testExpectationStore(t, sqlStore)
57 28
58 // Test the caching version of the MySQL store. 29 // Test the caching version of the MySQL store.
59 cachingStore := NewCachingExpectationStore(sqlStore) 30 cachingStore := NewCachingExpectationStore(sqlStore)
60 testExpectationStore(t, cachingStore) 31 testExpectationStore(t, cachingStore)
61 } 32 }
62 33
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 assert.Equal(t, types.TestClassification(map[string]types.Label{DIGEST_2 1: types.POSITIVE}), foundExps.Tests[TEST_2]) 76 assert.Equal(t, types.TestClassification(map[string]types.Label{DIGEST_2 1: types.POSITIVE}), foundExps.Tests[TEST_2])
106 77
107 changeExps.RemoveDigests([]string{DIGEST_12}) 78 changeExps.RemoveDigests([]string{DIGEST_12})
108 err = store.Put(changeExps, "user-3") 79 err = store.Put(changeExps, "user-3")
109 assert.Nil(t, err) 80 assert.Nil(t, err)
110 81
111 foundExps, err = store.Get(false) 82 foundExps, err = store.Get(false)
112 assert.Nil(t, err) 83 assert.Nil(t, err)
113 assert.Equal(t, 1, len(foundExps.Tests)) 84 assert.Equal(t, 1, len(foundExps.Tests))
114 } 85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698