-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher_task_test.go
More file actions
81 lines (62 loc) · 1.99 KB
/
watcher_task_test.go
File metadata and controls
81 lines (62 loc) · 1.99 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package wadjit
import (
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
// TODO: potentially rename file as "task_test.go"
type watcherTaskTestSuite struct {
newTask func() WatcherTask
}
func (s *watcherTaskTestSuite) TestWatcherTaskInitialize(t *testing.T) {
task := s.newTask()
responseChan := make(chan WatcherResponse, 1)
err := task.Initialize("test-watcher-id", responseChan)
assert.NoError(t, err)
}
func (s *watcherTaskTestSuite) TestWatcherTaskTask(t *testing.T) {
task := s.newTask()
responseChan := make(chan WatcherResponse, 1)
err := task.Initialize("test-watcher-id", responseChan)
assert.NoError(t, err)
tk := task.Task()
assert.NotNil(t, tk)
}
func (s *watcherTaskTestSuite) TestWatcherTaskValidate(t *testing.T) {
task := s.newTask()
responseChan := make(chan WatcherResponse, 1)
err := task.Initialize("test-watcher-id", responseChan)
assert.NoError(t, err)
err = task.Validate()
assert.NoError(t, err)
}
func (s *watcherTaskTestSuite) TestWatcherTaskClose(t *testing.T) {
task := s.newTask()
responseChan := make(chan WatcherResponse, 1)
err := task.Initialize("test-watcher-id", responseChan)
assert.NoError(t, err)
err = task.Close()
assert.NoError(t, err)
}
func runWatcherTaskTestSuite(t *testing.T, s *watcherTaskTestSuite) {
t.Run("Initialize", s.TestWatcherTaskInitialize)
t.Run("Task", s.TestWatcherTaskTask)
t.Run("Validate", s.TestWatcherTaskValidate)
t.Run("Close", s.TestWatcherTaskClose)
}
func TestWatcherTaskSuite(t *testing.T) {
testURL, _ := url.Parse("http://example.com")
t.Run("HTTPEndpoint", func(t *testing.T) {
newTask := func() WatcherTask {
return NewHTTPEndpoint(testURL, http.MethodGet, WithID("test-id"))
}
runWatcherTaskTestSuite(t, &watcherTaskTestSuite{newTask: newTask})
})
t.Run("WSEndpoint", func(t *testing.T) {
newTask := func() WatcherTask {
return NewWSEndpoint(testURL, http.Header{}, OneHitText, nil, "test-id")
}
runWatcherTaskTestSuite(t, &watcherTaskTestSuite{newTask: newTask})
})
}