Documentation
¶
Index ¶
- func SetupEtcd(testName string) (string, error)
- func SetupPostgresDatabase(testName string) (*sql.DB, *database.PostgresDatabaseSettings, error)
- func SetupRabbitMQ(testName string) (string, error)
- func SetupRabbitMQWithTimeOut(testName string, timeOut time.Duration) (string, error)
- func SetupRedis(testName string) (*goredis.Options, error)
- func TeardownEtcd(testName string) error
- func TeardownKafka(testName string)
- func TeardownMSSqlDatabase(testName string) error
- func TeardownPostgresDatabase(testName string) error
- func TeardownRabbitMQ(testName string) error
- func TeardownRedis(testName string) error
- type DatabaseSetup
- type KafkaSetup
- type MSSqlDatabaseSettings
- type NoOpLogger
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetupEtcd ¶
SetupEtcd sets up a etcd database
Example ¶
package main import ( "fmt" "github.com/syncromatics/go-kit/v2/testing/docker" ) func main() { etcdURL, err := docker.SetupEtcd("test") if err != nil { panic(err) } fmt.Printf("etcdURL is set: %t\n", etcdURL != "") /* cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{etcdURL}, DialTimeout: 5*time.Second, }) if err != nil { panic(err) } // snip err = cli.Close() if err != nil { panic(err) } */ docker.TeardownEtcd("test") }
Output: etcdURL is set: true
func SetupPostgresDatabase ¶
SetupPostgresDatabase sets up a postgres database
Example ¶
package main import ( "github.com/syncromatics/go-kit/v2/testing/docker" ) func main() { db, _, err := docker.SetupPostgresDatabase("test") if err != nil { panic(err) } err = db.Ping() if err != nil { panic(err) } err = db.Close() if err != nil { panic(err) } docker.TeardownPostgresDatabase("test") }
Output:
func SetupRabbitMQ ¶
Example ¶
package main import ( "fmt" "github.com/syncromatics/go-kit/v2/testing/docker" ) func main() { amqpURL, err := docker.SetupRabbitMQ("test") if err != nil { panic(err) } fmt.Printf("amqpURL is set: %t\n", amqpURL != "") /* conn, err := amqp.Dial(amqpURL) if err != nil { panic(err) } // snip err = conn.Close() if err != nil { panic(err) } */ docker.TeardownRabbitMQ("test") }
Output: amqpURL is set: true
func SetupRabbitMQWithTimeOut ¶ added in v2.2.1
SetupRabbitMQ sets up a RabbitMQ broker
Example ¶
package main import ( "fmt" "time" "github.com/syncromatics/go-kit/v2/testing/docker" ) func main() { timeOut := 30 * time.Second amqpURL, err := docker.SetupRabbitMQWithTimeOut("test", timeOut) if err != nil { panic(err) } fmt.Printf("amqpURL is set: %t\n", amqpURL != "") /* conn, err := amqp.Dial(amqpURL) if err != nil { panic(err) } // snip err = conn.Close() if err != nil { panic(err) } */ docker.TeardownRabbitMQ("test") }
Output: amqpURL is set: true
func SetupRedis ¶
SetupRedis sets up a redis store
Example ¶
package main import ( "github.com/syncromatics/go-kit/v2/redis" "github.com/syncromatics/go-kit/v2/testing/docker" ) func main() { options, err := docker.SetupRedis("test") if err != nil { panic(err) } err = redis.WaitForRedisToBeOnline(options, 10) if err != nil { panic(err) } docker.TeardownRedis("test") }
Output:
func TeardownKafka ¶
func TeardownKafka(testName string)
TeardownKafka will remove the containers of the test kafka setup
func TeardownMSSqlDatabase ¶
TeardownMSSqlDatabase tears down the Microsoft SQL Server database
func TeardownPostgresDatabase ¶
TeardownPostgresDatabase tears down the postgres db
func TeardownRabbitMQ ¶
TeardownRabbitMQ tears down the RabbitMQ broker
func TeardownRedis ¶
TeardownRedis tears down the redis store
Types ¶
type DatabaseSetup ¶
type DatabaseSetup struct { TestName string DatabaseImage *string UserName string Password string DatabaseName *string }
DatabaseSetup is the settings for the test database
type KafkaSetup ¶
KafkaSetup is the details about the kafka setup
func SetupKafka ¶
func SetupKafka(testName string) (*KafkaSetup, error)
SetupKafka sets up the zookeeper and kafka test containers
Example ¶
package main import ( "fmt" "github.com/syncromatics/go-kit/v2/testing/docker" ) func main() { setup, err := docker.SetupKafka("test") if err != nil { panic(err) } fmt.Printf("Kafka broker and proto registry hosts are set: %t", setup.ExternalBroker != "" && setup.ProtoRegistry != "") docker.TeardownKafka("test") }
Output: Kafka broker and proto registry hosts are set: true
type MSSqlDatabaseSettings ¶
MSSqlDatabaseSettings is the settings for the database
func SetupMSSqlDatabase ¶
func SetupMSSqlDatabase(setup DatabaseSetup) (*MSSqlDatabaseSettings, error)
SetupMSSqlDatabase sets up a Microsoft SQL Server database
Example ¶
package main import ( "github.com/syncromatics/go-kit/v2/testing/docker" ) func main() { settings, err := docker.SetupMSSqlDatabase(docker.DatabaseSetup{ TestName: "test", UserName: "sa", Password: "superS3cureP@ssword", // The Microsoft SQL Server image has password complexity requirements by default }) if err != nil { panic(err) } db, err := settings.GetDB() if err != nil { panic(err) } err = db.Ping() if err != nil { panic(err) } err = db.Close() if err != nil { panic(err) } docker.TeardownMSSqlDatabase("test") }
Output:
func (*MSSqlDatabaseSettings) GetDB ¶
func (ds *MSSqlDatabaseSettings) GetDB() (*sql.DB, error)
GetDB will return a database instance from the settings
func (*MSSqlDatabaseSettings) WaitForDatabaseToBeOnline ¶
func (ds *MSSqlDatabaseSettings) WaitForDatabaseToBeOnline(secondsToWait int) error
WaitForDatabaseToBeOnline will wait for the database server to be online for the given seconds.
type NoOpLogger ¶
type NoOpLogger struct{}
NoOpLogger is a logger that does nothing
func (*NoOpLogger) Panicf ¶
func (l *NoOpLogger) Panicf(msg string, args ...interface{})
Panicf will panic