pet_sets_test.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. Copyright 2016 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. "testing"
  16. "k8s.io/kubernetes/pkg/api"
  17. "k8s.io/kubernetes/pkg/api/testapi"
  18. "k8s.io/kubernetes/pkg/apis/apps"
  19. "k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
  20. )
  21. func getPetSetResourceName() string {
  22. return "petsets"
  23. }
  24. func TestListPetSets(t *testing.T) {
  25. ns := api.NamespaceAll
  26. c := &simple.Client{
  27. Request: simple.Request{
  28. Method: "GET",
  29. Path: testapi.Apps.ResourcePath(getPetSetResourceName(), ns, ""),
  30. },
  31. Response: simple.Response{StatusCode: 200,
  32. Body: &apps.PetSetList{
  33. Items: []apps.PetSet{
  34. {
  35. ObjectMeta: api.ObjectMeta{
  36. Name: "foo",
  37. Labels: map[string]string{
  38. "foo": "bar",
  39. "name": "baz",
  40. },
  41. },
  42. Spec: apps.PetSetSpec{
  43. Replicas: 2,
  44. Template: api.PodTemplateSpec{},
  45. },
  46. },
  47. },
  48. },
  49. },
  50. }
  51. receivedRSList, err := c.Setup(t).Apps().PetSets(ns).List(api.ListOptions{})
  52. c.Validate(t, receivedRSList, err)
  53. }
  54. func TestGetPetSet(t *testing.T) {
  55. ns := api.NamespaceDefault
  56. c := &simple.Client{
  57. Request: simple.Request{Method: "GET", Path: testapi.Apps.ResourcePath(getPetSetResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
  58. Response: simple.Response{
  59. StatusCode: 200,
  60. Body: &apps.PetSet{
  61. ObjectMeta: api.ObjectMeta{
  62. Name: "foo",
  63. Labels: map[string]string{
  64. "foo": "bar",
  65. "name": "baz",
  66. },
  67. },
  68. Spec: apps.PetSetSpec{
  69. Replicas: 2,
  70. Template: api.PodTemplateSpec{},
  71. },
  72. },
  73. },
  74. }
  75. receivedRS, err := c.Setup(t).Apps().PetSets(ns).Get("foo")
  76. c.Validate(t, receivedRS, err)
  77. }
  78. func TestGetPetSetWithNoName(t *testing.T) {
  79. ns := api.NamespaceDefault
  80. c := &simple.Client{Error: true}
  81. receivedPod, err := c.Setup(t).Apps().PetSets(ns).Get("")
  82. if (err != nil) && (err.Error() != simple.NameRequiredError) {
  83. t.Errorf("Expected error: %v, but got %v", simple.NameRequiredError, err)
  84. }
  85. c.Validate(t, receivedPod, err)
  86. }
  87. func TestUpdatePetSet(t *testing.T) {
  88. ns := api.NamespaceDefault
  89. requestRS := &apps.PetSet{
  90. ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
  91. }
  92. c := &simple.Client{
  93. Request: simple.Request{Method: "PUT", Path: testapi.Apps.ResourcePath(getPetSetResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
  94. Response: simple.Response{
  95. StatusCode: 200,
  96. Body: &apps.PetSet{
  97. ObjectMeta: api.ObjectMeta{
  98. Name: "foo",
  99. Labels: map[string]string{
  100. "foo": "bar",
  101. "name": "baz",
  102. },
  103. },
  104. Spec: apps.PetSetSpec{
  105. Replicas: 2,
  106. Template: api.PodTemplateSpec{},
  107. },
  108. },
  109. },
  110. }
  111. receivedRS, err := c.Setup(t).Apps().PetSets(ns).Update(requestRS)
  112. c.Validate(t, receivedRS, err)
  113. }
  114. func TestDeletePetSet(t *testing.T) {
  115. ns := api.NamespaceDefault
  116. c := &simple.Client{
  117. Request: simple.Request{Method: "DELETE", Path: testapi.Apps.ResourcePath(getPetSetResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
  118. Response: simple.Response{StatusCode: 200},
  119. }
  120. err := c.Setup(t).Apps().PetSets(ns).Delete("foo", nil)
  121. c.Validate(t, nil, err)
  122. }
  123. func TestCreatePetSet(t *testing.T) {
  124. ns := api.NamespaceDefault
  125. requestRS := &apps.PetSet{
  126. ObjectMeta: api.ObjectMeta{Name: "foo"},
  127. }
  128. c := &simple.Client{
  129. Request: simple.Request{Method: "POST", Path: testapi.Apps.ResourcePath(getPetSetResourceName(), ns, ""), Body: requestRS, Query: simple.BuildQueryValues(nil)},
  130. Response: simple.Response{
  131. StatusCode: 200,
  132. Body: &apps.PetSet{
  133. ObjectMeta: api.ObjectMeta{
  134. Name: "foo",
  135. Labels: map[string]string{
  136. "foo": "bar",
  137. "name": "baz",
  138. },
  139. },
  140. Spec: apps.PetSetSpec{
  141. Replicas: 2,
  142. Template: api.PodTemplateSpec{},
  143. },
  144. },
  145. },
  146. }
  147. receivedRS, err := c.Setup(t).Apps().PetSets(ns).Create(requestRS)
  148. c.Validate(t, receivedRS, err)
  149. }
  150. // TODO: Test Status actions.