forked from qustavo/httplab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump_test.go
43 lines (36 loc) · 994 Bytes
/
dump_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
package httplab
import (
"bytes"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDumpRequestWithJSON(t *testing.T) {
t.Run("should be indented", func(t *testing.T) {
req, _ := http.NewRequest("GET", "/withJSON", bytes.NewBuffer(
[]byte(`{"foo": "bar", "a": [1,2,3]}`),
))
req.Header.Set("Content-Type", "application/json")
buf, err := DumpRequest(req)
require.NoError(t, err)
fmt.Printf("%s\n", buf)
})
t.Run("should be displayed as is", func(t *testing.T) {
req, _ := http.NewRequest("GET", "/invalidJSON", bytes.NewBuffer(
[]byte(`invalid json`),
))
req.Header.Set("Content-Type", "application/json")
buf, err := DumpRequest(req)
require.NoError(t, err)
fmt.Printf("%s\n", buf)
})
}
func TestDecolorization(t *testing.T) {
for i, _ := range [107]struct{}{} {
text := "Some Text"
nocolor := Decolorize([]byte(withColor(i, text)))
assert.Equal(t, text, string(nocolor))
}
}