MCPcopy
hub / github.com/helm/helm / TestCreate

Function TestCreate

pkg/kube/client_test.go:204–323  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

202}
203
204func TestCreate(t *testing.T) {
205 // Note: c.Create with the fake client can currently only test creation of a single pod/object in the same list. When testing
206 // with more than one pod, c.Create will run into a data race as it calls perform->batchPerform which performs creation
207 // in batches. The race is something in the fake client itself in `func (c *RESTClient) do(...)`
208 // when it stores the req: c.Req = req and cannot (?) be fixed easily.
209
210 type testCase struct {
211 Name string
212 Pods v1.PodList
213 Callback func(t *testing.T, tc testCase, previous []RequestResponseAction, req *http.Request) (*http.Response, error)
214 ServerSideApply bool
215 ExpectedActions []string
216 ExpectedErrorContains string
217 }
218
219 testCases := map[string]testCase{
220 "Create success (client-side apply)": {
221 Pods: newPodList("starfish"),
222 ServerSideApply: false,
223 Callback: func(t *testing.T, tc testCase, previous []RequestResponseAction, _ *http.Request) (*http.Response, error) {
224 t.Helper()
225
226 if len(previous) < 2 { // simulate a conflict
227 return newResponseJSON(http.StatusConflict, resourceQuotaConflict)
228 }
229
230 return newResponse(http.StatusOK, &tc.Pods.Items[0])
231 },
232 ExpectedActions: []string{
233 "/namespaces/default/pods:POST",
234 "/namespaces/default/pods:POST",
235 "/namespaces/default/pods:POST",
236 },
237 },
238 "Create success (server-side apply)": {
239 Pods: newPodList("whale"),
240 ServerSideApply: true,
241 Callback: func(t *testing.T, tc testCase, _ []RequestResponseAction, _ *http.Request) (*http.Response, error) {
242 t.Helper()
243
244 return newResponse(http.StatusOK, &tc.Pods.Items[0])
245 },
246 ExpectedActions: []string{
247 "/namespaces/default/pods/whale:PATCH",
248 },
249 },
250 "Create fail: incompatible server (server-side apply)": {
251 Pods: newPodList("lobster"),
252 ServerSideApply: true,
253 Callback: func(t *testing.T, _ testCase, _ []RequestResponseAction, req *http.Request) (*http.Response, error) {
254 t.Helper()
255
256 return &http.Response{
257 StatusCode: http.StatusUnsupportedMediaType,
258 Request: req,
259 }, nil
260 },
261 ExpectedErrorContains: "server-side apply not available on the server:",

Callers

nothing calls this directly

Calls 13

newPodListFunction · 0.85
newResponseJSONFunction · 0.85
newResponseFunction · 0.85
newTestClientFunction · 0.85
objBodyFunction · 0.85
HelperMethod · 0.80
FatalMethod · 0.80
RunMethod · 0.65
BuildMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…