Documentation ¶
Overview ¶
Package cucumber allows you to use cucumber to execute Gherkin based BDD test scenarios with some helpful API testing step implementations.
Some steps allow you store variables or use those variables. The variables are scoped to the Scenario. The http response state is stored in the users session. Switching users will switch the session. Scenarios are executed concurrently. The same user can be logged into two scenarios, but each scenario has a different session.
Note: be careful using the same user/organization across different scenarios since they will likely see unexpected API mutations done in the other scenarios.
Using in a test
func TestMain(m *testing.M) { ocmServer := mocks.NewMockConfigurableServerBuilder().Build() defer ocmServer.close() h, _, teardown := test.RegisterIntegration(&testing.T{}, ocmServer) defer teardown() cucumber.TestMain(h)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
Types ¶
type TestScenario ¶
type TestScenario struct { Suite *TestSuite DB *sqlx.DB 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) (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
JSONMustMatch compares 2 JSONs
func (*TestScenario) Session ¶
func (s *TestScenario) Session() *TestSession
Session set the session for the current user within a test scenario
func (*TestScenario) User ¶
func (s *TestScenario) User() *TestUser
User sets current user within the test scenario
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)
SetRespBytes set the response for an http session
type TestSuite ¶
type TestSuite struct { APIURL string Mu sync.Mutex DB *sqlx.DB Logger *zap.SugaredLogger // contains filtered or unexported fields }
TestSuite holds the sate global to all the test scenarios. It is accessed concurrently from all test scenarios.
func (*TestSuite) InitializeScenario ¶
func (s *TestSuite) InitializeScenario(ctx *godog.ScenarioContext)
InitializeScenario initializes each scenario for the test suite