Pipelines

A pipeline gathers one or more requests that must be executed in order within the same test flow.

Each step contains a request and, optionally, an expectation. GOX retains the session and cookies between the steps to reproduce dependent interactions.


ExecutePipeLine

test.ExecutePipeLine contains two properties:

PropertyDescription
RequestHTTP request or Action request.
ExpectedContract for the reply.

One HTTP request use test.NewResponseExpected; one Action use test.NewResponseActionExpected.


Simple pipeline

gox
pipeline := []test.ExecutePipeLine{
	{
		Request: test.NewRequest{Method: test.GET, URL: "/index"},
		Expected: test.NewResponseExpected{
			Status: 200,
			Body: test.ExpectedBody.Contains("Hello Gox"),
		},
	},
}

result, match := test.Execute(test.Config{}, pipeline)

match will be true only if all the steps were implemented and met their expectations.


Several requests

gox
pipeline := []test.ExecutePipeLine{
	{
		Request: test.NewRequest{Method: test.POST, URL: "/login", Body: test.RequestBody.JSON(test.Map{
			"name": "George",
		})},
		Expected: test.NewResponseExpected{Status: 200},
	},
	{
		Request: test.NewRequest{Method: test.GET, URL: "/profile"},
		Expected: test.NewResponseExpected{
			Status: 200,
			Body: test.ExpectedBody.Contains("George"),
		},
	},
}

Cookies created by /login will be available for /profile.


Session

All steps share the initial state defined in the configuration. Changes made by a handler are available for later steps.

Each independent call to test.Execute() creates a new execution context and does not reuse the status of an earlier call.


Results per step

The result retains the order of the pipeline. Each step records its type, method, URL, response, expectations and coincidence.

When one step fails, test.Explain() can show the exact difference. Results to interpret and save this information.


Integration with Go

The pipeline is a slice of structures that accept interfaces for the request and the expectation. The specific types determine whether the runner should run an HTTP route or an Action.

The runtime maintains a test browser per run. It keeps cookies and uses the same session status as it sequentially runs the slice.


Best practices

  • It uses a pipeline to represent a single user flow.
  • Keep the order necessary to produce the required state.
  • Do not combine independent cases only to reduce the amount of functions.
  • It adds an expectation to each step whose result is part of the proven behavior.
  • Use separate calls to test.Execute() when you need isolation.

See also

Next step

Continue with Configuration to define the initial session and temporarily modify the server settings.

Configuration