forked from stoewer/go-nakadi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_test.go
59 lines (49 loc) · 1.22 KB
/
helper_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
58
59
package nakadi
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewHTTPClient(t *testing.T) {
timeout := 20 * time.Second
client := newHTTPClient(timeout)
require.NotNil(t, client)
assert.Equal(t, timeout, client.Timeout)
}
func TestNewHTTPStream(t *testing.T) {
timeout := 20 * time.Second
client := newHTTPStream(timeout)
require.NotNil(t, client)
assert.Equal(t, 0*time.Second, client.Timeout)
}
func TestProblemJSON_Marshal(t *testing.T) {
problem := &problemJSON{}
expected := helperLoadTestData(t, "problem-json.json", problem)
serialized, err := json.Marshal(problem)
require.NoError(t, err)
assert.JSONEq(t, string(expected), string(serialized))
}
func helperLoadTestData(t *testing.T, name string, target interface{}) []byte {
path := filepath.Join("testdata", name)
bytes, err := ioutil.ReadFile(path)
require.NoError(t, err)
if target != nil {
err = json.Unmarshal(bytes, target)
require.NoError(t, err)
}
return bytes
}
func helperMakeCounter(n int) chan int {
counter := make(chan int)
go func() {
for i := 0; i <= n; i++ {
counter <- i
}
close(counter)
}()
return counter
}