-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtestutil_test.go
More file actions
49 lines (37 loc) · 1020 Bytes
/
testutil_test.go
File metadata and controls
49 lines (37 loc) · 1020 Bytes
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
package testutil
import (
"bytes"
"io"
"net/http"
"testing"
"github.com/arschles/assert"
)
type nopCloser struct {
io.Reader
}
func (nopCloser) Close() error { return nil }
// TestStripProgress ensures StripProgress strips what is expected.
func TestStripProgress(t *testing.T) {
testInput := "Lorem ipsum dolar sit amet"
expectedOutput := "Lorem ipsum dolar sit amet"
assert.Equal(t, StripProgress(testInput), expectedOutput, "output")
testInput = "Lorem ipsum dolar sit amet...\b\b\b"
assert.Equal(t, StripProgress(testInput), expectedOutput, "output")
}
// TestAssertBody ensures AssertBody correctly marshals into the interface.
func TestAssertBody(t *testing.T) {
b := nopCloser{bytes.NewBufferString(`{"data":{"lorem":"ipsum"},"dolar":["sit","amet"]}`)}
sampleRequest := http.Request{
Body: b,
}
expected := map[string]interface{}{
"data": map[string]interface{}{
"lorem": "ipsum",
},
"dolar": []string{
"sit",
"amet",
},
}
AssertBody(t, expected, &sampleRequest)
}