(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func TestConvertDockerPort(t *testing.T) { |
| 54 | t.Parallel() |
| 55 | |
| 56 | for _, tc := range []struct { |
| 57 | name string |
| 58 | in string |
| 59 | expectPort uint16 |
| 60 | expectNetwork string |
| 61 | expectError string |
| 62 | }{ |
| 63 | { |
| 64 | name: "empty port", |
| 65 | in: "", |
| 66 | expectError: "invalid port", |
| 67 | }, |
| 68 | { |
| 69 | name: "valid tcp port", |
| 70 | in: "8080/tcp", |
| 71 | expectPort: 8080, |
| 72 | expectNetwork: "tcp", |
| 73 | }, |
| 74 | { |
| 75 | name: "valid udp port", |
| 76 | in: "8080/udp", |
| 77 | expectPort: 8080, |
| 78 | expectNetwork: "udp", |
| 79 | }, |
| 80 | { |
| 81 | name: "valid port no network", |
| 82 | in: "8080", |
| 83 | expectPort: 8080, |
| 84 | expectNetwork: "tcp", |
| 85 | }, |
| 86 | { |
| 87 | name: "invalid port", |
| 88 | in: "invalid/tcp", |
| 89 | expectError: "invalid port", |
| 90 | }, |
| 91 | { |
| 92 | name: "invalid port no network", |
| 93 | in: "invalid", |
| 94 | expectError: "invalid port", |
| 95 | }, |
| 96 | { |
| 97 | name: "multiple network", |
| 98 | in: "8080/tcp/udp", |
| 99 | expectError: "invalid port", |
| 100 | }, |
| 101 | } { |
| 102 | t.Run(tc.name, func(t *testing.T) { |
| 103 | t.Parallel() |
| 104 | actualPort, actualNetwork, actualErr := convertDockerPort(tc.in) |
| 105 | if tc.expectError != "" { |
| 106 | assert.Zero(t, actualPort, "expected no port") |
| 107 | assert.Empty(t, actualNetwork, "expected no network") |
| 108 | assert.ErrorContains(t, actualErr, tc.expectError) |
| 109 | } else { |
| 110 | assert.NoError(t, actualErr, "expected no error") |
nothing calls this directly
no test coverage detected