-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest.put_test.go
50 lines (43 loc) · 1.06 KB
/
request.put_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
package braid
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestPutRequestRoundTrip(t *testing.T) {
patch1 := []byte(`{"asdf": "jkl;"}`)
patch2 := []byte(`{"braid": "http", "oof": ["rab", "zab"]}`)
expected := &PutRequest{
ContentType: "application/json",
Accept: "application/json",
Version: "12345",
Parents: []string{"foo", "bar"},
Patches: []Patch{
{
Name: "patch-type-1",
ContentRange: "json [-0:-0]",
ContentLength: uint64(len(patch1)),
ExtraHeaders: map[string]string{
"Quux": "xyzzy",
"Quack": "duck",
},
Body: patch1,
},
{
Name: "patch-type-2",
ContentRange: "json .foo.bar",
ContentLength: uint64(len(patch2)),
ExtraHeaders: map[string]string{
"Encoding": "flarf",
"Cache": "zork",
},
Body: patch2,
},
},
}
req, err := MakePutRequest(context.Background(), "http://braid.org", *expected)
require.NoError(t, err)
got, err := ReadPutRequest(req)
require.NoError(t, err)
require.Equal(t, expected, got)
}