| 1 | package reverseproxy |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestResolveIpVersion(t *testing.T) { |
| 6 | falseBool := false |
| 7 | trueBool := true |
| 8 | tests := []struct { |
| 9 | Versions *IPVersions |
| 10 | expectedIpVersion string |
| 11 | }{ |
| 12 | { |
| 13 | Versions: &IPVersions{IPv4: &trueBool}, |
| 14 | expectedIpVersion: "ip4", |
| 15 | }, |
| 16 | { |
| 17 | Versions: &IPVersions{IPv4: &falseBool}, |
| 18 | expectedIpVersion: "ip", |
| 19 | }, |
| 20 | { |
| 21 | Versions: &IPVersions{IPv4: &trueBool, IPv6: &falseBool}, |
| 22 | expectedIpVersion: "ip4", |
| 23 | }, |
| 24 | { |
| 25 | Versions: &IPVersions{IPv6: &trueBool}, |
| 26 | expectedIpVersion: "ip6", |
| 27 | }, |
| 28 | { |
| 29 | Versions: &IPVersions{IPv6: &falseBool}, |
| 30 | expectedIpVersion: "ip", |
| 31 | }, |
| 32 | { |
| 33 | Versions: &IPVersions{IPv6: &trueBool, IPv4: &falseBool}, |
| 34 | expectedIpVersion: "ip6", |
| 35 | }, |
| 36 | { |
| 37 | Versions: &IPVersions{}, |
| 38 | expectedIpVersion: "ip", |
| 39 | }, |
| 40 | { |
| 41 | Versions: &IPVersions{IPv4: &trueBool, IPv6: &trueBool}, |
| 42 | expectedIpVersion: "ip", |
| 43 | }, |
| 44 | { |
| 45 | Versions: &IPVersions{IPv4: &falseBool, IPv6: &falseBool}, |
| 46 | expectedIpVersion: "ip", |
| 47 | }, |
| 48 | } |
| 49 | for _, test := range tests { |
| 50 | ipVersion := resolveIpVersion(test.Versions) |
| 51 | if ipVersion != test.expectedIpVersion { |
| 52 | t.Errorf("resolveIpVersion(): Expected %s got %s", test.expectedIpVersion, ipVersion) |
| 53 | } |
| 54 | } |
| 55 | } |