unversioned_warning_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 (
  15. "testing"
  16. "github.com/stretchr/testify/assert"
  17. )
  18. func TestUnversionedWarning(t *testing.T) {
  19. beginMark := beginMungeTag(unversionedWarningTag)
  20. endMark := endMungeTag(unversionedWarningTag)
  21. warningString := makeUnversionedWarning("filename.md", false).String()
  22. warningBlock := beginMark + "\n" + warningString + endMark + "\n"
  23. var cases = []struct {
  24. in string
  25. expected string
  26. }{
  27. {"", warningBlock},
  28. {
  29. "Foo\nBar\n",
  30. warningBlock + "\nFoo\nBar\n",
  31. },
  32. {
  33. "Foo\n<!-- TAG IS_VERSIONED -->\nBar",
  34. "Foo\n<!-- TAG IS_VERSIONED -->\nBar",
  35. },
  36. {
  37. beginMark + "\n" + endMark + "\n",
  38. warningBlock,
  39. },
  40. {
  41. beginMark + "\n" + "something\n" + endMark + "\n",
  42. warningBlock,
  43. },
  44. {
  45. "Foo\n" + beginMark + "\n" + endMark + "\nBar\n",
  46. "Foo\n" + warningBlock + "Bar\n",
  47. },
  48. {
  49. "Foo\n" + warningBlock + "Bar\n",
  50. "Foo\n" + warningBlock + "Bar\n",
  51. },
  52. }
  53. for i, c := range cases {
  54. in := getMungeLines(c.in)
  55. expected := getMungeLines(c.expected)
  56. actual, err := updateUnversionedWarning("filename.md", in)
  57. assert.NoError(t, err)
  58. if !expected.Equal(actual) {
  59. t.Errorf("case[%d]: expected %v got %v", i, expected.String(), actual.String())
  60. }
  61. }
  62. }
  63. func TestMakeUnversionedWarning(t *testing.T) {
  64. const fileName = "filename.md"
  65. var cases = []struct {
  66. linkToReleaseDoc bool
  67. expected string
  68. }{
  69. {
  70. true,
  71. `
  72. <!-- BEGIN STRIP_FOR_RELEASE -->
  73. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  74. width="25" height="25">
  75. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  76. width="25" height="25">
  77. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  78. width="25" height="25">
  79. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  80. width="25" height="25">
  81. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  82. width="25" height="25">
  83. <h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
  84. If you are using a released version of Kubernetes, you should
  85. refer to the docs that go with that version.
  86. <!-- TAG RELEASE_LINK, added by the munger automatically -->
  87. <strong>
  88. The latest release of this document can be found
  89. [here](http://releases.k8s.io/release-1.3/filename.md).
  90. Documentation for other releases can be found at
  91. [releases.k8s.io](http://releases.k8s.io).
  92. </strong>
  93. --
  94. <!-- END STRIP_FOR_RELEASE -->
  95. `,
  96. },
  97. {
  98. false,
  99. `
  100. <!-- BEGIN STRIP_FOR_RELEASE -->
  101. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  102. width="25" height="25">
  103. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  104. width="25" height="25">
  105. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  106. width="25" height="25">
  107. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  108. width="25" height="25">
  109. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  110. width="25" height="25">
  111. <h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
  112. If you are using a released version of Kubernetes, you should
  113. refer to the docs that go with that version.
  114. Documentation for other releases can be found at
  115. [releases.k8s.io](http://releases.k8s.io).
  116. </strong>
  117. --
  118. <!-- END STRIP_FOR_RELEASE -->
  119. `,
  120. },
  121. }
  122. for i, c := range cases {
  123. if e, a := c.expected, makeUnversionedWarning(fileName, c.linkToReleaseDoc).String(); e != a {
  124. t.Errorf("case[%d]: \nexpected %s\ngot %s", i, e, a)
  125. }
  126. }
  127. }