cucumber

package
v0.0.0-...-3a8821d Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 29 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     |

Index

Constants

This section is empty.

Variables

View Source
var JsonEncoding = Encoding{
	Name: "json",
	Marshal: func(a any) ([]byte, error) {
		return json.MarshalIndent(a, "", "  ")
	},
	Unmarshal: json.Unmarshal,
}
View Source
var PipeFunctions = map[string]func(any, error) (any, error){
	"json": func(value any, err error) (any, error) {
		if err != nil {
			return value, err
		}
		buf := bytes.NewBuffer(nil)
		encoder := json.NewEncoder(buf)
		encoder.SetIndent("", "  ")
		err = encoder.Encode(value)
		if err != nil {
			return value, err
		}
		return buf.String(), err
	},
	"json_escape": func(value any, err error) (any, error) {
		if err != nil {
			return value, err
		}
		data, err := json.Marshal(fmt.Sprintf("%v", value))
		if err != nil {
			return value, err
		}
		return strings.TrimSuffix(strings.TrimPrefix(string(data), `"`), `"`), nil
	},
	"string": func(value any, err error) (any, error) {
		if err != nil {
			return value, err
		}
		return fmt.Sprintf("%v", value), nil
	},
}
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.

View Source
var YamlEncoding = Encoding{
	Name:      "yaml",
	Marshal:   yaml.Marshal,
	Unmarshal: yaml.Unmarshal,
}

Functions

func DefaultOptions

func DefaultOptions() godog.Options

func GodogTableToStringTable

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

func StringTableToCucumberTable

func StringTableToCucumberTable(data [][]string) string

func ToString

func ToString(value interface{}, name string, encoding Encoding) (string, error)

Types

type Encoding

type Encoding struct {
	Name      string
	Marshal   func(any) ([]byte, error)
	Unmarshal func([]byte, any) error
}

type TestScenario

type TestScenario struct {
	Suite       *TestSuite
	CurrentUser string
	PathPrefix  string

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

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

func (*TestScenario) EncodingMustMatch

func (s *TestScenario) EncodingMustMatch(encoding Encoding, actual, expected string, expandExpected bool) error

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) JsonMustContain

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

func (*TestScenario) JsonMustMatch

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

func (*TestScenario) Logf

func (s *TestScenario) Logf(format string, args ...any)

func (*TestScenario) Resolve

func (s *TestScenario) Resolve(name string) (interface{}, error)

func (*TestScenario) ResolveString

func (s *TestScenario) ResolveString(name string) (string, error)

func (*TestScenario) SelectChild

func (s *TestScenario) SelectChild(value any, path string) (any, 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) SendHttpRequestWithJsonBodyAsEventStream

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

func (*TestScenario) Session

func (s *TestScenario) Session() *TestSession

func (*TestScenario) TheResponseShouldContainJsonDoc

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

func (*TestScenario) TheResponseShouldMatchJsonDoc

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

func (*TestScenario) User

func (s *TestScenario) User() *TestUser

func (*TestScenario) YamlMustMatch

func (s *TestScenario) YamlMustMatch(actual, expected string, expandExpected bool) error

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 {
	Context context.Context
	ApiURL  string
	Mu      sync.Mutex

	TlsConfig *tls.Config
	DB        *gorm.DB
	TestingT  *testing.T
	// 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() *TestSuite

func (*TestSuite) InitializeScenario

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

type TestUser

type TestUser struct {
	Name     string
	Subject  string
	Password string
	Token    *oauth2.Token
	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