kubectl_dash_f_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. Copyright 2015 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 main
  14. import "testing"
  15. func TestKubectlDashF(t *testing.T) {
  16. var cases = []struct {
  17. in string
  18. ok bool
  19. }{
  20. // No match
  21. {"", true},
  22. {
  23. "Foo\nBar\n",
  24. true,
  25. },
  26. {
  27. "Foo\nkubectl blah blech\nBar",
  28. true,
  29. },
  30. {
  31. "Foo\n```shell\nkubectl blah blech\n```\nBar",
  32. true,
  33. },
  34. {
  35. "Foo\n```\nkubectl -blah create blech\n```\nBar",
  36. true,
  37. },
  38. // Special cases
  39. {
  40. "Foo\n```\nkubectl -blah create -f -\n```\nBar",
  41. true,
  42. },
  43. {
  44. "Foo\n```\nkubectl -blah create -f-\n```\nBar",
  45. true,
  46. },
  47. {
  48. "Foo\n```\nkubectl -blah create -f FILENAME\n```\nBar",
  49. true,
  50. },
  51. {
  52. "Foo\n```\nkubectl -blah create -fFILENAME\n```\nBar",
  53. true,
  54. },
  55. {
  56. "Foo\n```\nkubectl -blah create -f http://google.com/foobar\n```\nBar",
  57. true,
  58. },
  59. {
  60. "Foo\n```\nkubectl -blah create -fhttp://google.com/foobar\n```\nBar",
  61. true,
  62. },
  63. {
  64. "Foo\n```\nkubectl -blah create -f ./foobar\n```\nBar",
  65. true,
  66. },
  67. {
  68. "Foo\n```\nkubectl -blah create -f./foobar\n```\nBar",
  69. true,
  70. },
  71. {
  72. "Foo\n```\nkubectl -blah create -f /foobar\n```\nBar",
  73. true,
  74. },
  75. {
  76. "Foo\n```\nkubectl -blah create -f/foobar\n```\nBar",
  77. true,
  78. },
  79. {
  80. "Foo\n```\nkubectl -blah create -f~/foobar\n```\nBar",
  81. true,
  82. },
  83. // Real checks
  84. {
  85. "Foo\n```\nkubectl -blah create -f mungedocs.go\n```\nBar",
  86. true,
  87. },
  88. {
  89. "Foo\n```\nkubectl -blah create -fmungedocs.go\n```\nBar",
  90. true,
  91. },
  92. {
  93. "Foo\n```\nkubectl -blah update -f mungedocs.go\n```\nBar",
  94. true,
  95. },
  96. {
  97. "Foo\n```\nkubectl -blah update -fmungedocs.go\n```\nBar",
  98. true,
  99. },
  100. {
  101. "Foo\n```\nkubectl -blah replace -f mungedocs.go\n```\nBar",
  102. true,
  103. },
  104. {
  105. "Foo\n```\nkubectl -blah replace -fmungedocs.go\n```\nBar",
  106. true,
  107. },
  108. {
  109. "Foo\n```\nkubectl -blah delete -f mungedocs.go\n```\nBar",
  110. true,
  111. },
  112. {
  113. "Foo\n```\nkubectl -blah delete -fmungedocs.go\n```\nBar",
  114. true,
  115. },
  116. // Failures
  117. {
  118. "Foo\n```\nkubectl -blah delete -f does_not_exist\n```\nBar",
  119. false,
  120. },
  121. {
  122. "Foo\n```\nkubectl -blah delete -fdoes_not_exist\n```\nBar",
  123. false,
  124. },
  125. }
  126. for i, c := range cases {
  127. repoRoot = ""
  128. in := getMungeLines(c.in)
  129. _, err := updateKubectlFileTargets("filename.md", in)
  130. if err != nil && c.ok {
  131. t.Errorf("case[%d]: expected success, got %v", i, err)
  132. }
  133. if err == nil && !c.ok {
  134. t.Errorf("case[%d]: unexpected success", i)
  135. }
  136. }
  137. }