Comments (8)
it is simple to debug it, since you have two slices of bytes to compare, assert the length first, then loop through every byte and compare it, if it does not match you can print the sequence of bytes [:i] as string in order to know where it did not match exactly. The issue in general does not relate to godog, that is all about your step definitions, you should not question such issues here, but rather on stackoverflow since it does not relate to godog
func (a *apiFeature) theResponseShouldMatchJSON(body *gherkin.DocString) (err error) {
var expected, actual []byte
var data interface{}
if err = json.Unmarshal([]byte(body.Content), &data); err != nil {
return
}
if expected, err = json.Marshal(data); err != nil {
return
}
actual = bytes.TrimSpace(a.resp.Body.Bytes())
if len(actual) != len(expected) {
return fmt.Errorf("expected json length: %d does not match actual: %d", len(expected), len(actual))
}
for i, b := range actual {
if b != expected[i] {
return fmt.Errorf("expected json does not match actual at character: %s^%s", string(actual[:i]), string(actual[i:i+1]))
}
}
return
}
from godog.
Hi, I rarely visit any chats, so guess if you wish to have a channel, where people using godog could connect and chat or have discussions. feel free to create such and add a reference in README, I could also place it in the description of repository if there will be people using it. cheers.
from godog.
I think it's better that you do it as I'm not a core member of godog and DATA-DOG.
You can take a look here : https://gitter.im/home/explore#createcommunity
from godog.
does anyone else need a community chat?
from godog.
Hello, I am stuck with a problem with my REST API test. Below is the scenario:
I have a struct like:
type Status struct {
ErrorCode string `json:"ERROR_CODE"`
ErrorText string `json:"ERROR_TEXT"`
}
type OutputResponse1 struct {
Status Status `json:"STATUS"`
}
type OutputResponse2 struct {
Status Status `json:"STATUS"`
Config json.RawMessage `json:"CONFIG"`
}
A byte type variable:
var responseByte []byte
And two different kind of output response:
//--------------1
responseByte, _ = json.Marshal(OutputResponse1{
Status: Status{
ErrorCode: "-2",
ErrorText: "Config was not found",
},
})
//------------2
responseByte, _ = json.Marshal(&OutputResponseSuccess{
Status: Status{
ErrorCode: "0",
ErrorText: " ",},
Config: json.RawMessage(body),
})
The json.Rawmessage is something coming from another source which looks like:
{
"binaryVersion":"1.0.0",
"configVersion":"1.1.1"
}
Now in feature file I have tested out something like this:
//--------------1
And the response should match json:
"""
{
"STATUS": {
"ERROR_CODE": "-2",
"ERROR_TEXT": "Config was not found"
}
}
"""
THIS TEST PASS
The other one being one with json.RawMessage
And the response should match json:
"""
{"STATUS":{"ERROR_CODE":"0","ERROR_TEXT":" "},"CONFIG":{"binaryVersion":"1.0.0","configVersion":"1.1.1"}}
"""
NOW THIS ONE FAILS, EVEN THOUGH THE GODG OUTPUT HAS THE ACTUAL AND EXPECTED SAME TO SAME
------------------------Acutal output of godog test---------------------------
And the response should match json:
"""
{"STATUS":{"ERROR_CODE":"0","ERROR_TEXT":" "},"CONFIG":{"binaryVersion":"1.0.0","configVersion":"1.1.1"}}
"""
Expected json does not match actual:
{"STATUS":{"ERROR_CODE":"0","ERROR_TEXT":" "},"CONFIG":{"binaryVersion":"1.0.0","configVersion":"1.1.1"}}
--- Failed scenarios:
Any idea?
from godog.
@vickeyshrestha most likely there is a new line
in the actual response from your REST api action. try trimming the actual value taken from response body. Usually with similar issues you should check the length, because spaces and all that stuff are not visible. I should have trimmed spaces in this example.
from godog.
@l3pp4rd Hello, thank for your quick answer. I tried trimming down the leading and trailing white space with the mentioned function. Unfortunately, it did not work out for me. Still showing the same problem. I tried with a very basic example that has a struct with "json.RawMessage" type in it. Still it failed in that case as well.
from godog.
@l3pp4rd Cool, Thank you for your guidance. Sorry about putting this question here, I did not know that (I am new to golang ). I will open this issue in stackoverflow. :)
from godog.
Related Issues (20)
- click on run tests but tests are not running HOT 1
- Please update the concurrency paragraph in the docs to clarify if scenario outlines run in parallel or only the scenarios HOT 1
- Is this feature file in godog/_examples/godogs running sequencially ? HOT 2
- Why Getting total scenarios as 6 while I am having total 5 scenarios HOT 3
- Skipping a test by returning `godog.ErrSkip` does not work? HOT 4
- print error stack when panic
- step function support return a nil Context with error HOT 1
- Conflict between global flags set by godog.BindCommandLineFlags and spf13/cobra HOT 1
- HELP: I want to know the index of a scenario in a scenario outline in the before scenario hook.
- Can't navigate to step definition from Gherkin step
- Unexpected step line values in cucumber report generated by Godog for scenario outlines
- ReadMe add step `go get ...` see provided patch to fix it
- Tag Filtering Expressions HOT 2
- Calculated step duration is wrong HOT 3
- Support for attachments / embeddings as per Cucumber and Behave HOT 9
- Slack registration token_revoked error HOT 1
- Broken link in „help wanted” issue
- MacOS arm64 package
- runAfterStepHooks should allow the user to replace an error with a nil or another error
- godog should report failure if ambiguous matching steps are found HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godog.