From 4495559ad648c3f7e3da3f4531ea457b872b5763 Mon Sep 17 00:00:00 2001 From: Ajit Yagaty Date: Thu, 14 Apr 2016 10:56:12 -0700 Subject: [PATCH] e2e: Test case for the etcdctlv3 'role grant' command. Adding a test case to test the 'role grant' sub-command. --- e2e/ctl_v3_role_test.go | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/e2e/ctl_v3_role_test.go b/e2e/ctl_v3_role_test.go index a38bd2aab..7716374f2 100644 --- a/e2e/ctl_v3_role_test.go +++ b/e2e/ctl_v3_role_test.go @@ -22,15 +22,19 @@ func TestCtlV3RoleAddClientTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(c func TestCtlV3RoleAddPeerTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(configPeerTLS)) } func TestCtlV3RoleAddTimeout(t *testing.T) { testCtl(t, roleAddTest, withDialTimeout(0)) } +func TestCtlV3RoleGrant(t *testing.T) { testCtl(t, roleGrantTest) } + func roleAddTest(cx ctlCtx) { cmdSet := []struct { args []string expectedStr string }{ + // Add a role. { args: []string{"add", "root"}, expectedStr: "Role root created", }, + // Try adding the same role. { args: []string{"add", "root"}, expectedStr: "role name already exists", @@ -46,6 +50,45 @@ func roleAddTest(cx ctlCtx) { } } +func roleGrantTest(cx ctlCtx) { + cmdSet := []struct { + args []string + expectedStr string + }{ + // Add a role. + { + args: []string{"add", "root"}, + expectedStr: "Role root created", + }, + // Grant read permission to the role. + { + args: []string{"grant", "root", "read", "foo"}, + expectedStr: "Role root updated", + }, + // Grant write permission to the role. + { + args: []string{"grant", "root", "write", "foo"}, + expectedStr: "Role root updated", + }, + // Grant rw permission to the role. + { + args: []string{"grant", "root", "readwrite", "foo"}, + expectedStr: "Role root updated", + }, + // Try granting invalid permission to the role. + { + args: []string{"grant", "root", "123", "foo"}, + expectedStr: "invalid permission type", + }, + } + + for i, cmd := range cmdSet { + if err := ctlV3Role(cx, cmd.args, cmd.expectedStr); err != nil { + cx.t.Fatalf("roleGrantTest #%d: ctlV3Role error (%v)", i, err) + } + } +} + func ctlV3Role(cx ctlCtx, args []string, expStr string) error { cmdArgs := append(cx.PrefixArgs(), "role") cmdArgs = append(cmdArgs, args...)