Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@youngnick
Copy link
Member

@youngnick youngnick commented Aug 12, 2020

This change replaces the current github.com/google/go-cmp/cmp based internal
assert.Equal with an aliased version of testify assert.Equal. If we need
other assertions, we'll need to add them one by one. This allows better output
for non-protobuf tests. However, it does mean that now Error message text is
being checked - there were about four places I needed to fix as a result.

Unfortunately, testify does not have support for unmarshaling protobufs, so
I needed to move to a new assert.EqualProto function that uses protocmp
to compare the two protobufs.

This also exposed another issue that the old assert.Equal was working around:
the Envoy DiscoveryResponse proto has version and nonce fields that can change in
ways that make tests flaky. However, it turns out that all the tests in featuretests
that needed the workaround only change the Resources field. So I've updated the
featuretests infrastructure to have the Equals method on the Response struct
for testing only compare that Resources field. This should probably be replaced
with EqualResources and NoResources for the normal and empty case respectively,
but this PR is big enough for now.

Updates #2786 for now, until a second PR that will change the names as above.

Signed-off-by: Nick Young [email protected]

@youngnick youngnick added the area/testing Issues or PRs related to tests or testing tools. label Aug 12, 2020
@youngnick youngnick self-assigned this Aug 12, 2020
@codecov
Copy link

codecov bot commented Aug 12, 2020

Codecov Report

Merging #2787 into master will decrease coverage by 0.04%.
The diff coverage is 42.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2787      +/-   ##
==========================================
- Coverage   76.69%   76.64%   -0.05%     
==========================================
  Files          72       72              
  Lines        5651     5635      -16     
==========================================
- Hits         4334     4319      -15     
  Misses       1228     1228              
+ Partials       89       88       -1     
Impacted Files Coverage Δ
internal/featuretests/featuretests.go 90.25% <0.00%> (-0.99%) ⬇️
internal/assert/assert.go 57.14% <60.00%> (-17.86%) ⬇️

"github.com/golang/protobuf/ptypes/any"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
tassert "github.com/stretchr/testify/require"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be testify/assert so that testing.Error is used.

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

mostly LGTM, one comment.

@youngnick
Copy link
Member Author

Okay, this is good for rereview now.

Copy link
Contributor

@jpeach jpeach left a comment

Choose a reason for hiding this comment

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

LGTM

Nick Young added 5 commits August 13, 2020 00:55
This change replaces the current `github.com/google/go-cmp/cmp` based internal
`assert.Equal` with an aliased version of testify `assert.Equal`. If we need
other assertions, we'll need to add them one by one. This allows better output
for non-protobuf tests. However, it does mean that now Error message text is
being checked - there were about four places I needed to fix as a result.

Unfortunately, testify does not have support for unmarshaling protobufs, so
I needed to move to a new `assert.EqualProto` function that uses `protocmp`
to compare the two protobufs.

This also exposed another issue that the old `assert.Equal` was working around:
the Envoy DiscoveryResponse proto has version and nonce fields that can change in
ways that make tests flaky. However, it turns out that all the tests in `featuretests`
that needed the workaround only change the `Resources` field. So I've updated the
featuretests infrastructure to have the `Equals` method on the Response struct
for testing only compare that `Resources` field. This should probably be replaced
with `EqualResources` and `NoResources` for the normal and empty case respectively,
but this PR is big enough for now.

Updates projectcontour#2786 for now, until a second PR that will change the names as above.

Signed-off-by: Nick Young <[email protected]>
…ert more

The `internal/assert` library will now behave the same as the testify `assert`:
failures will produce t.Error() output, but will not be fatal.

The feature tests have been updated so that the `Equals()` method is still fatal;
this replicates the existing behavior.

Signed-off-by: Nick Young <[email protected]>
@youngnick youngnick merged commit 057fdc0 into projectcontour:master Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/testing Issues or PRs related to tests or testing tools.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants