common

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

README

SysEleven common library

Documentation goreportcard CI

This module hosts an array of convenience functionality aimed at infrastructure tests.

See docs

TODO
  • document thoroughly
  • CI: add gitlab-ci.yaml

Documentation

Overview

Package common provides frequently used metaphors to be used in infrastructure tests:

* means to define test suites with common setup and teardown functions * setting up and tearing down test environments * implicit handling of k8s access control * convenience for dealing with http connections and result verification

How to define a test suite:

// define a custom type
type SampleTestSuite struct {
}

// Setup is called once per suite
// before running any test
func (suite *SampleTestSuite) Setup(t *testing.T) {
	// suite setup code goes here
}

// TearDown is called once per suite
// after running all the tests
func (suite *SampleTestSuite) TearDown(t *testing.T) {
	// suite teardown code goes here
}

// individual tests must be prefixed with `InfraTest`

func (suite *SampleTestSuite) InfraTestSomething(t *testing.T) {
	// test code goes here
}

func (suite *SampleTestSuite) InfraTestSomethingElse(t *testing.T) {
	// test code goes here
}

// finally, add the main test function
func TestMain(t *testing.T) {
	s11.RunInfraTests(t, &SampleTestSuite{})
}

How to deal with setup/teardown:

import "code.syseleven.de/syseleven/common"

type SampleTestSuite struct {
	// keep the reference to the teardown
	// function returned by common.Setup
	teardown func(t *testing.T)
}

func (suite *SampleTestSuite) Setup(t *testing.T) {
	suite.teardown = common.Setup(t)
}

func (suite *SampleTestSuite) TearDown(t *testing.T) {
	suite.teardown(t)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractSimplePath

func ExtractSimplePath(data interface{}, path string) interface{}

func HTTPDoWithCustomValidation

func HTTPDoWithCustomValidation(t *testing.T, url string, validate func(int, string) bool)

func ProxyURL

func ProxyURL(t *testing.T, serviceName, portName string) string

func RunInfraTests

func RunInfraTests(t *testing.T, suite InfraTestSuite)

func Setup

func Setup(t *testing.T) func(t *testing.T)

func UnmarshalJSON

func UnmarshalJSON(data []byte) (map[string]interface{}, error)

func WaitUntilServiceAvailable

func WaitUntilServiceAvailable(t *testing.T, serviceName string)

Types

type HTTPProfile

type HTTPProfile struct {
	Token, Url string
	TLSConfig  *tls.Config
}

func GetHTTPProfile

func GetHTTPProfile(t *testing.T) *HTTPProfile

type InfraTestSuite

type InfraTestSuite interface {
	Setup(t *testing.T)
	TearDown(t *testing.T)
}

Jump to

Keyboard shortcuts

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