pawelwritescode / gdutils Goto Github PK
View Code? Open in Web Editor NEWLibrary with methods for testing HTTP(s) API
License: MIT License
Library with methods for testing HTTP(s) API
License: MIT License
DebuggerService
from debugger
subpackage.PathFinder
implementation in pathfinder
subpackageschema
subpackage.DebuggerService
from debugger
subpackagePathFinder
and Validator
PS: all changes should be merged to v1.2.0
branch created for this issue
pkg/pathfinder is package that contains various services that allow to query structured data
QJSONFinder
service and its corresponding method from package as it is not used anymorePathFinder describes ability to obtain node(s) from data in fixed data format. Project supports few data formats and therefore ships few PathFinder
implementations that are able to work with those data formats.
SchemaValidator describes entity that can validate document against some kind of schema. At this moment there is only one implementation available that allows to validate document against JSON schema.
PathFinder
and whether it would be beneficial to do so (check if its better than current implementations available in project). If so - write this implementationSchemaValidator
and whether it would be beneficial to do so. If so - write this implementation.Explore new candidate for another JSON Formatter and/or PathFinder: https://github.com/tidwall/gjson
I just stumbled across this repo and it is brilliant. Have you ever explored using the client generated code from https://github.com/go-swagger/go-swagger to wrap around godog tests so that we can leverage all the request objects? Or is that something we could collaborate on here?
Explore new candidate for another JSON Formatter and/or PathFinder: https://github.com/tidwall/gjson
Following methods:
AssertNodeIsType
AssertNodeIsNotType
AssertNodeIsTypeAndValue
accepts "nil", "string", "int", "float", "bool", "map", "slice"
as type argument.
Methods should be able to detect data types related with JSON / YAML.
So, methods should now accept also following types:
null, array, object, number, boolean
scalar, list, dictionary
Currently accepted types should remain available for any data format.
Internal methods implementation should change. Required changes are:
APIContext
: TypeCheckers
TypeCheckers
container should contain fields: JSON
, YAML
, which holds services for corresponding formats.Add new subpackage: typecheck
with TypeChecker
interface definition and implementation for JSON
and YAML
formats.
AssertResponseCookieValueMatchesRegExp
AsserNodeContainsSubString
AssertNodeNotContainsSubString
AssertNodeIsTypeAndHasOneOfValues
TODO:
Add following methods:
Following methods:
AssertNodeIsType
AssertNodeIsNotType
AssertNodeIsTypeAndValue
accepts "nil", "string", "int", "float", "bool", "map", "slice" as type argument.
Methods should be able to detect data types related with JSON / YAML.
So, methods should now accept also following types:
JSON: null, array, object, number, boolean
YAML: scalar, list, dictionary
Currently accepted types should remain available for any data format.
Internal methods implementation should change. Required changes are:
Add new services container to APIContext: TypeMappers
TypeMappers container should contain fields: JSON, YAML, Go which holds services for corresponding formats.
Add new subpackage: types with Mapper interface definition and implementation for JSON, YAML and Go-like formats.
gdutils is library with useful method for testing HTTP(s) API.
Create new method that allows to randomly pick one of predefined values.
For example, cucumber wrapper of such method may look like this
Given I pick randomly one "(string|int|float64)" of "value1|value2|value3"
Creator of such method should pre-define separator used for different values passed in last argument (example uses |
)
Add new methods:
Methods: IGenerateARandomRunesInTheRangeToAndSaveItAs
and IGenerateARandomSentenceInTheRangeFromToWordsAndSaveItAs
not only should change name as described above, but they should emphasize that they do not produce final output, but generator funcs instead.
Project supports various formats like JSON
, YAML
, XML
and plain text
.
Format package contains functions that helps detect whether given slice of bytes contains data in given format. Currently, there is missing function IsPlainText
.
Task is to write that kind of function. Implementation is up to developer. Function should have unit tests.
Weakest assumption may be that any non 0 length slice of bytes is detected as plain text. More sophisticated logic may use other package functions like IsJSON or IsXML to check whether those slice of bytes is detected as JSON or XML for example. If so, it assumes it is not plain-text.
Note, that it is not easy to guarantee any format so don't bother if function is not 100% correct.
For example:
IPrepareNewRequestToAndSaveItAs
may be changed to RequestPrepare
,
ISetFollowingHeadersForPreparedRequest
may be changed to RequestSetHeaders
,
TheResponseShouldHaveNodes
may be changed to AssertNodesExist
.
Methods: IGenerateARandomRunesInTheRangeToAndSaveItAs
and IGenerateARandomSentenceInTheRangeFromToWordsAndSaveItAs
not only should change name as described above, but also change from
and to
arguments to float64. In another words it should generate random float, from provided float interval.
Method IGenerateARandomFloatInTheRangeToAndSaveItAs
should not only change name, but also be modified so it returns generator func. This func should accept argument that sets rounding for output (for example, to 2 digits after dot) and return generating func that accepts left and right end of interval as float64
instead int
like currently.
Upgrade minimal golang version to 1.18 and replace all occurences of interface{}
with any
Add following methods:
TheResponseShouldHaveHeader
(the response should not have header)TheResponseShouldHaveCookie
TheResponseShouldHaveNode
TheResponseStatusCodeShouldBe
TheResponseBodyShouldHaveFormat
TheNodeShouldBeSliceOfLength
TheNodeShouldMatchRegExp
AC:
debugger represents utility service responsible for debugging whole testing process. Its implementation DebuggerService is used in default ApiContext
constructor. Its main method is Print(info string) which basically prints whatever is passed as info
to stdout with little modification.
Make few enchancements to DebuggerService
as follows:
Print
method to fixed number of bytes. This particular setting should be passed in service constructor (method New
). For example, if data passed to Print(info string)
method exceeds 1024 bytes, output should be truncated to 1024 bytes with additional info, that output was truncated.info
argument passed to Print
method is detected as JSON string, then output should be indented for better readability.Print
method may color output if it detects info
argument as JSON string. To do it - use this package.Project supports various formats like JSON
, YAML
, XML
and plain text
.
Format package contains functions that helps detect whether given slice of bytes contains data in given format. Currently, function that detects XML doesn't work good enough.
Task is to change IsXML function to make it work better. Additional unit tests should be added also.
New logic may check whether slice of bytes contains substring similar to <?xml version="1.0"
. It is up to developer to create this logic.
Note, that it is not easy to guarantee any format so don't bother if function is not 100% correct.
IsXML
functionpkg/formatter is utility package that defines services that knows how to serialize/deserialize data into different data formats.
JSONFormatter
-> JSON
, the same for restPackage contains 3rd party packages defined in go.mod
.
Each of those packages may be updated and task is to examine each of them and see if we can use newer version and eventually update it in go.mod
Task objective is to check all possible methods and try to create at least one example for each.
pkg/debugger is utility package that defines simple service useful for debugging purposes.
Current debugger works, yet is not perfect. Task is to re-design this service to make it more useful and convenient to use. Things to consider:
Is blocked by #48
pkg/cache is utility package that defines services which allows to persist data in memory having convenient to use facade.
Concurrent
Method IGenerateARandomFloatInTheRangeToAndSaveItAs
should not only change name, but also be modified so it returns generator func. This func should accept argument that sets rounding for output (for example, to 2 digits after dot) and return generating func that accepts left and right end of interval as float64 instead int like currently.
EDIT: Due to this discovery, please do not create generator func. Just create func with signature similar to:
// GenerateFloat64 generates pseudo-random float64 from provided interval and save it in cache under provided cacheKey
func (apiCtx *APIContext) GenerateFloat64(from, to float64, cacheKey string) error
pkg/mathutils defines mathematics related functions. Current functions RandomInt
and RandomFloat64
returns not only int
and float64
correspondingly, but also error. This error happens when from
argument is greather than to
argument. Although it is correct, it is also polluting code with unecessary if
s.
Having new functions MustRandomInt
and MustRandomFloat64
which do not return error would be convenient in cases when arguments passed to those functions are fixed and not passed from variable.
MustRandomInt
which is similar to already defined RandomInt
, but returns only int
and panics if from
argument is greater than to
argumentMustRandomFloat64
which is similar to already defined RandomFloat64
, but returns only float64
and panics if from
argument is greater than to
argumentrand.Seed
is depreciated. Please see why and adjust code to itAPIContext struct methods follow "godog" convention for naming. This is subject to change.
For example:
IPrepareNewRequestToAndSaveItAs
may be changed to RequestPrepare
,
ISetFollowingHeadersForPreparedRequest
may be changed to RequestSetHeaders
,
TheResponseShouldHaveNodes
may be changed to AssertNodesExist
.
Currently project allows to work with few data formats. To make it happen there are methods and structs related with particular format across whole project that allows to work with them. Good start to find them is to look here. Those are PathFinders
, TypeMappers
and more.. Those utility structs and methods are used in APIContext
's methods and can be found in steps.go file.
PathFinder
implementation for HTML tree.Some of packages defined under pkg/
for example pkg/cache
contains exported interfaces which are used by root module/package. See APIContext definition as example of that kind of usage.
Following best practices those interfaces should be removed from source package and defined in client package. Newly defined interfaces should not be exported.
For example cache.Cache
should be removed from pkg/cache
and re-defined in root level (interfaces.go
)
interfaces.go
file in root of packagepkg/
and remove exported interfaces from each subpackagego mod should accept minimal version of go: 1.18. Package and all sub packages should update their interface{}
s to any
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.