e2e

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2019 License: Apache-2.0 Imports: 43 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

Note that if you plan on running metrics-related E2E tests using the StackDriver backend, you need to give your Service Account the Monitoring Editor role on your Google Cloud project:

gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:cloudrunevents-pullsub@$PROJECT_ID.iam.gserviceaccount.com \
--role roles/monitoring.editor

Documentation

Index

Constants

View Source
const (
	ProwProjectKey = "E2E_PROJECT_ID"
)

Variables

This section is empty.

Functions

func BrokerWithPubSubChannelTestImpl added in v0.11.0

func BrokerWithPubSubChannelTestImpl(t *testing.T, packages map[string]string)

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 KoPublish added in v0.9.0

func KoPublish(pack string) (string, error)

func ParseTemplates

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

func PubSubWithTargetTestImpl added in v0.10.0

func PubSubWithTargetTestImpl(t *testing.T, packages map[string]string, assertMetrics bool)

PubSubWithTargetTestImpl tests we can receive an event from PubSub. If assertMetrics is set to true, we also assert for StackDriver metrics.

func PullSubscriptionWithTargetTestImpl added in v0.9.0

func PullSubscriptionWithTargetTestImpl(t *testing.T, packages map[string]string)

PullSubscriptionWithTargetTestImpl tests we can receive an event from a PullSubscription.

func SmokePubSubTestImpl added in v0.10.0

func SmokePubSubTestImpl(t *testing.T)

SmokePubSubTestImpl tests we can create a pubsub to ready state.

func SmokePullSubscriptionTestImpl

func SmokePullSubscriptionTestImpl(t *testing.T)

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

func SmokeTestChannelImpl added in v0.9.0

func SmokeTestChannelImpl(t *testing.T)

SmokeTestChannelImpl makes sure we can run tests.

func StorageWithTestImpl added in v0.10.0

func StorageWithTestImpl(t *testing.T, packages map[string]string, assertMetrics bool)

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) LogsFor added in v0.9.0

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

func (*Client) SetupStackDriverMetrics added in v0.10.0

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

func (*Client) StackDriverEventCountMetricFor added in v0.10.0

func (c *Client) StackDriverEventCountMetricFor(namespace, projectID, filter string) (*int64, error)

TODO make this function more generic.

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.

func (*Client) WaitUntilJobDone added in v0.9.0

func (c *Client) WaitUntilJobDone(namespace, name string) (string, 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 TargetOutput added in v0.9.0

type TargetOutput struct {
	Success bool `json:"success"`
}

type YamlPathsOptionFunc

type YamlPathsOptionFunc func([]string) []string

YamlPathsOptionFunc allows for bulk mutation of the yaml paths.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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