horizontalpodautoscaler_test.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 unversioned_test
  14. import (
  15. "net/url"
  16. "testing"
  17. "k8s.io/kubernetes/pkg/api"
  18. "k8s.io/kubernetes/pkg/api/testapi"
  19. "k8s.io/kubernetes/pkg/apis/autoscaling"
  20. "k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
  21. )
  22. func getHorizontalPodAutoscalersResoureName() string {
  23. return "horizontalpodautoscalers"
  24. }
  25. func TestHorizontalPodAutoscalerCreate(t *testing.T) {
  26. ns := api.NamespaceDefault
  27. horizontalPodAutoscaler := autoscaling.HorizontalPodAutoscaler{
  28. ObjectMeta: api.ObjectMeta{
  29. Name: "abc",
  30. Namespace: ns,
  31. },
  32. }
  33. c := &simple.Client{
  34. Request: simple.Request{
  35. Method: "POST",
  36. Path: testapi.Autoscaling.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
  37. Query: simple.BuildQueryValues(nil),
  38. Body: &horizontalPodAutoscaler,
  39. },
  40. Response: simple.Response{StatusCode: 200, Body: &horizontalPodAutoscaler},
  41. ResourceGroup: autoscaling.GroupName,
  42. }
  43. response, err := c.Setup(t).Autoscaling().HorizontalPodAutoscalers(ns).Create(&horizontalPodAutoscaler)
  44. defer c.Close()
  45. if err != nil {
  46. t.Fatalf("unexpected error: %v", err)
  47. }
  48. c.Validate(t, response, err)
  49. }
  50. func TestHorizontalPodAutoscalerGet(t *testing.T) {
  51. ns := api.NamespaceDefault
  52. horizontalPodAutoscaler := &autoscaling.HorizontalPodAutoscaler{
  53. ObjectMeta: api.ObjectMeta{
  54. Name: "abc",
  55. Namespace: ns,
  56. },
  57. }
  58. c := &simple.Client{
  59. Request: simple.Request{
  60. Method: "GET",
  61. Path: testapi.Autoscaling.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"),
  62. Query: simple.BuildQueryValues(nil),
  63. Body: nil,
  64. },
  65. Response: simple.Response{StatusCode: 200, Body: horizontalPodAutoscaler},
  66. ResourceGroup: autoscaling.GroupName,
  67. }
  68. response, err := c.Setup(t).Autoscaling().HorizontalPodAutoscalers(ns).Get("abc")
  69. defer c.Close()
  70. c.Validate(t, response, err)
  71. }
  72. func TestHorizontalPodAutoscalerList(t *testing.T) {
  73. ns := api.NamespaceDefault
  74. horizontalPodAutoscalerList := &autoscaling.HorizontalPodAutoscalerList{
  75. Items: []autoscaling.HorizontalPodAutoscaler{
  76. {
  77. ObjectMeta: api.ObjectMeta{
  78. Name: "foo",
  79. Namespace: ns,
  80. },
  81. },
  82. },
  83. }
  84. c := &simple.Client{
  85. Request: simple.Request{
  86. Method: "GET",
  87. Path: testapi.Autoscaling.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
  88. Query: simple.BuildQueryValues(nil),
  89. Body: nil,
  90. },
  91. Response: simple.Response{StatusCode: 200, Body: horizontalPodAutoscalerList},
  92. ResourceGroup: autoscaling.GroupName,
  93. }
  94. response, err := c.Setup(t).Autoscaling().HorizontalPodAutoscalers(ns).List(api.ListOptions{})
  95. defer c.Close()
  96. c.Validate(t, response, err)
  97. }
  98. func TestHorizontalPodAutoscalerUpdate(t *testing.T) {
  99. ns := api.NamespaceDefault
  100. horizontalPodAutoscaler := &autoscaling.HorizontalPodAutoscaler{
  101. ObjectMeta: api.ObjectMeta{
  102. Name: "abc",
  103. Namespace: ns,
  104. ResourceVersion: "1",
  105. },
  106. }
  107. c := &simple.Client{
  108. Request: simple.Request{Method: "PUT", Path: testapi.Autoscaling.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"), Query: simple.BuildQueryValues(nil)},
  109. Response: simple.Response{StatusCode: 200, Body: horizontalPodAutoscaler},
  110. ResourceGroup: autoscaling.GroupName,
  111. }
  112. response, err := c.Setup(t).Autoscaling().HorizontalPodAutoscalers(ns).Update(horizontalPodAutoscaler)
  113. defer c.Close()
  114. c.Validate(t, response, err)
  115. }
  116. func TestHorizontalPodAutoscalerUpdateStatus(t *testing.T) {
  117. ns := api.NamespaceDefault
  118. horizontalPodAutoscaler := &autoscaling.HorizontalPodAutoscaler{
  119. ObjectMeta: api.ObjectMeta{
  120. Name: "abc",
  121. Namespace: ns,
  122. ResourceVersion: "1",
  123. },
  124. }
  125. c := &simple.Client{
  126. Request: simple.Request{Method: "PUT", Path: testapi.Autoscaling.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc") + "/status", Query: simple.BuildQueryValues(nil)},
  127. Response: simple.Response{StatusCode: 200, Body: horizontalPodAutoscaler},
  128. ResourceGroup: autoscaling.GroupName,
  129. }
  130. response, err := c.Setup(t).Autoscaling().HorizontalPodAutoscalers(ns).UpdateStatus(horizontalPodAutoscaler)
  131. defer c.Close()
  132. c.Validate(t, response, err)
  133. }
  134. func TestHorizontalPodAutoscalerDelete(t *testing.T) {
  135. ns := api.NamespaceDefault
  136. c := &simple.Client{
  137. Request: simple.Request{Method: "DELETE", Path: testapi.Autoscaling.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
  138. Response: simple.Response{StatusCode: 200},
  139. ResourceGroup: autoscaling.GroupName,
  140. }
  141. err := c.Setup(t).Autoscaling().HorizontalPodAutoscalers(ns).Delete("foo", nil)
  142. defer c.Close()
  143. c.Validate(t, nil, err)
  144. }
  145. func TestHorizontalPodAutoscalerWatch(t *testing.T) {
  146. c := &simple.Client{
  147. Request: simple.Request{
  148. Method: "GET",
  149. Path: testapi.Autoscaling.ResourcePathWithPrefix("watch", getHorizontalPodAutoscalersResoureName(), "", ""),
  150. Query: url.Values{"resourceVersion": []string{}}},
  151. Response: simple.Response{StatusCode: 200},
  152. ResourceGroup: autoscaling.GroupName,
  153. }
  154. _, err := c.Setup(t).Autoscaling().HorizontalPodAutoscalers(api.NamespaceAll).Watch(api.ListOptions{})
  155. defer c.Close()
  156. c.Validate(t, nil, err)
  157. }