(t *testing.T)
| 171 | } |
| 172 | |
| 173 | func TestApplyPortOffsetSkipsExplicitPorts(t *testing.T) { |
| 174 | t.Parallel() |
| 175 | |
| 176 | projectRoot := "/tmp/coder/worktree-offset" |
| 177 | for i := range 100 { |
| 178 | candidate := fmt.Sprintf("/tmp/coder/worktree-offset-%d", i) |
| 179 | if portOffset(candidate) != 0 { |
| 180 | projectRoot = candidate |
| 181 | break |
| 182 | } |
| 183 | } |
| 184 | offset := portOffset(projectRoot) |
| 185 | require.NotZero(t, offset) |
| 186 | |
| 187 | cfg := &devConfig{ |
| 188 | apiPort: 3000, |
| 189 | webPort: 8080, |
| 190 | proxyPort: 3010, |
| 191 | coderMetricsPort: 2114, |
| 192 | portOffsetEnabled: true, |
| 193 | projectRoot: projectRoot, |
| 194 | portExplicit: portExplicit{ |
| 195 | web: true, |
| 196 | metrics: true, |
| 197 | }, |
| 198 | } |
| 199 | cfg.applyPortOffset() |
| 200 | |
| 201 | assert.Equal(t, int64(3000+offset), cfg.apiPort) |
| 202 | assert.Equal(t, int64(8080), cfg.webPort) |
| 203 | assert.Equal(t, int64(3010+offset), cfg.proxyPort) |
| 204 | assert.Equal(t, int64(2114), cfg.coderMetricsPort) |
| 205 | assert.Equal(t, portSourceOffset, cfg.apiPortSource) |
| 206 | assert.Equal(t, portSourceExplicit, cfg.webPortSource) |
| 207 | assert.Equal(t, portSourceOffset, cfg.proxyPortSource) |
| 208 | assert.Equal(t, portSourceExplicit, cfg.metricsPortSource) |
| 209 | } |
| 210 | |
| 211 | func TestApplyPortOffsetDisabledUsesDefaultPorts(t *testing.T) { |
| 212 | t.Parallel() |
nothing calls this directly
no test coverage detected