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

Improve TestListReleases for /pkg/agent #1369

Merged
merged 1 commit into from
Dec 12, 2019

Conversation

latiif
Copy link
Contributor

@latiif latiif commented Dec 12, 2019

  • Check the content of returned listed releases (not just size comparison).
  • Complete information about returned apps in test cases.
  • Add test case for release with same name, but different versions and namespaces.

Description of the change

Build and expand on the existing test of TestListReleases in /pkg/agent, by ensuring the equivalence between what is expected and the returned values of ListReleases.

The current test checks only if |G| = |W| where W is the expected result and G is the result of ListReleases.

Benefits

  • By populating the expected results of the test cases with namespace and version, better distinction between releases is achieved.

  • This PR adds an additional constraint, namely ∀ g ∊ G : g ∊ W, which together with the previous one i.e. |G| = |W|, ensures that G = W.

  • The new test case tests the scenario where ListReleases returns two apps with same name but different namespaces and versions.

Applicable issues

- Check the content of returned listed releases (not just size comparison).
- Complete information about returned apps in test cases.
- Add test case for release with same name, but different versions and namespaces.
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

Thanks for the extra test!

@andresmgot andresmgot merged commit b9f3103 into vmware-tanzu:master Dec 12, 2019
@latiif latiif deleted the agent-test branch December 12, 2019 13:10
Copy link
Contributor

@absoludity absoludity left a comment

Choose a reason for hiding this comment

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

Nice - thanks @latiif for finishing the tests!

}

for _, app := range apps {
rs := releaseStub{app.ReleaseName, app.Namespace, strtoi(app.Version)}
Copy link
Contributor

Choose a reason for hiding this comment

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

So I think this is comparing a manually constructed releaseStub made from the output AppOverview, with another manually constructed releaseStub created from the expected AppOverview. Why not just compare the output AppOverview with the expected AppOverview directly? (bonus that they then have the same types).

Also, not sure if it could have been used here, but the cmp from the go-cmp module is quite nice for comparisons... you might also be able to do something like:

import "github.com/google/go-cmp/cmp"
...
    if !cmp.Equal(tc.expectedApps, apps) {
        t.Errorf(cmp.Diff(tc.expectedApps, apps))
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely, comparing AppOverView's makes more sense.
I'll take a look at go-cmp, but I have a gut feeling that additional fields need to be filled in the expected AppOverview array.

I'll create a new PR since this one is merged & closed.

Copy link
Contributor

@andresmgot andresmgot Dec 13, 2019

Choose a reason for hiding this comment

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

I tried that while reviewing this PR and it doesn't work (that's why I assumed it was doing the comparison manually). There are still some fields that are not in the expected release (like the status of the release) and also the order in the slices changes sometimes so the comparison fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was able to fix it by using the library @absoludity mentioned in PR #1379.

It was done by mapping a unique id (presumably no two releases can have the same name in the same namespaces in the expected results) to a pointer to the expected AppOverview.

Then, by generating a unique id for the attained result, looking up it in the mapping, and then and only then, perform deep equality check on both objects.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it got even simpler than that too. Great, thanks @latiif

@latiif latiif restored the agent-test branch December 13, 2019 07:02
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.

3 participants