// clearDB initializes the database, upgrading it if needed, and removes all // data to ensure that the test begins with a clean slate. Returns a MySQLTestDatabase // which must be closed after the test finishes. func clearDB(t *testing.T) *testutil.MySQLTestDatabase { failMsg := "Database initialization failed. Do you have the test database set up properly? Details: %v" // Set up the database. testDb := testutil.SetupMySQLTestDatabase(t, migrationSteps) conf := testutil.LocalTestDatabaseConfig(migrationSteps) var err error DB, err = sqlx.Open("mysql", conf.MySQLString()) assert.Nil(t, err, failMsg) return testDb }
func TestTrybotIngester(t *testing.T) { // Set up the test database. testDb := testutil.SetupMySQLTestDatabase(t, db.MigrationSteps()) defer testDb.Close(t) conf := testutil.LocalTestDatabaseConfig(db.MigrationSteps()) vdb, err := conf.NewVersionedDB() assert.Nil(t, err) Init(vdb) resultStore := NewTrybotResultStorage(vdb) // Get the constructor and create an instance of gold-trybot ingester. tbIngester := ingester.Constructor(config.CONSTRUCTOR_GOLD_TRYBOT)() _ = ingestFile(t, tbIngester, TEST_FILE) tries, err := resultStore.Get(TEST_ISSUE) assert.Nil(t, err) assert.Equal(t, 1, len(tries.Bots)) var targetBot *BotResults for _, v := range tries.Bots { assert.Equal(t, len(TEST_DIGESTS), len(v.TestResults)) targetBot = v } for _, entry := range targetBot.TestResults { assert.True(t, TEST_DIGESTS[tries.Digests[entry.DigestIdx]]) } allIssues, _, err := resultStore.List(0, 10) assert.Nil(t, err) assert.Equal(t, 1, len(allIssues)) assert.Equal(t, TEST_ISSUE, allIssues[0].Issue) time.Sleep(time.Second) _ = ingestFile(t, tbIngester, TEST_FILE_2) tries, err = resultStore.Get(TEST_ISSUE) assert.Nil(t, err) assert.Equal(t, 1, len(tries.Bots)) assert.Equal(t, 1, len(tries.Digests)) assert.Equal(t, MODIFIED_DIGEST, tries.Digests[0]) for _, bot := range tries.Bots { for _, result := range bot.TestResults { assert.Equal(t, MODIFIED_DIGEST, result.digest) assert.Equal(t, 0, result.DigestIdx) } } }
func TestSQLIgnoreStore(t *testing.T) { // Set up the database. This also locks the db until this test is finished // causing similar tests to wait. migrationSteps := db.MigrationSteps() mysqlDB := testutil.SetupMySQLTestDatabase(t, migrationSteps) defer mysqlDB.Close(t) vdb, err := testutil.LocalTestDatabaseConfig(migrationSteps).NewVersionedDB() assert.Nil(t, err) defer testutils.AssertCloses(t, vdb) store := NewSQLIgnoreStore(vdb) testIgnoreStore(t, store) }
func TestMySQLExpectationsStore(t *testing.T) { // Set up the test database. testDb := testutil.SetupMySQLTestDatabase(t, db.MigrationSteps()) defer testDb.Close(t) conf := testutil.LocalTestDatabaseConfig(db.MigrationSteps()) vdb, err := conf.NewVersionedDB() assert.Nil(t, err) // Test the MySQL backed store sqlStore := NewSQLExpectationStore(vdb) testExpectationStore(t, sqlStore, nil) // Test the caching version of the MySQL store. eventBus := eventbus.New(nil) cachingStore := NewCachingExpectationStore(sqlStore, eventBus) testExpectationStore(t, cachingStore, eventBus) }
func TestTrybotIngester(t *testing.T) { // Set up the test database. testDb := testutil.SetupMySQLTestDatabase(t, db.MigrationSteps()) defer testDb.Close(t) conf := testutil.LocalTestDatabaseConfig(db.MigrationSteps()) vdb, err := conf.NewVersionedDB() assert.Nil(t, err) Init(vdb) // Get the constructor and create an instance of gold-trybot ingester. tbIngester := ingester.Constructor(config.CONSTRUCTOR_GOLD_TRYBOT)() _ = ingestFile(t, tbIngester, TEST_FILE) tries, err := Get(vdb, TEST_ISSUE) assert.Nil(t, err) assert.Equal(t, len(TEST_DIGESTS), len(tries)) for _, entry := range tries { assert.True(t, TEST_DIGESTS[entry.Digest]) } allIssues, err := List(vdb, 10) assert.Nil(t, err) assert.Equal(t, 1, len(allIssues)) assert.Equal(t, TEST_ISSUE, allIssues[0]) time.Sleep(time.Second) _ = ingestFile(t, tbIngester, TEST_FILE_2) tries, err = Get(vdb, TEST_ISSUE) assert.Nil(t, err) assert.Equal(t, len(TEST_DIGESTS), len(tries)) for _, entry := range tries { assert.Equal(t, MODIFIED_DIGEST, entry.Digest) } }