(t *testing.T)
| 209 | } |
| 210 | |
| 211 | func TestApplyPortOffsetDisabledUsesDefaultPorts(t *testing.T) { |
| 212 | t.Parallel() |
| 213 | |
| 214 | projectRoot := "/tmp/coder/worktree-offset" |
| 215 | for i := range 100 { |
| 216 | candidate := fmt.Sprintf("/tmp/coder/worktree-offset-disabled-%d", i) |
| 217 | if portOffset(candidate) != 0 { |
| 218 | projectRoot = candidate |
| 219 | break |
| 220 | } |
| 221 | } |
| 222 | require.NotZero(t, portOffset(projectRoot)) |
| 223 | |
| 224 | cfg := &devConfig{ |
| 225 | apiPort: 3000, |
| 226 | webPort: 8080, |
| 227 | proxyPort: 3010, |
| 228 | coderMetricsPort: 2114, |
| 229 | projectRoot: projectRoot, |
| 230 | } |
| 231 | cfg.applyPortOffset() |
| 232 | |
| 233 | assert.Equal(t, int64(3000), cfg.apiPort) |
| 234 | assert.Equal(t, int64(8080), cfg.webPort) |
| 235 | assert.Equal(t, int64(3010), cfg.proxyPort) |
| 236 | assert.Equal(t, int64(2114), cfg.coderMetricsPort) |
| 237 | assert.Zero(t, cfg.portOffset) |
| 238 | assert.Empty(t, cfg.apiPortSource) |
| 239 | assert.Empty(t, cfg.webPortSource) |
| 240 | assert.Empty(t, cfg.proxyPortSource) |
| 241 | assert.Empty(t, cfg.metricsPortSource) |
| 242 | assert.Equal(t, "API: 3000", portBannerLine("API", cfg.apiPort, cfg.apiPortSource, cfg.portOffset)) |
| 243 | } |
| 244 | |
| 245 | func TestPortOffsetDefaultPortsDoNotOverlap(t *testing.T) { |
| 246 | t.Parallel() |
nothing calls this directly
no test coverage detected