Documentation
¶
Overview ¶
Package icingatesting contains helpers to facilitate performing integration tests between components of the Icinga stack using the Go testing package. The general idea is to write test cases in Go that can dynamically spawn individual components as required, connect them and then perform checks on this setup. This is implemented by using the Docker API to start and stop containers locally as required by the tests.
The following environment variables are used by icinga-testing:
- ICINGA_TESTING_ICINGA2_IMAGE: Icinga 2 container image to use (default: "icinga/icinga2:master")
- ICINGA_TESTING_MYSQL_IMAGE: MySQL/MariaDB container image to use (default: "mysql:latest")
- ICINGA_TESTING_PGSQL_IMAGE: PostgreSQL container image to use (default: "postgres:latest")
- ICINGA_TESTING_REDIS_IMAGE: Redis container image to use (default: "redis:latest")
- ICINGA_TESTING_REDIS_MONITOR: If set to "1", log all Redis commands to the debug log using redis-cli monitor
- ICINGA_TESTING_ICINGADB_BINARY: Path to the Icinga DB binary to test. It will run in a container and therefore must be compiled using CGO_ENABLED=0
- ICINGA_TESTING_ICINGADB_SCHEMA_MYSQL: Path to the full Icinga DB schema file for MySQL/MariaDB
- ICINGA_TESTING_ICINGADB_SCHEMA_PGSQL: Path to the full Icinga DB schema file for PostgreSQL
Index ¶
- type IT
- func (it *IT) Cleanup()
- func (it *IT) Icinga2Node(name string) services.Icinga2
- func (it *IT) Icinga2NodeT(t testing.TB, name string) services.Icinga2
- func (it *IT) IcingaDbInstance(redis services.RedisServer, rdb services.RelationalDatabase, ...) services.IcingaDb
- func (it *IT) IcingaDbInstanceT(t testing.TB, redis services.RedisServer, rdb services.RelationalDatabase, ...) services.IcingaDb
- func (it *IT) Logger(t testing.TB) *zap.Logger
- func (it *IT) MysqlDatabase() services.MysqlDatabase
- func (it *IT) MysqlDatabaseT(t testing.TB) services.MysqlDatabase
- func (it *IT) PostgresqlDatabase() services.PostgresqlDatabase
- func (it *IT) PostgresqlDatabaseT(t testing.TB) services.PostgresqlDatabase
- func (it *IT) RedisServer() services.RedisServer
- func (it *IT) RedisServerT(t testing.TB) services.RedisServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IT ¶
type IT struct {
// contains filtered or unexported fields
}
IT is the core type to start interacting with this module.
The intended use is to create a global variable of type *IT in the test package and then initialize it in TestMain to allow the individual Test* functions to make use of it to dynamically start services as required:
var it *icingatesting.IT func TestMain(m *testing.M) { it = icingatesting.NewIT() defer it.Cleanup() m.Run() }
func (*IT) Cleanup ¶
func (it *IT) Cleanup()
Cleanup tears down everything that was started during the tests by this IT instance.
func (*IT) Icinga2Node ¶
Icinga2Node creates a new Icinga 2 node.
Each call to this function will spawn a dedicated Icinga 2 Docker container using the icinga/icinga2:master image.
func (*IT) Icinga2NodeT ¶
Icinga2NodeT creates a new Icinga 2 node and registers its cleanup function with testing.T.
func (*IT) IcingaDbInstance ¶
func (it *IT) IcingaDbInstance(redis services.RedisServer, rdb services.RelationalDatabase, options ...services.IcingaDbOption) services.IcingaDb
IcingaDbInstance starts a new Icinga DB instance.
It expects the ICINGA_TESTING_ICINGADB_BINARY environment variable to be set to the path of a precompiled icingadb binary which is then started in a new Docker container when this function is called.
func (*IT) IcingaDbInstanceT ¶
func (it *IT) IcingaDbInstanceT( t testing.TB, redis services.RedisServer, rdb services.RelationalDatabase, options ...services.IcingaDbOption, ) services.IcingaDb
IcingaDbInstanceT creates a new Icinga DB instance and registers its cleanup function with testing.T.
func (*IT) Logger ¶
Logger returns a *zap.Logger which additionally logs the current test case name.
func (*IT) MysqlDatabase ¶
func (it *IT) MysqlDatabase() services.MysqlDatabase
MysqlDatabase creates a new MySQL database and a user to access it.
The IT object will start a single MySQL Docker container on demand using the mysql:latest image and then creates multiple databases in it.
func (*IT) MysqlDatabaseT ¶
func (it *IT) MysqlDatabaseT(t testing.TB) services.MysqlDatabase
MysqlDatabaseT creates a new MySQL database and registers its cleanup function with testing.T.
func (*IT) PostgresqlDatabase ¶
func (it *IT) PostgresqlDatabase() services.PostgresqlDatabase
PostgresqlDatabase creates a new PostgreSQL database and a user to access it.
The IT object will start a single PostgreSQL Docker container on demand using the postgres:latest image and then creates multiple databases in it.
func (*IT) PostgresqlDatabaseT ¶
func (it *IT) PostgresqlDatabaseT(t testing.TB) services.PostgresqlDatabase
PostgresDatabaseT creates a new MySQL database and registers its cleanup function with testing.T.
func (*IT) RedisServer ¶
func (it *IT) RedisServer() services.RedisServer
RedisServer creates a new Redis server.
Each call to this function will spawn a dedicated Redis Docker container using the redis:latest image.
func (*IT) RedisServerT ¶
func (it *IT) RedisServerT(t testing.TB) services.RedisServer
RedisServerT creates a new Redis server and registers its cleanup function with testing.T.