|
7 | 7 | "fmt" |
8 | 8 | "os" |
9 | 9 | "path/filepath" |
| 10 | + "strings" |
10 | 11 | "testing" |
11 | 12 | "time" |
12 | 13 |
|
@@ -142,7 +143,7 @@ func TestConfigRemove(t *testing.T) { |
142 | 143 | require.NoError(t, os.WriteFile(tmpcfg, []byte(`proxy.addr = "gg"`), 0644)) |
143 | 144 |
|
144 | 145 | // check that re-watch still works |
145 | | - require.Eventually(t, func() bool { return cfgmgr.GetConfig().Proxy.Addr == "gg" }, 3*time.Second, 100*time.Millisecond) |
| 146 | + require.Eventually(t, func() bool { return cfgmgr.GetConfig() != nil && cfgmgr.GetConfig().Proxy.Addr == "gg" }, 3*time.Second, 100*time.Millisecond) |
146 | 147 |
|
147 | 148 | // remove again but with a long sleep |
148 | 149 | require.NoError(t, os.Remove(tmpcfg)) |
@@ -298,13 +299,19 @@ func TestFilePath(t *testing.T) { |
298 | 299 | } |
299 | 300 |
|
300 | 301 | func TestChecksum(t *testing.T) { |
301 | | - cfgmgr, _, _ := testConfigManager(t, "", "") |
| 302 | + cfgmgr, text, _ := testConfigManager(t, "", "") |
| 303 | + require.Equal(t, 1, strings.Count(text.String(), "current config")) |
302 | 304 | c1 := cfgmgr.GetConfigChecksum() |
303 | 305 | require.NoError(t, cfgmgr.SetTOMLConfig([]byte(`proxy.addr = "gg"`))) |
| 306 | + require.Equal(t, 2, strings.Count(text.String(), "current config")) |
| 307 | + // same config, shouldn't log it again |
| 308 | + require.NoError(t, cfgmgr.SetTOMLConfig([]byte(`proxy.addr = "gg"`))) |
| 309 | + require.Equal(t, 2, strings.Count(text.String(), "current config")) |
304 | 310 | c2 := cfgmgr.GetConfigChecksum() |
305 | 311 | require.NoError(t, cfgmgr.SetTOMLConfig([]byte(`proxy.addr = "vv"`))) |
306 | 312 | c3 := cfgmgr.GetConfigChecksum() |
307 | 313 | require.NoError(t, cfgmgr.SetTOMLConfig([]byte(`proxy.addr="gg"`))) |
| 314 | + require.Equal(t, 4, strings.Count(text.String(), "current config")) |
308 | 315 | c4 := cfgmgr.GetConfigChecksum() |
309 | 316 | require.Equal(t, c2, c4) |
310 | 317 | require.NotEqual(t, c1, c2) |
|
0 commit comments