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

Replace go-spew with go-cmp #87

Merged
merged 1 commit into from
Jan 31, 2023

Conversation

justinsb
Copy link

Produces more compact test failures messages.

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jan 31, 2023
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 31, 2023
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 31, 2023
@justinsb
Copy link
Author

Example before and after.

Before:

--- FAIL: TestJSONObjectToYAMLObject (0.00s)
    --- FAIL: TestJSONObjectToYAMLObject/values (0.00s)
        yaml_test.go:836: jsonToYAML() = (yaml.MapSlice) (len=15 cap=15) {
             (yaml.MapItem) {
              Key: (string) (len=4) "bool",
              Value: (bool) true
             },
             (yaml.MapItem) {
              Key: (string) (len=9) "empty map",
              Value: (yaml.MapSlice) <nil>
             },
             (yaml.MapItem) {
              Key: (string) (len=11) "empty slice",
              Value: ([]interface {}) {
              }
             },
             (yaml.MapItem) {
              Key: (string) (len=7) "float64",
              Value: (float64) 42.1
             },
             (yaml.MapItem) {
              Key: (string) (len=12) "fractionless",
              Value: (int) 42
             },
             (yaml.MapItem) {
              Key: (string) (len=3) "int",
              Value: (int) 42
             },
             (yaml.MapItem) {
              Key: (string) (len=5) "int64",
              Value: (int) 42
             },
             (yaml.MapItem) {
              Key: (string) (len=9) "int64 big",
              Value: (int) 4611686018427387904
             },
             (yaml.MapItem) {
              Key: (string) (len=3) "map",
              Value: (yaml.MapSlice) (len=1 cap=1) {
               (yaml.MapItem) {
                Key: (string) (len=3) "foo",
                Value: (string) (len=3) "bar"
               }
              }
             },
             (yaml.MapItem) {
              Key: (string) (len=18) "negative int64 big",
              Value: (int) -4611686018427387904
             },
             (yaml.MapItem) {
              Key: (string) (len=7) "nil map",
              Value: (interface {}) <nil>
             },
             (yaml.MapItem) {
              Key: (string) (len=9) "nil slice",
              Value: (interface {}) <nil>
             },
             (yaml.MapItem) {
              Key: (string) (len=5) "slice",
              Value: ([]interface {}) (len=2 cap=2) {
               (string) (len=3) "foo",
               (string) (len=3) "bar"
              }
             },
             (yaml.MapItem) {
              Key: (string) (len=6) "string",
              Value: (string) (len=3) "foo"
             },
             (yaml.MapItem) {
              Key: (string) (len=10) "uint64 big",
              Value: (uint64) 9223372036854776000
             }
            }
            , want (yaml.MapSlice) (len=15 cap=15) {
             (yaml.MapItem) {
              Key: (string) (len=4) "bool",
              Value: (bool) true
             },
             (yaml.MapItem) {
              Key: (string) (len=9) "empty map",
              Value: (yaml.MapSlice) <nil>
             },
             (yaml.MapItem) {
              Key: (string) (len=11) "empty slice",
              Value: ([]interface {}) {
              }
             },
             (yaml.MapItem) {
              Key: (string) (len=7) "float64",
              Value: (float64) 42.1
             },
             (yaml.MapItem) {
              Key: (string) (len=12) "fractionless",
              Value: (int) 42
             },
             (yaml.MapItem) {
              Key: (string) (len=3) "int",
              Value: (int) 42
             },
             (yaml.MapItem) {
              Key: (string) (len=5) "int64",
              Value: (int) 432
             },
             (yaml.MapItem) {
              Key: (string) (len=9) "int64 big",
              Value: (int) 4611686018427387904
             },
             (yaml.MapItem) {
              Key: (string) (len=3) "map",
              Value: (yaml.MapSlice) (len=1 cap=1) {
               (yaml.MapItem) {
                Key: (string) (len=3) "foo",
                Value: (string) (len=3) "bar"
               }
              }
             },
             (yaml.MapItem) {
              Key: (string) (len=18) "negative int64 big",
              Value: (int) -4611686018427387904
             },
             (yaml.MapItem) {
              Key: (string) (len=7) "nil map",
              Value: (interface {}) <nil>
             },
             (yaml.MapItem) {
              Key: (string) (len=9) "nil slice",
              Value: (interface {}) <nil>
             },
             (yaml.MapItem) {
              Key: (string) (len=5) "slice",
              Value: ([]interface {}) (len=2 cap=2) {
               (string) (len=3) "foo",
               (string) (len=3) "bar"
              }
             },
             (yaml.MapItem) {
              Key: (string) (len=6) "string",
              Value: (string) (len=3) "foo"
             },
             (yaml.MapItem) {
              Key: (string) (len=10) "uint64 big",
              Value: (uint64) 9223372036854776000
             }
            }
FAIL
FAIL	sigs.k8s.io/yaml	0.028s
FAIL

After:

--- FAIL: TestJSONObjectToYAMLObject (0.00s)
    --- FAIL: TestJSONObjectToYAMLObject/values (0.00s)
        yaml_test.go:837: jsonToYAML() returned unexpected results (-want+got):
              yaml.MapSlice{
              	... // 4 identical elements
              	{Key: string("fractionless"), Value: int(42)},
              	{Key: string("int"), Value: int(42)},
              	{
              		Key:   string("int64"),
            - 		Value: int(42),
            + 		Value: int(432),
              	},
              	{Key: string("int64 big"), Value: int(4611686018427387904)},
              	{Key: string("map"), Value: yaml.MapSlice{{Key: string("foo"), Value: string("bar")}}},
              	... // 6 identical elements
              }
FAIL
FAIL	sigs.k8s.io/yaml	0.036s
FAIL

@justinsb
Copy link
Author

Prompted by https://groups.google.com/g/kubernetes-security-discuss/c/8ecsl416G18, but I haven't found documentation that this library is actually EOL. However, go-cmp is actively maintained, used in k/k, and produces more compact output, so I think it's a good choice anyway.

yaml_test.go Show resolved Hide resolved
Produces more compact test failures messages.
@liggitt
Copy link

liggitt commented Jan 31, 2023

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 31, 2023
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, liggitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 31, 2023
@k8s-ci-robot k8s-ci-robot merged commit 65d71bb into kubernetes-sigs:master Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants