Categorygithub.com/pawelWritesCode/gdutils
modulepackage
1.2.2
Repository: https://github.com/pawelwritescode/gdutils.git
Documentation: pkg.go.dev

# README

gdutils Go Reference Coverage

GDUTILS

Simple library with methods useful for e2e testing of HTTP(s) API using JSON/YAML/XML.

Downloading

go get github.com/pawelWritesCode/gdutils

Related project:

Skeleton that allows to write E2E tests covering any HTTP API using godog & gdutils almost instantly with minimal configuration. https://github.com/pawelWritesCode/godog-http-api

Simple usage:

ac := gdutils.NewDefaultAPIContext(false, "")

if err := ac.RequestPrepare("GET", "https://random-d.uk/api/v2/list", "DUCK_GIFS_LIST"); err != nil {
	return err
}

if err := ac.RequestSend("DUCK_GIFS_LIST"); err != nil {
    return err
}

if err := ac.AssertStatusCodeIs(200); err != nil {
    return err
}

if err := ac.AssertResponseFormatIs(format.JSON); err != nil {
    return err
}

if err := ac.AssertNodeIsType(format.JSON, "$.gifs", types.Array); err != nil {
    return err
}

Available methods:

NAMEDESCRIPTION
Sending HTTP(s) requests:
RequestSendWithBodyAndHeadersSends HTTP(s) request with provided body and headers.
RequestPreparePrepare HTTP(s) request
RequestSetHeadersSets provided headers for previously prepared request
RequestSetFormSets provided form for previously prepared request
RequestSetCookiesSets provided cookies for previously prepared request
RequestSetBodySets body for previously prepared request
RequestSendSends previously prepared HTTP(s) request
Random data generation:
GenerateRandomIntGenerates random integer from provided range and save it under provided cache key
GenerateFloat64Generates random float from provided range and save it under provided cache key
GeneratorRandomRunesCreates generator for random strings from provided charset in provided range
GeneratorRandomSentenceCreates generator for random sentence from provided charset in provided range
GetTimeAndTravelAccepts time object and move in time by given time interval
GenerateTimeAndTravelCreates current time object and move in time by given time interval
Preserving data:
SaveNodeSaves from last response body JSON node under given cacheKey key
SaveHeaderSaves into cache given header value
SaveSaves into cache arbitrary passed value
Debugging:
DebugPrintResponseBodyPrints last response from request
DebugStartStarts debugging mode
DebugStopStops debugging mode
Flow control:
WaitStops test execution for provided amount of time
Assertions:
AssertResponseHeaderExistsChecks whether last HTTP(s) response has given header
AssertResponseHeaderNotExistsChecks whether last HTTP(s) response doesn't have given header
AssertResponseHeaderValueIsChecks whether last HTTP(s) response has given header with provided value
AssertStatusCodeIsChecks last HTTP(s) response status code
AssertStatusCodeIsNotChecks if last HTTP(s) response status code is not of provided value
AssertResponseFormatIsChecks whether last HTTP(s) response body has given data format
AssertResponseFormatIsNotChecks whether last HTTP(s) response body doesn't have given data format
AssertNodeExistsChecks whether last response body contains given key
AssertNodeNotExistsChecks whether last response body doesn't contain given key
AssertNodesExistChecks whether last HTTP(s) response body JSON has given nodes
AssertNodeIsTypeAndValueCompares json node value from expression to expected by user
AssertNodeIsTypeAndHasOneOfValuesCompares node value from expression to expected by user set of values
AssertNodeContainsSubStringChecks whether node value from expression contains given substring
AssertNodeNotContainsSubStringChecks whether node value from expression doesn't contain given substring
AssertNodeIsTypeChecks whether node from last HTTP(s) response body is of provided type
AssertNodeIsNotTypeChecks whether node from last HTTP(s) response body is not of provided type
AssertNodeMatchesRegExpChecks whether last HTTP(s) response body JSON node matches regExp
AssertNodeNotMatchesRegExpChecks whether last HTTP(s) response body JSON node doesn't match regExp
AssertNodeSliceLengthIschecks whether given key is slice and has given length
AssertNodeSliceLengthIsNotchecks whether given key is slice and doesn't have given length
AssertResponseMatchesSchemaByReferenceValidates last HTTP(s) response body against provided in reference JSON schema
AssertResponseMatchesSchemaByStringValidates last HTTP(s) response body against provided JSON schema
AssertNodeMatchesSchemaByStringValidates last HTTP(s) response body JSON node against provided JSON schema
AssertNodeMatchesSchemaByReferenceValidates last HTTP(s) response body JSON node against provided in reference JSON schema
AssertTimeBetweenRequestAndResponseIsAsserts that last HTTP(s) request-response time is <= than expected
AssertResponseCookieExistsChecks whether last HTTP(s) response has given cookie
AssertResponseCookieNotExistsChecks whether last HTTP(s) response doesn't have given cookie
AssertResponseCookieValueIsChecks whether last HTTP(s) response has given cookie of given value
AssertResponseCookieValueMatchesRegExpChecks whether last HTTP(s) response has given cookie matching provided regExp
AssertResponseCookieValueNotMatchesRegExpChecks whether last HTTP(s) response has given cookie is not matching provided regExp

# Packages

Package pkg holds packages used for steps.

# Functions

NewAPIContext returns *APIContext.
NewDefaultAPIContext returns *APIContext with default services.

# Variables

No description provided by the author

# Structs

APIContext holds utility services for working with HTTP(s) API.
BodyHeaders is entity that holds information about request body and request headers.
No description provided by the author
Formatters is container for entities that know how to serialize and deserialize data.
PathFinders is container for different data types pathfinders.
SchemaValidators is container for JSON schema validators.
TypeMappers is container for different data format mappers.