dryrun_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright 2018 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 openapi_test
  14. import (
  15. "testing"
  16. "k8s.io/apimachinery/pkg/runtime/schema"
  17. "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
  18. )
  19. func TestSupportsDryRun(t *testing.T) {
  20. doc, err := fakeSchema.OpenAPISchema()
  21. if err != nil {
  22. t.Fatalf("Failed to get OpenAPI Schema: %v", err)
  23. }
  24. tests := []struct {
  25. gvk schema.GroupVersionKind
  26. success bool
  27. supports bool
  28. }{
  29. {
  30. gvk: schema.GroupVersionKind{
  31. Group: "",
  32. Version: "v1",
  33. Kind: "Pod",
  34. },
  35. success: true,
  36. supports: true,
  37. },
  38. {
  39. gvk: schema.GroupVersionKind{
  40. Group: "",
  41. Version: "v1",
  42. Kind: "UnknownKind",
  43. },
  44. success: false,
  45. supports: false,
  46. },
  47. {
  48. gvk: schema.GroupVersionKind{
  49. Group: "",
  50. Version: "v1",
  51. Kind: "NodeProxyOptions",
  52. },
  53. success: true,
  54. supports: false,
  55. },
  56. }
  57. for _, test := range tests {
  58. supports, err := openapi.SupportsDryRun(doc, test.gvk)
  59. if supports != test.supports || ((err == nil) != test.success) {
  60. errStr := "nil"
  61. if test.success == false {
  62. errStr = "err"
  63. }
  64. t.Errorf("SupportsDryRun(doc, %v) = (%v, %v), expected (%v, %v)",
  65. test.gvk,
  66. supports, err,
  67. test.supports, errStr,
  68. )
  69. }
  70. }
  71. }