Files
releases/vendor/github.com/foxcpp/go-mockdns
Stephan Renatus 27274e08b6 build: use go 1.19, drop go 1.16 (#5013)
With this, we'll build our container images and binaries using golang 1.19.

Also, the go.mod version stanza is increased, letting us use go1.17+ features.

I had to run

    go mod tidy -go=1.16 && go mod tidy -go=1.17

to get rid of `go mod tidy` related messages, and ran `go mod vendor`
afterwards.

* prometheus: adjust tests for new go1.19 metrics

Note that the new metrics only appear when using the Go runtime of 1.19. So,
we do the same we've done before when 1.17 brought in new metrics: add them
to the tests, and use build flags to not run the tests in the previous versions.

When the bump of github.com/prometheus/go_client to 1.13.0 was merged, it was
properly tested with all of 1.17 and 1.18. So, the previously expected metrics
should be there when using OPA from 1.17 or 1.18.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-08-15 18:05:55 +02:00
..

go-mockdns

Reference

Boilerplate for testing of code involving DNS lookups, including unholy hacks to redirect net.Lookup* calls.

Example

Trivial mock resolver, for cases where tested code supports custom resolvers:

r := mockdns.Resolver{
    Zones: map[string]mockdns.Zone{
        "example.org.": {
            A: []string{"1.2.3.4"},
        },
    },
}

addrs, err := r.LookupHost(context.Background(), "example.org")
fmt.Println(addrs, err)

// Output:
// [1.2.3.4] <nil>

Unholy hack for cases where it doesn't:

srv, _ := mockdns.NewServer(map[string]mockdns.Zone{
    "example.org.": {
        A: []string{"1.2.3.4"},
    },
}, false)
defer srv.Close()

srv.PatchNet(net.DefaultResolver)
defer mockdns.UnpatchNet(net.DefaultResolver)

addrs, err := net.LookupHost("example.org")
fmt.Println(addrs, err)

// Output:
// [1.2.3.4] <nil>

Note, if you need to replace net.Dial calls and tested code supports custom net.Dial, patch the resolver object inside it instead of net.DefaultResolver. If tested code supports Dialer-like objects - use Resolver itself, it implements Dial and DialContext methods.