MCPcopy Index your code
hub / github.com/docker/cli / TestValidateIPAddress

Function TestValidateIPAddress

opts/opts_test.go:12–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestValidateIPAddress(t *testing.T) {
13 tests := []struct {
14 doc string
15 input string
16 expectedOut string
17 expectedErr string
18 }{
19 {
20 doc: "IPv4 loopback",
21 input: `127.0.0.1`,
22 expectedOut: `127.0.0.1`,
23 },
24 {
25 doc: "IPv4 loopback with whitespace",
26 input: ` 127.0.0.1 `,
27 expectedOut: `127.0.0.1`,
28 },
29 {
30 doc: "IPv6 loopback long form",
31 input: `0:0:0:0:0:0:0:1`,
32 expectedOut: `::1`,
33 },
34 {
35 doc: "IPv6 loopback",
36 input: `::1`,
37 expectedOut: `::1`,
38 },
39 {
40 doc: "IPv6 loopback with whitespace",
41 input: ` ::1 `,
42 expectedOut: `::1`,
43 },
44 {
45 doc: "IPv6 lowercase",
46 input: `2001:db8::68`,
47 expectedOut: `2001:db8::68`,
48 },
49 {
50 doc: "IPv6 uppercase",
51 input: `2001:DB8::68`,
52 expectedOut: `2001:db8::68`,
53 },
54 {
55 doc: "IPv6 with brackets",
56 input: `[::1]`,
57 expectedErr: `IP address is not correctly formatted: [::1]`,
58 },
59 {
60 doc: "IPv4 partial",
61 input: `127`,
62 expectedErr: `IP address is not correctly formatted: 127`,
63 },
64 {
65 doc: "random invalid string",
66 input: `random invalid string`,
67 expectedErr: `IP address is not correctly formatted: random invalid string`,
68 },
69 }

Callers

nothing calls this directly

Calls 2

ValidateIPAddressFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…