merge_map_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. Copyright 2017 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 strategy_test
  14. import (
  15. . "github.com/onsi/ginkgo"
  16. "k8s.io/kubernetes/pkg/kubectl/apply/strategy"
  17. )
  18. var _ = Describe("Merging fields of type map with openapi for some fields", func() {
  19. Context("where a field has been deleted", func() {
  20. It("should delete the field", func() {
  21. recorded := create(`
  22. apiVersion: apps/v1
  23. kind: Deployment
  24. spec:
  25. replicas: 3
  26. foo1:
  27. bar: "baz1"
  28. image: "1"
  29. `)
  30. local := create(`
  31. apiVersion: apps/v1
  32. kind: Deployment
  33. spec:
  34. replicas: 3
  35. foo2: null
  36. `)
  37. remote := create(`
  38. apiVersion: apps/v1
  39. kind: Deployment
  40. spec:
  41. replicas: 3
  42. foo1:
  43. bar: "baz1"
  44. image: "1"
  45. foo2:
  46. bar: "baz2"
  47. image: "2"
  48. foo3:
  49. bar: "baz3"
  50. image: "3"
  51. `)
  52. expected := create(`
  53. apiVersion: apps/v1
  54. kind: Deployment
  55. spec:
  56. replicas: 3
  57. foo3:
  58. bar: "baz3"
  59. image: "3"
  60. `)
  61. run(strategy.Create(strategy.Options{}), recorded, local, remote, expected)
  62. })
  63. })
  64. Context("where a field is has been added", func() {
  65. It("should add the field", func() {
  66. recorded := create(`
  67. apiVersion: apps/v1
  68. kind: Deployment
  69. spec:
  70. foo1:
  71. bar: "baz1"
  72. image: "1"
  73. `)
  74. local := create(`
  75. apiVersion: apps/v1
  76. kind: Deployment
  77. spec:
  78. replicas: 3
  79. foo1:
  80. bar: "baz1"
  81. image: "1"
  82. foo2:
  83. bar: "baz2"
  84. image: "2"
  85. `)
  86. remote := create(`
  87. apiVersion: apps/v1
  88. kind: Deployment
  89. spec:
  90. `)
  91. expected := create(`
  92. apiVersion: apps/v1
  93. kind: Deployment
  94. spec:
  95. replicas: 3
  96. foo1:
  97. bar: "baz1"
  98. image: "1"
  99. foo2:
  100. bar: "baz2"
  101. image: "2"
  102. `)
  103. run(strategy.Create(strategy.Options{}), recorded, local, remote, expected)
  104. })
  105. })
  106. Context("where a field is has been updated", func() {
  107. It("should update the field", func() {
  108. recorded := create(`
  109. apiVersion: apps/v1
  110. kind: Deployment
  111. spec:
  112. foo1:
  113. bar: "baz1=1"
  114. image: "1-1"
  115. `)
  116. local := create(`
  117. apiVersion: apps/v1
  118. kind: Deployment
  119. spec:
  120. replicas: 3
  121. foo1:
  122. bar: "baz1-1"
  123. image: "1-1"
  124. foo2:
  125. bar: "baz2-1"
  126. image: "2-1"
  127. `)
  128. remote := create(`
  129. apiVersion: apps/v1
  130. kind: Deployment
  131. spec:
  132. replicas: 2
  133. foo1:
  134. bar: "baz1-0"
  135. image: "1-0"
  136. foo2:
  137. bar: "baz2-0"
  138. image: "2-0"
  139. `)
  140. expected := create(`
  141. apiVersion: apps/v1
  142. kind: Deployment
  143. spec:
  144. replicas: 3
  145. foo1:
  146. bar: "baz1-1"
  147. image: "1-1"
  148. foo2:
  149. bar: "baz2-1"
  150. image: "2-1"
  151. `)
  152. run(strategy.Create(strategy.Options{}), recorded, local, remote, expected)
  153. })
  154. })
  155. })