ctl_v3_role_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2016 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package e2e
  15. import "testing"
  16. func TestCtlV3RoleAdd(t *testing.T) { testCtl(t, roleAddTest) }
  17. func TestCtlV3RoleAddNoTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(configNoTLS)) }
  18. func TestCtlV3RoleAddClientTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(configClientTLS)) }
  19. func TestCtlV3RoleAddPeerTLS(t *testing.T) { testCtl(t, roleAddTest, withCfg(configPeerTLS)) }
  20. func TestCtlV3RoleAddTimeout(t *testing.T) { testCtl(t, roleAddTest, withDialTimeout(0)) }
  21. func roleAddTest(cx ctlCtx) {
  22. cmdSet := []struct {
  23. args []string
  24. expectedStr string
  25. }{
  26. {
  27. args: []string{"add", "root"},
  28. expectedStr: "Role root created",
  29. },
  30. {
  31. args: []string{"add", "root"},
  32. expectedStr: "role name already exists",
  33. },
  34. }
  35. for i, cmd := range cmdSet {
  36. if err := ctlV3Role(cx, cmd.args, cmd.expectedStr); err != nil {
  37. if cx.dialTimeout > 0 && !isGRPCTimedout(err) {
  38. cx.t.Fatalf("roleAddTest #%d: ctlV3Role error (%v)", i, err)
  39. }
  40. }
  41. }
  42. }
  43. func ctlV3Role(cx ctlCtx, args []string, expStr string) error {
  44. cmdArgs := append(cx.PrefixArgs(), "role")
  45. cmdArgs = append(cmdArgs, args...)
  46. return spawnWithExpect(cmdArgs, expStr)
  47. }