mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Increased test coverage for messages library
This commit is contained in:
parent
0f99c5ab12
commit
3bdcc3408e
1 changed files with 57 additions and 0 deletions
|
@ -82,6 +82,57 @@ func TestEncodeProxyPollRequests(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDecodeProxyPollResponse(t *testing.T) {
|
||||||
|
Convey("Context", t, func() {
|
||||||
|
for _, test := range []struct {
|
||||||
|
offer string
|
||||||
|
data string
|
||||||
|
err error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"fake offer",
|
||||||
|
`{"Status":"client match","Offer":"fake offer"}`,
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
`{"Status":"no match"}`,
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
`{"Status":"client match"}`,
|
||||||
|
fmt.Errorf("no supplied offer"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
`{"Test":"test"}`,
|
||||||
|
fmt.Errorf(""),
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
offer, err := DecodePollResponse([]byte(test.data))
|
||||||
|
So(offer, ShouldResemble, test.offer)
|
||||||
|
So(err, ShouldHaveSameTypeAs, test.err)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEncodeProxyPollResponse(t *testing.T) {
|
||||||
|
Convey("Context", t, func() {
|
||||||
|
b, err := EncodePollResponse("fake offer", true)
|
||||||
|
So(err, ShouldEqual, nil)
|
||||||
|
offer, err := DecodePollResponse(b)
|
||||||
|
So(offer, ShouldEqual, "fake offer")
|
||||||
|
So(err, ShouldEqual, nil)
|
||||||
|
|
||||||
|
b, err = EncodePollResponse("", false)
|
||||||
|
So(err, ShouldEqual, nil)
|
||||||
|
offer, err = DecodePollResponse(b)
|
||||||
|
So(offer, ShouldEqual, "")
|
||||||
|
So(err, ShouldEqual, nil)
|
||||||
|
})
|
||||||
|
}
|
||||||
func TestDecodeProxyAnswerRequest(t *testing.T) {
|
func TestDecodeProxyAnswerRequest(t *testing.T) {
|
||||||
Convey("Context", t, func() {
|
Convey("Context", t, func() {
|
||||||
for _, test := range []struct {
|
for _, test := range []struct {
|
||||||
|
@ -173,5 +224,11 @@ func TestEncodeProxyAnswerResponse(t *testing.T) {
|
||||||
success, err := DecodeAnswerResponse(b)
|
success, err := DecodeAnswerResponse(b)
|
||||||
So(success, ShouldEqual, true)
|
So(success, ShouldEqual, true)
|
||||||
So(err, ShouldEqual, nil)
|
So(err, ShouldEqual, nil)
|
||||||
|
|
||||||
|
b, err = EncodeAnswerResponse(false)
|
||||||
|
So(err, ShouldEqual, nil)
|
||||||
|
success, err = DecodeAnswerResponse(b)
|
||||||
|
So(success, ShouldEqual, false)
|
||||||
|
So(err, ShouldEqual, nil)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue