Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handlers/v1: add json tags to response structs #1473

Merged
merged 5 commits into from
Jul 26, 2018

Conversation

haikuoliu
Copy link
Contributor

@haikuoliu haikuoliu commented Jul 25, 2018

Summary

This PR adds a json tag to DockerID in v1 handler response, so that when it's marshalled the json text of this DockerID attribute will be DockerId, this is to fix a bug (introduced in this PR) where we provide a different container response for v1 handler in Agent 1.19.0, and it breaks the customers who are using v1 handler.

Will add functional tests in a separate PR.

Implementation details

Testing

  • Builds on Linux (make release)
  • Builds on Windows (go build -out amazon-ecs-agent.exe ./agent)
  • Unit tests on Linux (make test) pass
  • Unit tests on Windows (go test -timeout=25s ./agent/...) pass
  • Integration tests on Linux (make run-integ-tests) pass
  • Integration tests on Windows (.\scripts\run-integ-tests.ps1) pass
  • Functional tests on Linux (make run-functional-tests) pass
  • Functional tests on Windows (.\scripts\run-functional-tests.ps1) pass

New tests cover the changes: yes

Description for the changelog

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@haikuoliu haikuoliu added this to the 1.20.0 milestone Jul 25, 2018
@haikuoliu haikuoliu requested a review from a team July 25, 2018 21:30
@@ -46,7 +46,7 @@ type TasksResponse struct {

// ContainerResponse is the schema for the container response JSON object
type ContainerResponse struct {
DockerID string
DockerID string `json:"DockerId"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as #1471 (comment):

I'd also suggest adding unit tests that unmarshal raw strings and validate each of the fields in the unmarshalled object with the expected one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, there is a TODO in the summary that indicates I will add tests for it.

Will add it soon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaithal I would rather use a functional test that consumes the endpoint metadata for this instead of a unit test on the unmarshaller. I think a functional test will raise more warning flags about things like this breaking in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd vote for both instead of one or the other. You'd know immediately (during development) if you're breaking contracts if you add unit tests.

Copy link
Contributor

@adnxn adnxn Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think in this case neither option would have helped because the tests were also changed with the field renames in the original PR. i cant think of any way to really help prevent this other than having more eyes reviewing. lmk if you have any other ideas though. 😕

i do agree we should add both unit and functional tests though for this change.

@adnxn
Copy link
Contributor

adnxn commented Jul 25, 2018

@haikuoliu: please add json tags for the other fields as well.

)

func TestTaskResponse(t *testing.T) {
expectedTaskResponseJSONString :=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of testing for string exactness, this should preferably test for the shape of the data: the expected keys and their values (so as to not test serialization/deserialization string format). This certainly handles the case at hand, but isn't very maintainable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting that adding fields or reordering (through any cause) will make these fields unaligned and test fail.

@haikuoliu
Copy link
Contributor Author

@aaithal @adnxn @petderek
I have added the unit tests and json tags for all fields.

Instead of unmarshalling raw string, I choose to marshal the struct and then compare it with the raw string, because I found that when I unmarshalled the string, it'll be marshalled successfully when either json tag matches or struct attribute matches, and it's case insensitive, so it cannot prevent the DockerId -> DockerID case.

I will add functional test in a separate PR, so please review, thanks!

Copy link
Contributor

@petderek petderek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this -- just address Jake's comment about the TaskResponse. Thanks for adding tests!

Copy link

@richardpen richardpen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

haikuoliu added a commit to haikuoliu/amazon-ecs-agent that referenced this pull request Jul 26, 2018
@haikuoliu
Copy link
Contributor Author

@jahkeup I have addressed your comments and added the changelog.

@haikuoliu haikuoliu removed this from the 1.20.0 milestone Jul 26, 2018
Copy link
Member

@jahkeup jahkeup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haikuoliu haikuoliu changed the base branch from dev to 1.19.1 July 26, 2018 19:32
haikuoliu added a commit to haikuoliu/amazon-ecs-agent that referenced this pull request Jul 26, 2018
@haikuoliu haikuoliu merged commit 094de2a into aws:1.19.1 Jul 26, 2018
yhlee-aws pushed a commit to yhlee-aws/amazon-ecs-agent that referenced this pull request Aug 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants