summaryrefslogtreecommitdiffstats
path: root/tests/internal/utils/database.go
blob: c32566b328da565c3b8137bcfac191bfdb15e806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package utils

import (
	"fmt"
	"github.com/icinga/icinga-testing"
	"github.com/icinga/icinga-testing/services"
	"os"
	"strings"
	"testing"
)

func GetDatabase(it *icingatesting.IT, t testing.TB) services.RelationalDatabase {
	k := "ICINGADB_TESTS_DATABASE_TYPE"
	v := strings.ToLower(os.Getenv(k))

	var rdb services.RelationalDatabase

	switch v {
	case "mysql":
		rdb = it.MysqlDatabaseT(t)
	case "pgsql":
		rdb = it.PostgresqlDatabaseT(t)
	default:
		panic(fmt.Sprintf(`unknown database in %s environment variable: %q (must be "mysql" or "pgsql")`, k, v))
	}

	return rdb
}