MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / TestStartAndStopSuccess

Function TestStartAndStopSuccess

internal/watcher/watcher_test.go:229–262  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

227}
228
229func TestStartAndStopSuccess(t *testing.T) {
230 tmpDir := t.TempDir()
231 authDir := filepath.Join(tmpDir, "auth")
232 if err := os.MkdirAll(authDir, 0o755); err != nil {
233 t.Fatalf("failed to create auth dir: %v", err)
234 }
235 configPath := filepath.Join(tmpDir, "config.yaml")
236 if err := os.WriteFile(configPath, []byte("auth_dir: "+authDir), 0o644); err != nil {
237 t.Fatalf("failed to create config file: %v", err)
238 }
239
240 var reloads int32
241 w, err := NewWatcher(configPath, authDir, func(*config.Config) {
242 atomic.AddInt32(&reloads, 1)
243 })
244 if err != nil {
245 t.Fatalf("failed to create watcher: %v", err)
246 }
247 w.SetConfig(&config.Config{AuthDir: authDir})
248
249 ctx, cancel := context.WithCancel(context.Background())
250 defer cancel()
251
252 if err := w.Start(ctx); err != nil {
253 t.Fatalf("expected Start to succeed: %v", err)
254 }
255 cancel()
256 if err := w.Stop(); err != nil {
257 t.Fatalf("expected Stop to succeed: %v", err)
258 }
259 if got := atomic.LoadInt32(&reloads); got != 1 {
260 t.Fatalf("expected one reload callback, got %d", got)
261 }
262}
263
264func TestStartFailsWhenConfigMissing(t *testing.T) {
265 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 4

SetConfigMethod · 0.95
StartMethod · 0.95
StopMethod · 0.95
NewWatcherFunction · 0.85

Tested by

no test coverage detected