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

Different objects are formatted identically #194

Closed
ArseniiPetrovich opened this issue Apr 1, 2020 · 7 comments
Closed

Different objects are formatted identically #194

ArseniiPetrovich opened this issue Apr 1, 2020 · 7 comments
Labels

Comments

@ArseniiPetrovich
Copy link

Hi, guys. I'm trying to write a set of tests that will compare existing security group with a predefined ones. For that I'm using this library to compare two groups - the one that is received via AWS DescribeSecurityGroups request and the one I define.

The predefined struct is:

var rules = []ec2.IpPermission {
                ec2.IpPermission {
                  FromPort: &fromPorts[0],
                  IpProtocol: &ipProtocols[0],
                  IpRanges: []*ec2.IpRange {
                    &ec2.IpRange {
                      CidrIp: &cidrIPs[0],
                    },
                  },
                  ToPort: &toPorts[0],
                },
}

When I compared it for the first time I got "false" result and decided to add some logging to figure out the root of the issue. The cmp.Diff gave me the following output:

    TestBundle/Security_groups_tests: bundle_test.go:338: DEBUG. That is no match. The difference is:                                 
    TestBundle/Security_groups_tests: bundle_test.go:339:   interface{}(                                                              
        -       s"{\n  FromPort: 30333,\n  IpProtocol: \"tcp\",\n  IpRanges: [{\n      CidrIp: \"0.0.0.0/0\"\n    }],\n  ToPort: 30333
\n}",                                                                                                                                 
        +       s"{\n  FromPort: 30333,\n  IpProtocol: \"tcp\",\n  IpRanges: [{\n      CidrIp: \"0.0.0.0/0\"\n    }],\n  ToPort: 30333
\n}",                                                                                                                                 
          )

As you can see there is a perfect match of two objects, however they are not equal according to cmp.Equal method.

@dsnet
Copy link
Collaborator

dsnet commented Apr 2, 2020

Without runnable code, there isn't much we can do to debug this. Typically when something like this happens, it's because cmp is comparing upon some value that is incomparable (e.g., a cache, a mutex, a floating-point NaN, etc).

@ArseniiPetrovich
Copy link
Author

Hi, @dsnet! Thank you for such a quick answer. Our project is going to be published under Apache 2.0 license, so I think there's no problem for me to share this project with you now. I've added you to our private repo as an outside collaborator. Please, check your email for details.
Our Golang scripts reside in tests/aws folder. The function I have issue with is called SGCheck. Thanks!

@dsnet
Copy link
Collaborator

dsnet commented Apr 7, 2020

Following up here: I don't think I ever got any such link in my email.

@ArseniiPetrovich
Copy link
Author

@dsnet
Please, use this link => https://github.com/Altoros/polkadot-validator-failover/invitations
It should point you directly to our repo. Thank you!

@ArseniiPetrovich
Copy link
Author

Oops. Accidentally closed 🥇

@ArseniiPetrovich
Copy link
Author

@dsnet Any progress on this issue? We could probably schedule a call to work on this issue?

@ArseniiPetrovich
Copy link
Author

Okay, I was finally able to identify the issue. I was comparing the array of object with array of pointers to objects. The problems is that cmp.Diff does not show this difference, which complicated the identification of problems. I would recommend to add more verbose info to Diff function.

@dsnet dsnet added bug and removed waiting-for-info labels Jun 8, 2020
@dsnet dsnet changed the title BUG: Two identical objects gets recognized as different objects Different objects are formatted identically Jun 8, 2020
@dsnet dsnet closed this as completed in 44914b3 Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants