MCPcopy Index your code
hub / github.com/coder/coder / TestConvertDockerPort

Function TestConvertDockerPort

agent/agentcontainers/containers_internal_test.go:53–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func 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")

Callers

nothing calls this directly

Calls 4

convertDockerPortFunction · 0.85
RunMethod · 0.65
EmptyMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected