GithubHelp home page GithubHelp logo

Community chat ? about godog HOT 8 CLOSED

cucumber avatar cucumber commented on July 30, 2024
Community chat ?

from godog.

Comments (8)

l3pp4rd avatar l3pp4rd commented on July 30, 2024 1

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
}

2017-03-16-202415

from godog.

l3pp4rd avatar l3pp4rd commented on July 30, 2024

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.

Dogild avatar Dogild commented on July 30, 2024

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.

l3pp4rd avatar l3pp4rd commented on July 30, 2024

does anyone else need a community chat?

from godog.

vickeyshrestha avatar vickeyshrestha commented on July 30, 2024

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.

l3pp4rd avatar l3pp4rd commented on July 30, 2024

@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.

vickeyshrestha avatar vickeyshrestha commented on July 30, 2024

@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.

vickeyshrestha avatar vickeyshrestha commented on July 30, 2024

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.