Giter Site home page Giter Site logo

ptrs_orig's People

Contributors

jmwample avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

ptrs_orig's Issues

Report and fix goptlib test oversight.

This is not actually a bug in the code - everything works as it expects to, this is just a bad test case that should fail, but doesn't.

When you actually check that the Args parsed in the tests match there is an issue in one of the "Good" test cases.

diff --git a/pt_test.go b/pt_test.go
index d74d6d7..b261da5 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -275,7 +275,7 @@ func TestResolveAddr(t *testing.T) {
 
 func bindaddrSliceContains(s []Bindaddr, v Bindaddr) bool {
        for _, sv := range s {
-               if sv.MethodName == v.MethodName && tcpAddrsEqual(sv.Addr, v.Addr) {
+               if sv.MethodName == v.MethodName && tcpAddrsEqual(sv.Addr, v.Addr) && argsEqual(sv.Options, v.Options) {
                        return true
                }
        }

This causes the TestGetServerBindaddrs to fail.

$ go test -v -run TestGetServerBindaddrs                                                                                                                                                                                         :main|✚2
=== RUN   TestGetServerBindaddrs
    pt_test.go:435: TOR_PT_SERVER_BINDADDR="alpha-1.2.3.4:1111,beta-[1:2::3:4]:2222" TOR_PT_SERVER_TRANSPORTS="alpha,beta,gamma" TOR_PT_SERVER_TRANSPORT_OPTIONS="alpha:k1=v1,beta:k2=v2,gamma:k3=v3" → [{"alpha" "1.2.3.4:1111" map["k1":["v1,beta:k2=v2,gamma:k3=v3"]]} {"beta" "[1:2::3:4]:2222" map[]}] (expected [{"alpha" "1.2.3.4:1111" map["k1":["v1"]]} {"beta" "[1:2::3:4]:2222" map["k2":["v2"]]}])
--- FAIL: TestGetServerBindaddrs (0.00s)
FAIL
exit status 1
FAIL	git.torproject.org/pluggable-transports/goptlib.git	0.016s

This is due to the use of commas instead of semi-colons in the ptServerTransportOptions test parameter. We can update this and add a second test to make sure these are handled correctly:

diff --git a/pt_test.go b/pt_test.go
index d74d6d7..5501afe 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -275,7 +275,7 @@ func TestResolveAddr(t *testing.T) {
 
 func bindaddrSliceContains(s []Bindaddr, v Bindaddr) bool {
        for _, sv := range s {
-               if sv.MethodName == v.MethodName && tcpAddrsEqual(sv.Addr, v.Addr) {
+               if sv.MethodName == v.MethodName && tcpAddrsEqual(sv.Addr, v.Addr) && argsEqual(sv.Options, v.Options) {
                        return true
                }
        }
@@ -355,6 +355,15 @@ func TestGetServerBindaddrs(t *testing.T) {
                        "alpha-1.2.3.4:1111,beta-[1:2::3:4]:2222",
                        "alpha,beta,gamma",
                        "alpha:k1=v1,beta:k2=v2,gamma:k3=v3",
+                       []Bindaddr{
+                               {"alpha", &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}, Args{"k1": []string{"v1,beta:k2=v2,gamma:k3=v3"}}},
+                               {"beta", &net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 2222}, Args{}},
+                       },
+               },
+               {
+                       "alpha-1.2.3.4:1111,beta-[1:2::3:4]:2222",
+                       "alpha,beta,gamma",
+                       "alpha:k1=v1;beta:k2=v2;gamma:k3=v3",
                        []Bindaddr{
                                {"alpha", &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}, Args{"k1": []string{"v1"}}},
                                {"beta", &net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 2222}, Args{"k2": []string{"v2"}}},

It might also be worth adding similar tests to args_test.go to make sure this is functioning properly (it seems to be).

diff --git a/args_test.go b/args_test.go
index ff8a950..fae110d 100644
--- a/args_test.go
+++ b/args_test.go
@@ -281,6 +281,12 @@ func TestParseServerTransportOptions(t *testing.T) {
                                "t2": {"k": []string{"v2"}},
                        },
                },
+               {
+                       "alpha:k1=v1,beta:k2=v2,gamma:k3=v3",
+                       map[string]Args{
+                               "alpha": {"k1": []string{"v1,beta:k2=v2,gamma:k3=v3"}},
+                       },
+               },
                {
                        "t\\:1:k=v;t\\=2:k=v;t\\;3:k=v;t\\\\4:k=v",
                        map[string]Args{

`std::convert::From` Implementations for Args and Opts

Currently Args and Opts use Strings. This is pretty inconvenient to declare and use in tests. It would be nice to have an implmenetation of From<Hashmap<&str, Vec<&str>>> for Args and an equivalent for Opts.

This is not possible for type aliases which both Opts and Args currently are. This issue should be used to consider transitioning these types to the newtype pattern to allow implementations for non-local traits.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.