-
Notifications
You must be signed in to change notification settings - Fork 1
/
proxy_test.go
47 lines (35 loc) · 1.37 KB
/
proxy_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
package message_test
import (
"testing"
message "github.com/iij/legs-message"
"github.com/stretchr/testify/assert"
)
func TestNewProxyRequest(t *testing.T) {
msg := message.NewProxyRequest("server-id", "id", "session-id", "url", []byte("request"))
b, err := message.Marshal(msg)
assert.Nil(t, err)
parsed := &message.Proxy{}
err = message.Unmarshal(b, parsed)
assert.Nil(t, err)
assert.Equal(t, "proxy", parsed.MessageType)
assert.Equal(t, "proxy_request", parsed.Model)
assert.Equal(t, "server-id", parsed.Data.ServerID)
assert.Equal(t, "id", parsed.Data.ID)
assert.Equal(t, "session-id", parsed.Data.SessionID)
assert.Equal(t, "url", parsed.Data.URL)
assert.Equal(t, []byte("request"), parsed.Data.Request)
assert.Equal(t, []byte(nil), parsed.Data.Response)
}
func TestNewProxyResponse(t *testing.T) {
requestMsg := message.NewProxyRequest("server-id", "id", "session-id", "url", []byte("request"))
msg := message.NewProxyResponse(requestMsg.(*message.Proxy).Data, []byte("response message"))
b, err := message.Marshal(msg)
assert.Nil(t, err)
parsed := &message.Proxy{}
err = message.Unmarshal(b, parsed)
assert.Nil(t, err)
assert.Equal(t, "proxy", parsed.MessageType)
assert.Equal(t, "proxy_response", parsed.Model)
assert.Equal(t, requestMsg.(*message.Proxy).Data.Request, parsed.Data.Request)
assert.Equal(t, []byte("response message"), parsed.Data.Response)
}