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

Deep Equality Check in /pkg/agent test #1379

Merged
merged 9 commits into from
Dec 18, 2019

Conversation

latiif
Copy link
Contributor

@latiif latiif commented Dec 13, 2019

Description of the change

A follow up PR for #1369, where the comparisons between expected and attained apps are performed on the actual representation rather than a test stub.

Completed fields 'version' and 'icon' for expected results.

Benefits

Making sure the equality checks are performed on the entire structure of the attained results.

Applicable issues

Related PR #1369 based on the discussion that followed with @absoludity.

Additional information

No performance drawbacks noticed.

- 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.
- Use deep equality for comparison.
go.mod Outdated
@@ -8,6 +8,7 @@ require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/arschles/assert v1.0.0
github.com/davecgh/go-spew v1.1.1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one slipped through the cracks 🙁. Needed it for debugging.

Copy link
Contributor

Choose a reason for hiding this comment

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

you should be able to remove it now

Comment on lines 209 to 225
// Map a unique identifier to ptr to AppOverview
m := make(map[string]*proxy.AppOverview)

for _, eapp := range tc.expectedApps {
m[releaseStub{eapp.ReleaseName, eapp.Namespace, strtoi(eapp.Version)}] = true
for i, eapp := range tc.expectedApps {
m[getAppIdentity(eapp)] = &tc.expectedApps[i]
}

// All attained apps, must have a unique id that is already in the map
// Attained app and its mapping should be equal in structure not only identifier
for _, app := range apps {
rs := releaseStub{app.ReleaseName, app.Namespace, strtoi(app.Version)}
if _, ok := m[rs]; !ok {
t.Errorf("got: %v, want: %v", rs, "None")
appIdentity := getAppIdentity(app)
if expectedApp, ok := m[appIdentity]; !ok {
t.Errorf("got: %v, want: %v", &app, "None")
} else if !cmp.Equal(*expectedApp, app) {
t.Errorf(cmp.Diff(*expectedApp, app))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you can just do:

			if !cmp.Equal(tc.expectedApps, apps) {
				t.Errorf(cmp.Diff(tc.expectedApps, apps))
			}

If you reorder the expected 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.

Sure thing. It can be done that way with the pair app.ReleaseName and app.Namespace as keys to sort on.

Did I understand correctly?

Copy link
Contributor

Choose a reason for hiding this comment

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

nope, I meant that if you reorder the apps in tc.expectedApps to match the apps you don't need the map nor the iteration over the apps, you can just compare the arrays

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.

Thanks for following up on the previous discussion :) That's both simpler and more complete now. There's just some dead code that I think has been left from earlier work?

// getAppIdentity concatenates the release name and namespace of an app
func getAppIdentity(app proxy.AppOverview) string {
return fmt.Sprintf("%v %v", app.ReleaseName, app.Namespace)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it was left over from some testing or earlier sorting? I don't see it being used.

@andresmgot
Copy link
Contributor

Hi @latiif, it seems that you have rebased master or something like that and now there is a bunch of commits here that are not related to your change. Can you remove those?

Note: When getting the latest changes from master is better to merge that branch instead to avoid this issue.

@latiif
Copy link
Contributor Author

latiif commented Dec 16, 2019

Sorry for the mess @andresmgot ! Git is not my forté

With help from my colleagues, I think the commit history is in better shape now.

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.

LGTM! Just a minor comment because I think it can simplified a bit more

pkg/agent/agent_test.go Outdated Show resolved Hide resolved
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!

@andresmgot andresmgot merged commit 9b7450c into vmware-tanzu:master Dec 18, 2019
@absoludity
Copy link
Contributor

So it looks like the memory driver does not return results with consistent ordering? At least, we're seeing an ordering failure in tests occasionally it seems https://circleci.com/gh/kubeapps/kubeapps/14014

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