TODO: Re-write these examples in terms of how you actually use the fundamental options and filters and not in terms of what cool things you can do with them since that overlaps with cmp/cmpopts. Use Diff to print out a human-readable report of differences for tests comparing nested or structured dat
()
| 23 | // Use Diff to print out a human-readable report of differences for tests |
| 24 | // comparing nested or structured data. |
| 25 | func ExampleDiff_testing() { |
| 26 | // Let got be the hypothetical value obtained from some logic under test |
| 27 | // and want be the expected golden data. |
| 28 | got, want := MakeGatewayInfo() |
| 29 | |
| 30 | if diff := cmp.Diff(want, got); diff != "" { |
| 31 | t.Errorf("MakeGatewayInfo() mismatch (-want +got):\n%s", diff) |
| 32 | } |
| 33 | |
| 34 | // Output: |
| 35 | // MakeGatewayInfo() mismatch (-want +got): |
| 36 | // cmp_test.Gateway{ |
| 37 | // SSID: "CoffeeShopWiFi", |
| 38 | // - IPAddress: s"192.168.0.2", |
| 39 | // + IPAddress: s"192.168.0.1", |
| 40 | // NetMask: s"ffff0000", |
| 41 | // Clients: []cmp_test.Client{ |
| 42 | // ... // 2 identical elements |
| 43 | // {Hostname: "macchiato", IPAddress: s"192.168.0.153", LastSeen: s"2009-11-10 23:39:43 +0000 UTC"}, |
| 44 | // {Hostname: "espresso", IPAddress: s"192.168.0.121"}, |
| 45 | // { |
| 46 | // Hostname: "latte", |
| 47 | // - IPAddress: s"192.168.0.221", |
| 48 | // + IPAddress: s"192.168.0.219", |
| 49 | // LastSeen: s"2009-11-10 23:00:23 +0000 UTC", |
| 50 | // }, |
| 51 | // + { |
| 52 | // + Hostname: "americano", |
| 53 | // + IPAddress: s"192.168.0.188", |
| 54 | // + LastSeen: s"2009-11-10 23:03:05 +0000 UTC", |
| 55 | // + }, |
| 56 | // }, |
| 57 | // } |
| 58 | } |
| 59 | |
| 60 | // Approximate equality for floats can be handled by defining a custom |
| 61 | // comparer on floats that determines two values to be equal if they are within |
nothing calls this directly
no test coverage detected