Skip to content

Commit

Permalink
Integration tests: don't hard-code MySQL in some tests
Browse files Browse the repository at this point in the history
Some test cases always used a MySQL database as they didn't use the proper
function which would respect the ICINGADB_TESTS_DATABASE_TYPE=pgsql environment
variable. This commit fixes this and updates a similarly left-over error
message as well.
  • Loading branch information
julianbrost committed Mar 18, 2024
1 parent 6c7e94e commit c1be108
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
11 changes: 4 additions & 7 deletions tests/history_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ func BenchmarkHistory(b *testing.B) {
}

func benchmarkHistory(b *testing.B, numComments int64) {
m := it.MysqlDatabase()
defer m.Cleanup()
m.ImportIcingaDbSchema()

rdb := getDatabase(b)
r := it.RedisServer()
defer r.Cleanup()
n := it.Icinga2Node("master")
Expand All @@ -39,8 +36,8 @@ func benchmarkHistory(b *testing.B, numComments int64) {
err := n.Reload()
require.NoError(b, err, "icinga2 should reload without error")

db, err := sqlx.Connect("mysql", m.DSN())
require.NoError(b, err, "connecting to mysql")
db, err := sqlx.Connect(rdb.Driver(), rdb.DSN())
require.NoError(b, err, "connecting to database")
defer func() { _ = db.Close() }()

redisClient := r.Open()
Expand Down Expand Up @@ -97,7 +94,7 @@ func benchmarkHistory(b *testing.B, numComments int64) {
b.Logf("current stream length: %d", lastPending)

b.StartTimer()
idb := it.IcingaDbInstance(r, m)
idb := it.IcingaDbInstance(r, rdb)
defer idb.Cleanup()

ticker := time.NewTicker(5 * time.Millisecond)
Expand Down
2 changes: 1 addition & 1 deletion tests/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func testHistory(t *testing.T, numNodes int) {
}, 15*time.Second, 200*time.Millisecond)

db, err := sqlx.Connect(rdb.Driver(), rdb.DSN())
require.NoError(t, err, "connecting to mysql")
require.NoError(t, err, "connecting to database")
t.Cleanup(func() { _ = db.Close() })

client := nodes[0].IcingaClient
Expand Down
13 changes: 6 additions & 7 deletions tests/sla_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import (
)

func TestSla(t *testing.T) {
m := it.MysqlDatabaseT(t)
m.ImportIcingaDbSchema()
rdb := getDatabase(t)

r := it.RedisServerT(t)
i := it.Icinga2NodeT(t, "master")
i.EnableIcingaDb(r)
err := i.Reload()
require.NoError(t, err, "icinga2 should reload without error")
it.IcingaDbInstanceT(t, r, m)
it.IcingaDbInstanceT(t, r, rdb)

client := i.ApiClient()

Expand Down Expand Up @@ -109,8 +108,8 @@ func TestSla(t *testing.T) {

assert.Equal(t, 3, len(stateChanges), "there should be three hard state changes")

db, err := sqlx.Connect("mysql", m.DSN())
require.NoError(t, err, "connecting to mysql")
db, err := sqlx.Connect(rdb.Driver(), rdb.DSN())
require.NoError(t, err, "connecting to database")
defer func() { _ = db.Close() }()

type Row struct {
Expand Down Expand Up @@ -248,8 +247,8 @@ func TestSla(t *testing.T) {
End int64 `db:"downtime_end"`
}

db, err := sqlx.Connect("mysql", m.DSN())
require.NoError(t, err, "connecting to mysql")
db, err := sqlx.Connect(rdb.Driver(), rdb.DSN())
require.NoError(t, err, "connecting to database")
defer func() { _ = db.Close() }()

if !o.Fixed {
Expand Down

0 comments on commit c1be108

Please sign in to comment.