Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 package db | |
| 2 | |
| 3 import ( | |
| 4 "testing" | |
| 5 "time" | |
| 6 | |
| 7 assert "github.com/stretchr/testify/require" | |
| 8 "go.skia.org/infra/go/testutils" | |
| 9 ) | |
| 10 | |
| 11 func testGetBuildsForCommits(t *testing.T, c *BuildCache, b *Build) { | |
|
dogben
2016/08/08 19:22:38
Is there any reason to test GetBuildsForCommits fo
borenet
2016/08/08 19:51:18
If ingestion is done correctly, we should never ha
dogben
2016/08/08 20:16:07
Sorry, I meant two builds for the same commit but
borenet
2016/08/09 11:22:55
Oh! Done.
| |
| 12 for _, commit := range b.Commits { | |
| 13 builds, err := c.GetBuildsForCommits([]string{commit}) | |
| 14 assert.NoError(t, err) | |
| 15 testutils.AssertDeepEqual(t, map[string]map[string]*Build{ | |
| 16 commit: map[string]*Build{ | |
| 17 b.Id: b, | |
| 18 }, | |
| 19 }, builds) | |
| 20 } | |
| 21 } | |
| 22 | |
| 23 func TestDBCache(t *testing.T) { | |
| 24 db := NewInMemoryDB() | |
| 25 defer testutils.AssertCloses(t, db) | |
| 26 | |
| 27 // Pre-load a build into the DB. | |
| 28 startTime := time.Now().Add(-30 * time.Minute) // Arbitrary starting poi nt. | |
| 29 b1 := makeBuild("build1", startTime, []string{"a", "b", "c", "d"}) | |
| 30 assert.NoError(t, db.PutBuild(b1)) | |
| 31 | |
| 32 // Create the cache. Ensure that the existing build is present. | |
| 33 c, err := NewBuildCache(db, time.Hour) | |
| 34 assert.NoError(t, err) | |
| 35 testGetBuildsForCommits(t, c, b1) | |
| 36 | |
| 37 // Bisect the first build. | |
| 38 b2 := makeBuild("build2", startTime.Add(time.Minute), []string{"c", "d"} ) | |
| 39 b1.Commits = []string{"a", "b"} | |
| 40 assert.NoError(t, db.PutBuilds([]*Build{b2, b1})) | |
| 41 assert.NoError(t, c.Update()) | |
| 42 | |
| 43 // Ensure that b2 (and not b1) shows up for commits "c" and "d". | |
| 44 testGetBuildsForCommits(t, c, b1) | |
| 45 testGetBuildsForCommits(t, c, b2) | |
| 46 } | |
| OLD | NEW |