e2e

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: Apache-2.0 Imports: 27 Imported by: 0

README

E2E Tests

Prow will run ./e2e-tests.sh.

Adding E2E Tests

E2E tests are tagged with // +build e2e but tagging a go file this way will prevent the compiler from compiling the test code. To work around this, for the SmokeTest we will have two files:

test/e2e
├── smoke.go
└── smoke_test.go
  • smoke_test.go is the testing file entry point (tagged with e2e).
  • smoke.go is the test implementation (not tagged with e2e).

For SmokeTest, we will try an experimental way to implement e2e tests, we will use lightly templatized yaml files to create the testing setup. And then go to observe the results.

SmokeTest uses yaml files in config/smoke_test/* like this:

test/e2e
├── config
│   └── smoke_test
│       └── smoke-test.yaml
├── smoke.go
└── smoke_test.go

The SmokeTest test reads in all of these yamls and passes them through a golang template processor:

	yamls := fmt.Sprintf("%s/config/smoke_test/", filepath.Dir(filename))
	installer := NewInstaller(client.Dynamic, map[string]string{
		"namespace": client.Namespace,
	}, yamls)

The map[string]string above is the template parameters that will be used for the yaml files.

The test then uses installer like you might think about using kubectl to setup the test namespace:

	// Create the resources for the test.
	if err := installer.Do("create"); err != nil {
		t.Errorf("failed to create, %s", err)
	}

This is similar to kubectl create -f ./config/smoke_test after the templates have been processed.

After this point, you can write tests and interact with the cluster and resources like normal. SmokeTest uses a dynamic client, but you can add typed clients if you wish.

To run manually using go test and an existing cluster

go test --tags=e2e ./test/e2e/...

And count is supported too:

go test --tags=e2e ./test/e2e/... --count=3

If you want to run a specific test:

go test --tags=e2e ./test/e2e/... -run NameOfTest

For example, to run TestPullSubscription:

GOOGLE_APPLICATION_CREDENTIALS=<path to json creds file> \
E2E_PROJECT_ID=<project name> \
  go test --tags=e2e ./test/e2e/... -run TestPullSubscription

Documentation

Index

Constants

View Source
const (
	ProwProjectKey = "E2E_PROJECT_ID"
)

Variables

This section is empty.

Functions

func DeleteNameSpace

func DeleteNameSpace(client *Client) error

DeleteNameSpace deletes the namespace that has the given name.

func EndToEndConfigYaml

func EndToEndConfigYaml(paths []string, options ...YamlPathsOptionFunc) []string

EndToEndConfigYaml assembles yaml from the local config directory. Note: `config` dir is assumed to be relative to the caller path.

func ParseTemplates

func ParseTemplates(path string, config map[string]string) string

func SmokePullSubscriptionTestImpl

func SmokePullSubscriptionTestImpl(t *testing.T)

SmokePullSubscriptionTestImpl tests we can create a pull subscription to ready state.

func SmokeTestImpl

func SmokeTestImpl(t *testing.T)

SmokeTestImpl makes sure we can run tests.

func TearDown

func TearDown(client *Client)

TearDown will delete created names using clients.

Types

type Client

type Client struct {
	Kube    *test.KubeClient
	Dynamic dynamic.Interface

	Namespace string
	T         *testing.T
}

Client holds instances of interfaces for making requests to Knative.

func NewClient

func NewClient(configPath string, clusterName string, namespace string, t *testing.T) (*Client, error)

NewClient instantiates and returns clientsets required for making request to the cluster specified by the combination of clusterName and configPath.

func Setup

func Setup(t *testing.T, runInParallel bool) *Client

Setup creates the client objects needed in the e2e tests, and does other setups, like creating namespaces, set the test case to run in parallel, etc.

func (*Client) CreateNamespaceIfNeeded

func (c *Client) CreateNamespaceIfNeeded(t *testing.T)

CreateNamespaceIfNeeded creates a new namespace if it does not exist.

func (*Client) DuplicateSecret

func (c *Client) DuplicateSecret(t *testing.T, name, namespace string)

DuplicateSecret duplicates a secret from a namespace to a new namespace.

func (*Client) WaitForResourceReady

func (c *Client) WaitForResourceReady(namespace, name string, gvr schema.GroupVersionResource) error

WaitForResourceReady waits until the specified resource in the given namespace are ready.

type Installer

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

func NewInstaller

func NewInstaller(dc dynamic.Interface, config map[string]string, paths ...string) *Installer

func (*Installer) Do

func (r *Installer) Do(verb string) error

type YamlPathsOptionFunc

type YamlPathsOptionFunc func([]string) []string

YamlPathsOptionFunc allows for bulk mutation of the yaml paths.

Jump to

Keyboard shortcuts

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