testutil

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package testutil provides helpers for running the conduit integration tests.

All helpers are defined as functions on the TestHelper struct, which you should instantiate once per test, using the NewTestHelper function. Since that function also parses command line flags, it should be called as part of your test's TestMain function. For example:

package mytest

import (
	"os"
	"testing"

	"github.com/runconduit/conduit/testutil"
)

var TestHelper *util.TestHelper

func TestMain(m *testing.M) {
  TestHelper = util.NewTestHelper()
  os.Exit(m.Run())
}

func TestMyTest(t *testing.T) {
	// add test code here
}

Calling NewTestHelper adds the following command line flags:

-conduit string
		path to the conduit binary to test
-conduit-namespace string
		the namespace where conduit is installed (default "conduit")
-integration-tests
	must be provided to run the integration tests

Note that the -integration-tests flag must be set when running tests, so that the tests aren't inadvertently executed when unit tests for the project are run.

TestHelper embeds KubernetesHelper, so all functions defined on KubernetesHelper are also available to instances of TestHelper. See the individual function definitions for details on how to use each helper in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KubernetesHelper

type KubernetesHelper struct {
	// contains filtered or unexported fields
}

KubernetesHelper provides Kubernetes-related test helpers. It connects to the Kubernetes API using the environment's configured kubeconfig file.

func NewKubernetesHelper

func NewKubernetesHelper() (*KubernetesHelper, error)

NewKubernetesHelper creates a new instance of KubernetesHelper.

func (*KubernetesHelper) CheckDeployment

func (h *KubernetesHelper) CheckDeployment(namespace string, deploymentName string, replicas int) error

CheckDeployment checks that a deployment in a namespace contains the expected number of replicas.

func (*KubernetesHelper) CheckIfNamespaceExists

func (h *KubernetesHelper) CheckIfNamespaceExists(namespace string) error

CheckIfNamespaceExists checks if a namespace exists.

func (*KubernetesHelper) CheckPods

func (h *KubernetesHelper) CheckPods(namespace string, deploymentName string, replicas int) error

CheckPods checks that a deployment in a namespace contains the expected number of pods in the Running state.

func (*KubernetesHelper) CheckService

func (h *KubernetesHelper) CheckService(namespace string, serviceName string) error

CheckService checks that a service exists in a namespace.

func (*KubernetesHelper) CreateNamespaceIfNotExists

func (h *KubernetesHelper) CreateNamespaceIfNotExists(namespace string) error

CreateNamespaceIfNotExists creates a namespace if it does not already exist.

func (*KubernetesHelper) GetJobStatus

func (h *KubernetesHelper) GetJobStatus(namespace, jobName string) (string, error)

GetJobStatus gets the status of a job running in a namespace. If the job does not exist it return an error.

func (*KubernetesHelper) KubectlApply

func (h *KubernetesHelper) KubectlApply(stdin string, namespace string) (string, error)

KubectlApply applies a given configuration string in a namespace. If the namespace does not exist, it creates it first. If no namespace is provided, it uses the default namespace.

func (*KubernetesHelper) ParseNamespacedResource

func (h *KubernetesHelper) ParseNamespacedResource(resource string) (string, string, error)

ParseNamespacedResource extracts a namespace and resource name from a string that's in the format namespace/resource. If the strings is in a different format it returns an error.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream provides the ability of read the output of an executing process while it is still running

func (*Stream) ReadUntil

func (s *Stream) ReadUntil(lineCount int, timeout time.Duration) ([]string, error)

ReadUntil reads from the process output until specified number of lines has been reached, or until a timeout

func (*Stream) Stop

func (s *Stream) Stop()

Stop closes the stream and kills the process

type TestHelper

type TestHelper struct {
	KubernetesHelper
	// contains filtered or unexported fields
}

TestHelper provides helpers for running the conduit integration tests.

func NewTestHelper

func NewTestHelper() *TestHelper

NewTestHelper creates a new instance of TestHelper for the current test run. The new TestHelper can be configured via command line flags.

func (*TestHelper) BlockUntilTrue

func (h *TestHelper) BlockUntilTrue(timeout time.Duration, fn func() bool) error

BlockUntilTrue retries a given function every second until the function returns true or a timeout is reached. If the timeout is reached, it returns an error.

func (*TestHelper) CheckVersion

func (h *TestHelper) CheckVersion(serverVersion string) error

CheckVersion validates the the output of the "conduit version" command.

func (*TestHelper) CombinedOutput

func (h *TestHelper) CombinedOutput(name string, arg ...string) (string, error)

CombinedOutput executes a shell command and returns the output.

func (*TestHelper) ConduitRun

func (h *TestHelper) ConduitRun(arg ...string) (string, error)

ConduitRun executes a conduit command appended with the --conduit-namespace flag.

func (*TestHelper) ConduitRunStream

func (h *TestHelper) ConduitRunStream(arg ...string) (*Stream, error)

ConduitRunStream initiates a conduit command appended with the --conduit-namespace flag, and returns a Stream that can be used to read the command's output while it is still executing.

func (*TestHelper) GetConduitNamespace

func (h *TestHelper) GetConduitNamespace() string

GetConduitNamespace returns the namespace where conduit is installed. Set the namespace using the -conduit-namespace command line flag.

func (*TestHelper) GetTestNamespace

func (h *TestHelper) GetTestNamespace(testName string) string

GetTestNamespace returns the namespace for the given test. The test namespace is prefixed with the conduit namespace.

func (*TestHelper) GetURLForService

func (h *TestHelper) GetURLForService(namespace string, serviceName string) (string, error)

GetURLForService returns the external URL for a service in a namespace.

func (*TestHelper) GetVersion

func (h *TestHelper) GetVersion() string

GetVersion returns the version of conduit to test. This version corresponds to the client version of the conduit binary provided via the -conduit command line flag.

func (*TestHelper) HTTPGetURL

func (h *TestHelper) HTTPGetURL(url string) (string, error)

HTTPGetURL sends a GET request to the given URL. It returns the response body in the event of a successful 200 response. In the event of a non-200 response, it returns an error.

func (*TestHelper) RetryFor

func (h *TestHelper) RetryFor(timeout time.Duration, fn func() error) error

RetryFor retries a given function every second until the function returns without an error, or a timeout is reached. If the timeout is reached, it returns the last error received from the function.

func (*TestHelper) ValidateOutput

func (h *TestHelper) ValidateOutput(out, fixtureFile string) error

ValidateOutput validates a string against the contents of a file in the test's testdata directory.

Jump to

Keyboard shortcuts

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