comptest

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 14 Imported by: 0

README

comptest

API will be unstable until major release.

The package aims to make component testing easier by providing a set of helper functions.

  • Build binary from your code and run it
  • Inject migrations with seed data
  • Run migrations up and down
  • Wait for database, mocks and main service to be ready
  • Prepare and use gcp pubsub. Send messages to pubsub.

Quickstart

Get package

go get github.com/ingridhq/comptest

And start using it:

func TestMain(t *testing.M) {
	// Initialize comptest lib.

	ctx, cancel := context.WithTimeout(context.Background(), 40 * time.Second)
	defer cancel()

	c := comptest.New(ctx)

	c.HealthChecks(
		waitfor.TCP(os.Getenv("PUBSUB_EMULATOR_HOST")),
	)

	c.BuildAndRun("../main.go", waitfor.HTTP(fmt.Sprintf("http://%s/readiness", cfg.ReadinessPort)))

	t.Run()
}

func Test_response(t *testing.T) {
	resp, _ := http.Get("http://localhost:8080/")

	if resp.StatusCode != http.StatusOK {
		t.Fatalf("unexpected status code : %v", resp.StatusCode)
	}
}

Full example can be found in _example directory. There you will learn how to use most of the package's functionality. You can run it with make.


Read more

You can read more about component testing here:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateGRPCConn

func CreateGRPCConn(addr string) (*grpc.ClientConn, error)

CreateGRPCConn will create grpc conn with disabled TLS.

func MustCreateGRPCConn

func MustCreateGRPCConn(addr string) *grpc.ClientConn

func MustStartGRPCServer

func MustStartGRPCServer(addr string, regFn func(s *grpc.Server))

MustStartGRPCServer will register and start grpc server.

func New

func New(ctx context.Context) *comptest

New create new comptests suite.

func PubsubMessageToProtoMessage added in v0.0.4

func PubsubMessageToProtoMessage(m *pubsub.Message) (ptypes.DynamicAny, error)

Types

type CleanupFunc

type CleanupFunc func()

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

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