]> Cypherpunks repositories - gostls13.git/commitdiff
net/rpc: verify that embedding works with changed semantics
authorMarcel van Lohuizen <mpvl@golang.org>
Mon, 26 Oct 2015 15:09:48 +0000 (16:09 +0100)
committerMarcel van Lohuizen <mpvl@golang.org>
Fri, 13 Nov 2015 19:47:35 +0000 (19:47 +0000)
Exported methods of unexported embedded structs get added
correctly to the pool. Behavior is unchanged before and after
https://golang.org/cl/14085.

Change-Id: I2b4053bab02ff045f0a4577b8114808a60aae27e
Reviewed-on: https://go-review.googlesource.com/16305
Reviewed-by: Russ Cox <rsc@golang.org>
src/net/rpc/server_test.go

index 498217b6ed69e6a50fe8c863e9e7f7e9058bbebf..8871c88133c845f1da874dd4e0444aad8975c4f2 100644 (file)
@@ -74,6 +74,17 @@ func (t *Arith) Error(args *Args, reply *Reply) error {
        panic("ERROR")
 }
 
+type hidden int
+
+func (t *hidden) Exported(args Args, reply *Reply) error {
+       reply.C = args.A + args.B
+       return nil
+}
+
+type Embed struct {
+       hidden
+}
+
 func listenTCP() (net.Listener, string) {
        l, e := net.Listen("tcp", "127.0.0.1:0") // any available address
        if e != nil {
@@ -84,6 +95,7 @@ func listenTCP() (net.Listener, string) {
 
 func startServer() {
        Register(new(Arith))
+       Register(new(Embed))
        RegisterName("net.rpc.Arith", new(Arith))
 
        var l net.Listener
@@ -98,6 +110,7 @@ func startServer() {
 func startNewServer() {
        newServer = NewServer()
        newServer.Register(new(Arith))
+       newServer.Register(new(Embed))
        newServer.RegisterName("net.rpc.Arith", new(Arith))
        newServer.RegisterName("newServer.Arith", new(Arith))
 
@@ -142,6 +155,17 @@ func testRPC(t *testing.T, addr string) {
                t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
        }
 
+       // Methods exported from unexported embedded structs
+       args = &Args{7, 0}
+       reply = new(Reply)
+       err = client.Call("Embed.Exported", args, reply)
+       if err != nil {
+               t.Errorf("Add: expected no error but got string %q", err.Error())
+       }
+       if reply.C != args.A+args.B {
+               t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
+       }
+
        // Nonexistent method
        args = &Args{7, 0}
        reply = new(Reply)