kustomize_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright 2019 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 kustomize
  14. import (
  15. "testing"
  16. )
  17. func TestValidate(t *testing.T) {
  18. var cases = []struct {
  19. name string
  20. args []string
  21. path string
  22. erMsg string
  23. }{
  24. {"noargs", []string{}, "./", ""},
  25. {"file", []string{"beans"}, "beans", ""},
  26. {"path", []string{"a/b/c"}, "a/b/c", ""},
  27. {"path", []string{"too", "many"},
  28. "", "specify one path to a kustomization directory"},
  29. }
  30. for _, mycase := range cases {
  31. opts := kustomizeOptions{}
  32. e := opts.Validate(mycase.args)
  33. if len(mycase.erMsg) > 0 {
  34. if e == nil {
  35. t.Errorf("%s: Expected an error %v", mycase.name, mycase.erMsg)
  36. }
  37. if e.Error() != mycase.erMsg {
  38. t.Errorf("%s: Expected error %s, but got %v", mycase.name, mycase.erMsg, e)
  39. }
  40. continue
  41. }
  42. if e != nil {
  43. t.Errorf("%s: unknown error %v", mycase.name, e)
  44. continue
  45. }
  46. if opts.kustomizationDir != mycase.path {
  47. t.Errorf("%s: expected path '%s', got '%s'", mycase.name, mycase.path, opts.kustomizationDir)
  48. }
  49. }
  50. }