-
Notifications
You must be signed in to change notification settings - Fork 86
/
http_log_part_sink_test.go
57 lines (46 loc) · 1.21 KB
/
http_log_part_sink_test.go
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
package worker
import (
"net/http"
"net/http/httptest"
"testing"
gocontext "context"
"github.com/stretchr/testify/assert"
)
func TestNewHTTPLogPartSink(t *testing.T) {
ctx, cancel := gocontext.WithCancel(gocontext.TODO())
cancel()
lps := newHTTPLogPartSink(
ctx,
"http://example.org/log-parts/multi",
uint64(1000))
assert.NotNil(t, lps)
}
func TestHTTPLogPartSink_flush(t *testing.T) {
lss := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
w.WriteHeader(http.StatusNoContent)
return
}
w.WriteHeader(http.StatusNotImplemented)
}))
defer lss.Close()
httpLogPartSinksByURLMutex.Lock()
httpLogPartSinksByURL[lss.URL] = newHTTPLogPartSink(gocontext.TODO(), lss.URL, uint64(1000))
httpLogPartSinksByURLMutex.Unlock()
ctx := gocontext.TODO()
lps := newHTTPLogPartSink(ctx, lss.URL, uint64(10))
lps.flush(gocontext.TODO())
_ = lps.Add(ctx, &httpLogPart{
JobID: uint64(4),
Content: "wat",
Number: 3,
Final: false,
})
lps.partsBufferMutex.Lock()
assert.Len(t, lps.partsBuffer, 1)
lps.partsBufferMutex.Unlock()
lps.flush(ctx)
lps.partsBufferMutex.Lock()
assert.Len(t, lps.partsBuffer, 0)
lps.partsBufferMutex.Unlock()
}