runasany_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package group
  14. import (
  15. "testing"
  16. "k8s.io/apimachinery/pkg/util/validation/field"
  17. )
  18. func TestRunAsAnyGenerate(t *testing.T) {
  19. s, err := NewRunAsAny()
  20. if err != nil {
  21. t.Fatalf("unexpected error initializing NewRunAsAny %v", err)
  22. }
  23. groups, err := s.Generate(nil)
  24. if len(groups) > 0 {
  25. t.Errorf("expected empty but got %v", groups)
  26. }
  27. if err != nil {
  28. t.Errorf("unexpected error generating groups: %v", err)
  29. }
  30. }
  31. func TestRunAsAnyGenerateSingle(t *testing.T) {
  32. s, err := NewRunAsAny()
  33. if err != nil {
  34. t.Fatalf("unexpected error initializing NewRunAsAny %v", err)
  35. }
  36. group, err := s.GenerateSingle(nil)
  37. if group != nil {
  38. t.Errorf("expected empty but got %v", group)
  39. }
  40. if err != nil {
  41. t.Errorf("unexpected error generating groups: %v", err)
  42. }
  43. }
  44. func TestRunAsAnyValidate(t *testing.T) {
  45. s, err := NewRunAsAny()
  46. if err != nil {
  47. t.Fatalf("unexpected error initializing NewRunAsAny %v", err)
  48. }
  49. errs := s.Validate(field.NewPath(""), nil, nil)
  50. if len(errs) != 0 {
  51. t.Errorf("unexpected errors: %v", errs)
  52. }
  53. }