(t *testing.T)
| 934 | } |
| 935 | |
| 936 | func TestIPCost(t *testing.T) { |
| 937 | ipv4 := "ip('192.168.0.1')" |
| 938 | ipv4BaseEstimatedCost := checker.FixedCostEstimate(2) |
| 939 | ipv4BaseRuntimeCost := uint64(2) |
| 940 | |
| 941 | ipv6 := "ip('2001:db8:3333:4444:5555:6666:7777:8888')" |
| 942 | ipv6BaseEstimatedCost := checker.FixedCostEstimate(4) |
| 943 | ipv6BaseRuntimeCost := uint64(4) |
| 944 | |
| 945 | testCases := []struct { |
| 946 | ops []string |
| 947 | expectEsimatedCost func(checker.CostEstimate) checker.CostEstimate |
| 948 | expectRuntimeCost func(uint64) uint64 |
| 949 | }{ |
| 950 | { |
| 951 | // For just parsing the IP, the cost is expected to be the base. |
| 952 | ops: []string{""}, |
| 953 | expectEsimatedCost: func(c checker.CostEstimate) checker.CostEstimate { return c }, |
| 954 | expectRuntimeCost: func(c uint64) uint64 { return c }, |
| 955 | }, |
| 956 | { |
| 957 | ops: []string{".family()", ".isUnspecified()", ".isLoopback()", ".isLinkLocalMulticast()", ".isLinkLocalUnicast()", ".isGlobalUnicast()"}, |
| 958 | // For most other operations, the cost is expected to be the base + 1. |
| 959 | expectEsimatedCost: func(c checker.CostEstimate) checker.CostEstimate { |
| 960 | return checker.CostEstimate{Min: c.Min + 1, Max: c.Max + 1} |
| 961 | }, |
| 962 | expectRuntimeCost: func(c uint64) uint64 { return c + 1 }, |
| 963 | }, |
| 964 | { |
| 965 | ops: []string{" == ip('192.168.0.1')"}, |
| 966 | // For most other operations, the cost is expected to be the base + 1. |
| 967 | expectEsimatedCost: func(c checker.CostEstimate) checker.CostEstimate { |
| 968 | return c.Add(ipv4BaseEstimatedCost).Add(checker.CostEstimate{Min: 1, Max: 2}) |
| 969 | }, |
| 970 | expectRuntimeCost: func(c uint64) uint64 { return c + ipv4BaseRuntimeCost + 1 }, |
| 971 | }, |
| 972 | } |
| 973 | |
| 974 | for _, tc := range testCases { |
| 975 | for _, op := range tc.ops { |
| 976 | t.Run(ipv4+op, func(t *testing.T) { |
| 977 | testCost(t, ipv4+op, tc.expectEsimatedCost(ipv4BaseEstimatedCost), tc.expectRuntimeCost(ipv4BaseRuntimeCost)) |
| 978 | }) |
| 979 | |
| 980 | t.Run(ipv6+op, func(t *testing.T) { |
| 981 | testCost(t, ipv6+op, tc.expectEsimatedCost(ipv6BaseEstimatedCost), tc.expectRuntimeCost(ipv6BaseRuntimeCost)) |
| 982 | }) |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | func TestCIDRCost(t *testing.T) { |
| 988 | ipv4 := "cidr('192.168.0.0/16')" |
nothing calls this directly
no test coverage detected