Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to net-rpc-msgpackrpc #1307

Merged
merged 3 commits into from
Oct 15, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 48 additions & 47 deletions consul/acl_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/hashicorp/consul/consul/structs"
"github.com/hashicorp/consul/testutil"
"github.com/hashicorp/net-rpc-msgpackrpc"
)

func TestACLEndpoint_Apply(t *testing.T) {
Expand All @@ -17,10 +18,10 @@ func TestACLEndpoint_Apply(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

arg := structs.ACLRequest{
Datacenter: "dc1",
Expand All @@ -32,7 +33,7 @@ func TestACLEndpoint_Apply(t *testing.T) {
WriteRequest: structs.WriteRequest{Token: "root"},
}
var out string
if err := client.Call("ACL.Apply", &arg, &out); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out); err != nil {
t.Fatalf("err: %v", err)
}
id := out
Expand All @@ -56,7 +57,7 @@ func TestACLEndpoint_Apply(t *testing.T) {
// Do a delete
arg.Op = structs.ACLDelete
arg.ACL.ID = out
if err := client.Call("ACL.Apply", &arg, &out); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out); err != nil {
t.Fatalf("err: %v", err)
}

Expand All @@ -77,10 +78,10 @@ func TestACLEndpoint_Update_PurgeCache(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

arg := structs.ACLRequest{
Datacenter: "dc1",
Expand All @@ -92,7 +93,7 @@ func TestACLEndpoint_Update_PurgeCache(t *testing.T) {
WriteRequest: structs.WriteRequest{Token: "root"},
}
var out string
if err := client.Call("ACL.Apply", &arg, &out); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out); err != nil {
t.Fatalf("err: %v", err)
}
id := out
Expand All @@ -112,7 +113,7 @@ func TestACLEndpoint_Update_PurgeCache(t *testing.T) {
// Do an update
arg.ACL.ID = out
arg.ACL.Rules = `{"key": {"": {"policy": "deny"}}}`
if err := client.Call("ACL.Apply", &arg, &out); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out); err != nil {
t.Fatalf("err: %v", err)
}

Expand All @@ -134,7 +135,7 @@ func TestACLEndpoint_Update_PurgeCache(t *testing.T) {
// Do a delete
arg.Op = structs.ACLDelete
arg.ACL.Rules = ""
if err := client.Call("ACL.Apply", &arg, &out); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out); err != nil {
t.Fatalf("err: %v", err)
}

Expand All @@ -155,10 +156,10 @@ func TestACLEndpoint_Apply_CustomID(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

arg := structs.ACLRequest{
Datacenter: "dc1",
Expand All @@ -171,7 +172,7 @@ func TestACLEndpoint_Apply_CustomID(t *testing.T) {
WriteRequest: structs.WriteRequest{Token: "root"},
}
var out string
if err := client.Call("ACL.Apply", &arg, &out); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out); err != nil {
t.Fatalf("err: %v", err)
}
if out != "foobarbaz" {
Expand Down Expand Up @@ -201,10 +202,10 @@ func TestACLEndpoint_Apply_Denied(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

arg := structs.ACLRequest{
Datacenter: "dc1",
Expand All @@ -215,7 +216,7 @@ func TestACLEndpoint_Apply_Denied(t *testing.T) {
},
}
var out string
err := client.Call("ACL.Apply", &arg, &out)
err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
Expand All @@ -228,10 +229,10 @@ func TestACLEndpoint_Apply_DeleteAnon(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

arg := structs.ACLRequest{
Datacenter: "dc1",
Expand All @@ -244,7 +245,7 @@ func TestACLEndpoint_Apply_DeleteAnon(t *testing.T) {
WriteRequest: structs.WriteRequest{Token: "root"},
}
var out string
err := client.Call("ACL.Apply", &arg, &out)
err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out)
if err == nil || !strings.Contains(err.Error(), "delete anonymous") {
t.Fatalf("err: %v", err)
}
Expand All @@ -257,10 +258,10 @@ func TestACLEndpoint_Apply_RootChange(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

arg := structs.ACLRequest{
Datacenter: "dc1",
Expand All @@ -273,7 +274,7 @@ func TestACLEndpoint_Apply_RootChange(t *testing.T) {
WriteRequest: structs.WriteRequest{Token: "root"},
}
var out string
err := client.Call("ACL.Apply", &arg, &out)
err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out)
if err == nil || !strings.Contains(err.Error(), "root ACL") {
t.Fatalf("err: %v", err)
}
Expand All @@ -286,10 +287,10 @@ func TestACLEndpoint_Get(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

arg := structs.ACLRequest{
Datacenter: "dc1",
Expand All @@ -301,7 +302,7 @@ func TestACLEndpoint_Get(t *testing.T) {
WriteRequest: structs.WriteRequest{Token: "root"},
}
var out string
if err := client.Call("ACL.Apply", &arg, &out); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out); err != nil {
t.Fatalf("err: %v", err)
}

Expand All @@ -310,7 +311,7 @@ func TestACLEndpoint_Get(t *testing.T) {
ACL: out,
}
var acls structs.IndexedACLs
if err := client.Call("ACL.Get", &getR, &acls); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Get", &getR, &acls); err != nil {
t.Fatalf("err: %v", err)
}

Expand All @@ -333,10 +334,10 @@ func TestACLEndpoint_GetPolicy(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

arg := structs.ACLRequest{
Datacenter: "dc1",
Expand All @@ -348,7 +349,7 @@ func TestACLEndpoint_GetPolicy(t *testing.T) {
WriteRequest: structs.WriteRequest{Token: "root"},
}
var out string
if err := client.Call("ACL.Apply", &arg, &out); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out); err != nil {
t.Fatalf("err: %v", err)
}

Expand All @@ -357,7 +358,7 @@ func TestACLEndpoint_GetPolicy(t *testing.T) {
ACL: out,
}
var acls structs.ACLPolicy
if err := client.Call("ACL.GetPolicy", &getR, &acls); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.GetPolicy", &getR, &acls); err != nil {
t.Fatalf("err: %v", err)
}

Expand All @@ -371,7 +372,7 @@ func TestACLEndpoint_GetPolicy(t *testing.T) {
// Do a conditional lookup with etag
getR.ETag = acls.ETag
var out2 structs.ACLPolicy
if err := client.Call("ACL.GetPolicy", &getR, &out2); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.GetPolicy", &getR, &out2); err != nil {
t.Fatalf("err: %v", err)
}

Expand All @@ -390,10 +391,10 @@ func TestACLEndpoint_List(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

ids := []string{}
for i := 0; i < 5; i++ {
Expand All @@ -407,7 +408,7 @@ func TestACLEndpoint_List(t *testing.T) {
WriteRequest: structs.WriteRequest{Token: "root"},
}
var out string
if err := client.Call("ACL.Apply", &arg, &out); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.Apply", &arg, &out); err != nil {
t.Fatalf("err: %v", err)
}
ids = append(ids, out)
Expand All @@ -418,7 +419,7 @@ func TestACLEndpoint_List(t *testing.T) {
QueryOptions: structs.QueryOptions{Token: "root"},
}
var acls structs.IndexedACLs
if err := client.Call("ACL.List", &getR, &acls); err != nil {
if err := msgpackrpc.CallWithCodec(codec, "ACL.List", &getR, &acls); err != nil {
t.Fatalf("err: %v", err)
}

Expand Down Expand Up @@ -450,16 +451,16 @@ func TestACLEndpoint_List_Denied(t *testing.T) {
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
codec := rpcClient(t, s1)
defer codec.Close()

testutil.WaitForLeader(t, client.Call, "dc1")
testutil.WaitForLeader(t, s1.RPC, "dc1")

getR := structs.DCSpecificRequest{
Datacenter: "dc1",
}
var acls structs.IndexedACLs
err := client.Call("ACL.List", &getR, &acls)
err := msgpackrpc.CallWithCodec(codec, "ACL.List", &getR, &acls)
if err == nil || !strings.Contains(err.Error(), permissionDenied) {
t.Fatalf("err: %v", err)
}
Expand Down
Loading