docker

package
v2.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupEtcd

func SetupEtcd(testName string) (string, error)

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

func SetupPostgresDatabase(testName string) (*sql.DB, *database.PostgresDatabaseSettings, error)

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

func SetupRabbitMQ(testName string) (string, error)
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

func SetupRabbitMQWithTimeOut(testName string, timeOut time.Duration) (string, error)

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

func SetupRedis(testName string) (*goredis.Options, error)

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 TeardownEtcd

func TeardownEtcd(testName string) error

TeardownEtcd tears down the etcd db

func TeardownKafka

func TeardownKafka(testName string)

TeardownKafka will remove the containers of the test kafka setup

func TeardownMSSqlDatabase

func TeardownMSSqlDatabase(testName string) error

TeardownMSSqlDatabase tears down the Microsoft SQL Server database

func TeardownPostgresDatabase

func TeardownPostgresDatabase(testName string) error

TeardownPostgresDatabase tears down the postgres db

func TeardownRabbitMQ

func TeardownRabbitMQ(testName string) error

TeardownRabbitMQ tears down the RabbitMQ broker

func TeardownRedis

func TeardownRedis(testName string) error

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

type KafkaSetup struct {
	ExternalBroker string
	ProtoRegistry  string
}

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

type MSSqlDatabaseSettings struct {
	Host     string
	Port     int
	User     string
	Password string
	Name     *string
}

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

func (*NoOpLogger) Printf

func (l *NoOpLogger) Printf(string, ...interface{})

Printf does nothing

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL