MCPcopy
hub / github.com/google/go-cmp / ExampleIgnoreFields_testing

Function ExampleIgnoreFields_testing

cmp/cmpopts/example_test.go:24–54  ·  view source on GitHub ↗

Use IgnoreFields to ignore fields on a struct type when comparing by providing a value of the type and the field names to ignore. Typically, a zero value of the type is used (e.g., foo.MyStruct{}).

()

Source from the content-addressed store, hash-verified

22// by providing a value of the type and the field names to ignore.
23// Typically, a zero value of the type is used (e.g., foo.MyStruct{}).
24func ExampleIgnoreFields_testing() {
25 // Let got be the hypothetical value obtained from some logic under test
26 // and want be the expected golden data.
27 got, want := MakeGatewayInfo()
28
29 // While the specified fields will be semantically ignored for the comparison,
30 // the fields may be printed in the diff when displaying entire values
31 // that are already determined to be different.
32 if diff := cmp.Diff(want, got, cmpopts.IgnoreFields(Client{}, "IPAddress")); diff != "" {
33 t.Errorf("MakeGatewayInfo() mismatch (-want +got):\n%s", diff)
34 }
35
36 // Output:
37 // MakeGatewayInfo() mismatch (-want +got):
38 // cmpopts_test.Gateway{
39 // SSID: "CoffeeShopWiFi",
40 // - IPAddress: s"192.168.0.2",
41 // + IPAddress: s"192.168.0.1",
42 // NetMask: s"ffff0000",
43 // Clients: []cmpopts_test.Client{
44 // ... // 3 identical elements
45 // {Hostname: "espresso", ...},
46 // {Hostname: "latte", LastSeen: s"2009-11-10 23:00:23 +0000 UTC", ...},
47 // + {
48 // + Hostname: "americano",
49 // + IPAddress: s"192.168.0.188",
50 // + LastSeen: s"2009-11-10 23:03:05 +0000 UTC",
51 // + },
52 // },
53 // }
54}
55
56type (
57 Gateway struct {

Callers

nothing calls this directly

Calls 4

DiffFunction · 0.92
IgnoreFieldsFunction · 0.92
MakeGatewayInfoFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected