cucumber

package
v0.0.0-...-9b598c7 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Setting a path prefixed to subsequent http requests:

Given the path prefix is "/api/kafkas_mgmt"

Send an http request. Supports (GET|POST|PUT|DELETE|PATCH|OPTION):

When I GET path "/v1/some/${kid}

Send an http request with a body. Supports (GET|POST|PUT|DELETE|PATCH|OPTION):

When I POST path "/v1/some/${kid}" with json body:
  """
  {"some":"${kid}"}
  """

Wait until an http get responds with an expected result or a timeout occurs:

Given I wait up to "35.5" seconds for a GET on path "/v1/some/path" response ".total" selection to match "1"

Wait until an http get responds with an expected response code or a timeout occurs:

Given I wait up to "35.5" seconds for a GET on path "/v1/some/path" response code to match "200"

Send an http request that receives a stream of events. Supports (GET|POST|PUT|DELETE|PATCH|OPTION). :

When I GET path "/v1/some/${kid} as an event stream

Wait until a json event arrives on the event stream or a timeout occurs:

Given I wait up to "35" seconds for a response json event

Assert response code is correct:

Then the response code should be 202

Assert that a json field of the response body is correct. This uses a http://github.com/itchyny/gojq expression to select the json field of the response:

Then the ".status" selection from the response should match "assigning"

Assert that the response body matches the provided text:

Then the response should match "Hello"
Then the response should match:
"""
Hello
"""

Assert that response json matches the provided json. Differences in json formatting and field order are ignored.:

Then the response should match json:
  """
  {
      "id": "${cid}",
  }
  """

Stores a json field of the response body in a scenario variable:

Given I store the ".id" selection from the response as ${cid}

Stores a json value in a scenario variable:

Given I store json as ${$input}:
  """
  {
      "id": "${cid}",
  }
  """

Assert that a response header matches the provided text:

Then the response header "Content-Type" should match "application/json;stream=watch"

Assert that a json field of the response body is correct matches the provided json:

Then the ".deployment_location" selection from the response should match json:
  """
  {
      "namespace_id": "default"
  }
  """

Aquires and exclusive lock against the test suite so that it is the only scenario executing until the secnario finishes executing.

Given LOCK

Releases the exclusive lock previously acquired. Not required, any aquired lock is automatically released at the end of scenario.

Given UNLOCK

Sleeps for the given number of seconds.

And I sleep for 0.5 second

Runes a SQL statement against the DB

When I run SQL "UPDATE connectors SET connector_type_id='foo' WHERE id = '${connector_id}';" expect 1 row to be affected.

Runes a SQL statement against the DB and check the results

And I run SQL "SELECT count(*) from connector_deployments where connector_id='${connector_id}'" gives results:
  | count |
  | 0     |

Creating a user in a random organization:

Given a user named "Bob"

Creating a user in a given organization:

Given a user named "Jimmy" in organization "13639843"

Logging into a user session:

Given I am logged in as "Jimmy"

Setting the Authorization header of the current user session:

Given I set the Authorization header to "Bearer ${agent_token}"

Index

Constants

This section is empty.

Variables

View Source
var StepModules []func(ctx *godog.ScenarioContext, s *TestScenario)

StepModules is the list of functions used to add steps to a godog.ScenarioContext, you can add more to this list if you need test TestSuite specific steps.

Functions

func DefaultOptions

func DefaultOptions() godog.Options

func GodogTableToStringTable

func GodogTableToStringTable(table *godog.Table) [][]string

func StringTableToCucumberTable

func StringTableToCucumberTable(data [][]string) string

Types

type TableCell

type TableCell = messages.PickleStepArgument_PickleTable_PickleTableRow_PickleTableCell

type TableRow

type TableRow = messages.PickleStepArgument_PickleTable_PickleTableRow

type TestScenario

type TestScenario struct {
	Suite       *TestSuite
	CurrentUser string
	PathPrefix  string

	Variables map[string]interface{}
	// contains filtered or unexported fields
}

TestScenario holds that state of single scenario. It is not accessed concurrently.

func (*TestScenario) Expand

func (s *TestScenario) Expand(value string, skippedVars []string) (result string, rerr error)

Expand replaces ${var} or $var in the string based on saved Variables in the session/test scenario.

func (*TestScenario) JsonMustMatch

func (s *TestScenario) JsonMustMatch(actual, expected string, expand bool) error

func (*TestScenario) SendHttpRequestWithJsonBody

func (s *TestScenario) SendHttpRequestWithJsonBody(method, path string, jsonTxt *godog.DocString) (err error)

func (*TestScenario) SendHttpRequestWithJsonBodyAndStyle

func (s *TestScenario) SendHttpRequestWithJsonBodyAndStyle(method, path string, jsonTxt *godog.DocString, eventStream bool, expandJson bool) (err error)

func (*TestScenario) Session

func (s *TestScenario) Session() *TestSession

func (*TestScenario) TheResponseShouldMatchJsonDoc

func (s *TestScenario) TheResponseShouldMatchJsonDoc(expected *godog.DocString) error

func (*TestScenario) User

func (s *TestScenario) User() *TestUser

type TestSession

type TestSession struct {
	TestUser  *TestUser
	Client    *http.Client
	Resp      *http.Response
	Ctx       context.Context
	RespBytes []byte

	Header            http.Header
	EventStream       bool
	EventStreamEvents chan interface{}
	Debug             bool
	// contains filtered or unexported fields
}

TestSession holds the http context for a user kinda like a browser. Each scenario had a different session even if using the same user.

func (*TestSession) RespJson

func (s *TestSession) RespJson() (interface{}, error)

RespJson returns the last http response body as json

func (*TestSession) SetRespBytes

func (s *TestSession) SetRespBytes(bytes []byte)

type TestSuite

type TestSuite struct {
	ApiURL string
	Helper *test.Helper
	Mu     sync.Mutex
	// contains filtered or unexported fields
}

TestSuite holds the state global to all the test scenarios. It is accessed concurrently from all test scenarios.

func NewTestSuite

func NewTestSuite(helper *test.Helper) *TestSuite

func (*TestSuite) InitializeScenario

func (suite *TestSuite) InitializeScenario(ctx *godog.ScenarioContext)

type TestUser

type TestUser struct {
	Name     string
	OrgId    string
	Token    string
	UserName string
	Ctx      context.Context
	Mu       sync.Mutex
}

TestUser represents a user that can login to the system. The same users are shared by the different test scenarios.

Jump to

Keyboard shortcuts

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