MCPcopy
hub / github.com/kubernetes/client-go / TestWasCreated

Function TestWasCreated

rest/request_test.go:1591–1635  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1589}
1590
1591func TestWasCreated(t *testing.T) {
1592 reqObj := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
1593 reqBodyExpected, err := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), reqObj)
1594 if err != nil {
1595 t.Errorf("unexpected error: %v", err)
1596 }
1597
1598 expectedObj := &v1.Service{Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{
1599 Protocol: "TCP",
1600 Port: 12345,
1601 TargetPort: intstr.FromInt(12345),
1602 }}}}
1603 expectedBody, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), expectedObj)
1604 fakeHandler := utiltesting.FakeHandler{
1605 StatusCode: 201,
1606 ResponseBody: string(expectedBody),
1607 T: t,
1608 }
1609 testServer := httptest.NewServer(&fakeHandler)
1610 defer testServer.Close()
1611 c := testRESTClient(t, testServer)
1612 wasCreated := false
1613 obj, err := c.Verb("PUT").
1614 Prefix("foo/bar", "baz").
1615 Timeout(time.Second).
1616 Body(reqBodyExpected).
1617 Do().WasCreated(&wasCreated).Get()
1618 if err != nil {
1619 t.Errorf("Unexpected error: %v %#v", err, err)
1620 return
1621 }
1622 if obj == nil {
1623 t.Error("nil obj")
1624 } else if !apiequality.Semantic.DeepDerivative(expectedObj, obj) {
1625 t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
1626 }
1627 if !wasCreated {
1628 t.Errorf("Expected object was created")
1629 }
1630
1631 tmpStr := string(reqBodyExpected)
1632 requestURL := defaultResourcePathWithPrefix("foo/bar/baz", "", "", "")
1633 requestURL += "?timeout=1s"
1634 fakeHandler.ValidateRequest(t, requestURL, "PUT", &tmpStr)
1635}
1636
1637func TestVerbs(t *testing.T) {
1638 c := testRESTClient(t, nil)

Callers

nothing calls this directly

Calls 14

ValidateRequestMethod · 0.95
testRESTClientFunction · 0.85
WasCreatedMethod · 0.80
BodyMethod · 0.80
TimeoutMethod · 0.80
PrefixMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65
DoMethod · 0.65
VerbMethod · 0.65

Tested by

no test coverage detected