|
5 | 5 | "errors" |
6 | 6 | "io" |
7 | 7 | "net/http" |
| 8 | + "os" |
| 9 | + "path/filepath" |
8 | 10 | "strings" |
9 | 11 | "testing" |
10 | 12 | "time" |
@@ -306,6 +308,27 @@ func TestLoadConfig_RoundTrip(t *testing.T) { |
306 | 308 | assert.True(t, cfg.LastVersionCheckAt.Equal(loaded.LastVersionCheckAt)) |
307 | 309 | } |
308 | 310 |
|
| 311 | +func TestRun_DisabledShortCircuitsBeforeAnyDiskWrite(t *testing.T) { |
| 312 | + dir := t.TempDir() |
| 313 | + t.Setenv("POUTINE_CONFIG_DIR", dir) |
| 314 | + t.Setenv(DisableEnv, "") |
| 315 | + |
| 316 | + // Disabled via the option (CLI flag / config path). |
| 317 | + result := Run(context.Background(), "v0.18.0", true) |
| 318 | + assert.Nil(t, result) |
| 319 | + |
| 320 | + _, err := os.Stat(filepath.Join(dir, "config.yaml")) |
| 321 | + assert.True(t, os.IsNotExist(err), "no state file should be written when disabled") |
| 322 | + |
| 323 | + // Disabled via env var, even if the option is false. |
| 324 | + t.Setenv(DisableEnv, "1") |
| 325 | + result = Run(context.Background(), "v0.18.0", false) |
| 326 | + assert.Nil(t, result) |
| 327 | + |
| 328 | + _, err = os.Stat(filepath.Join(dir, "config.yaml")) |
| 329 | + assert.True(t, os.IsNotExist(err), "no state file should be written when disabled by env") |
| 330 | +} |
| 331 | + |
309 | 332 | func TestIsDisabledByEnv(t *testing.T) { |
310 | 333 | for _, value := range []string{"1", "true", "TRUE", "yes", "on"} { |
311 | 334 | assert.True(t, isDisabledByEnv(value), value) |
|
0 commit comments