aboutsummaryrefslogtreecommitdiff
path: root/internal/watcher/watcher_test.go
blob: 53c0baa2fe8f331d24bff5e343fe938a473936d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package watcher

import (
	"context"
	"testing"
	"time"
)

func TestRunReturnsOnContextCancellation(t *testing.T) {
	w := New(Config{})

	ctx, cancel := context.WithCancel(context.Background())

	done := make(chan error, 1)

	go func() {
		done <- w.Run(ctx)
	}()

	cancel()

	select {
	case err := <-done:
		if err != nil {
			t.Fatalf("expected nil, got %v", err)
		}

	case <-time.After(time.Second):
		t.Fatal("watcher did not exit")
	}
}