google / go-cmp

Package for comparing Go values in tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reporter truncating important context on diff output but leaving others alone

dprotaso opened this issue · comments

I think for tests I need a way to bump the amount of context that is printed. eg. when using the Gateway APIs I'm seeing diffs that are hard to understand.

Here i've compared two HTTPRoutes and you can see nested deep Spec.Rules[2] is deleted but the details of that rule entry is deleted. But oddly the other rules are printed fully. For testing I would prefer to see the whole entry of everything that was deleted in order to identify the entry.

I've seen other examples where I have the same structs in a list. It's important for me to see the Type field (unique key in list) to identify which struct was modified. Sometimes it remains under the fold in the reporter output (eg. 1 identical value)

 ingress_test.go:821: Extra update of (*v1beta1.HTTPRoute/ns/example.com):   &v1beta1.HTTPRoute{
          	TypeMeta:   {},
          	ObjectMeta: {Name: "example.com", Namespace: "ns", Labels: {"networking.knative.dev/visibility": ""}, Annotations: {"networking.knative.dev/ingress.class": "gateway-api.ingress.networking.knative.dev"}, ...},
          	Spec: v1.HTTPRouteSpec{
          		CommonRouteSpec: {ParentRefs: {{Group: &"gateway.networking.k8s.io", Kind: &"Gateway", Namespace: &"istio-system", Name: "istio-gateway", ...}}},
          		Hostnames:       {"example.com"},
          		Rules: []v1.HTTPRouteRule{
          			{Matches: {{Path: &{Type: &"PathPrefix", Value: &"/"}, Headers: {{Type: &"Exact", Name: "K-Network-Hash", Value: "override"}}}}, Filters: {{Type: "RequestHeaderModifier", RequestHeaderModifier: &{Set: {{Name: "K-Network-Hash", Value: "9333a9a68409bb44f2a5f538d2d7c617e5338b6b6c1ebc5e00a19612a5c962c2"}}}}}, BackendRefs: {{BackendRef: {BackendObjectReference: {Group: &"", Kind: &"Service", Name: "goo", Port: &123}, Weight: &100}, Filters: {{Type: "RequestHeaderModifier", RequestHeaderModifier: &{Set: {{Name: "K-Serving-Revision", Value: "goo"}, {Name: "K-Serving-Namespace", Value: "ns"}}}}}}}},
          			{Matches: {{Path: &{Type: &"PathPrefix", Value: &"/"}}}, BackendRefs: {{BackendRef: {BackendObjectReference: {Group: &"", Kind: &"Service", Name: "goo", Port: &123}, Weight: &100}, Filters: {{Type: "RequestHeaderModifier", RequestHeaderModifier: &{Set: {{Name: "K-Serving-Revision", Value: "goo"}, {Name: "K-Serving-Namespace", Value: "ns"}}}}}}}},
        - 			{
        - 				Matches: []v1.HTTPRouteMatch{{Path: &v1.HTTPPathMatch{...}, Headers: []v1.HTTPHeaderMatch{...}}},
        - 				Filters: []v1.HTTPRouteFilter{
        - 					{Type: "RequestHeaderModifier", RequestHeaderModifier: &v1.HTTPHeaderFilter{...}},
        - 				},
        - 				BackendRefs: []v1.HTTPBackendRef{{BackendRef: v1.BackendRef{...}, Filters: []v1.HTTPRouteFilter{...}}},
        - 			},
          			{Matches: {{Path: &{Type: &"PathPrefix", Value: &"/.well-known/knative/revision/ns/second-revision"}, Headers: {{Type: &"Exact", Name: "K-Network-Hash", Value: "override"}}}}, Filters: {{Type: "RequestHeaderModifier", RequestHeaderModifier: &{Set: {{Name: "K-Network-Hash", Value: "9333a9a68409bb44f2a5f538d2d7c617e5338b6b6c1ebc5e00a19612a5c962c2"}}}}}, BackendRefs: {{BackendRef: {BackendObjectReference: {Group: &"", Kind: &"Service", Name: "second-revision", Port: &123}}, Filters: {{Type: "RequestHeaderModifier", RequestHeaderModifier: &{Set: {{Name: "K-Serving-Namespace", Value: "ns"}, {Name: "K-Serving-Revision", Value: "second-revision"}}}}}}}},
          		},
          	},
          	Status: {RouteStatus: {Parents: {{Conditions: {{Type: "Accepted", Status: "True"}}}}}},
          }