Download this file
| 1 | package egress |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "net" |
| 7 | "net/netip" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestEgressDenialCount(t *testing.T) { |
| 12 | p := fixtureProxy(t, []netip.Addr{netip.MustParseAddr("127.0.0.1")}, func(context.Context, string, string) (net.Conn, error) { return nil, errors.New("unexpected dial") }) |
| 13 | counter, ok := any(p).(interface{ Denials() uint64 }) |
| 14 | if !ok { |
| 15 | t.Fatal("denials unavailable") |
| 16 | } |
| 17 | if counter.Denials() != 0 { |
| 18 | t.Fatal("nonzero initial count") |
| 19 | } |
| 20 | connect(t, p, request("unknown.example:443")) |
| 21 | connect(t, p, request("fixture.example:443")) |
| 22 | if counter.Denials() != 2 { |
| 23 | t.Fatal("denials not recorded", counter.Denials()) |
| 24 | } |
| 25 | } |
| 26 | |