commit 3bdcc3408ea2e5946dd27699e0f77e3f0f3816b2
Author: Cecylia Bocovich <coh...@torproject.org>
Date:   Wed Nov 27 10:55:48 2019 -0500

    Increased test coverage for messages library
---
 common/messages/proxy_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/common/messages/proxy_test.go b/common/messages/proxy_test.go
index 6783874..1570d4f 100644
--- a/common/messages/proxy_test.go
+++ b/common/messages/proxy_test.go
@@ -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) {
        Convey("Context", t, func() {
                for _, test := range []struct {
@@ -173,5 +224,11 @@ func TestEncodeProxyAnswerResponse(t *testing.T) {
                success, err := DecodeAnswerResponse(b)
                So(success, ShouldEqual, true)
                So(err, ShouldEqual, nil)
+
+               b, err = EncodeAnswerResponse(false)
+               So(err, ShouldEqual, nil)
+               success, err = DecodeAnswerResponse(b)
+               So(success, ShouldEqual, false)
+               So(err, ShouldEqual, nil)
        })
 }

_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to