MCPcopy Create free account
hub / github.com/facebook/time / TestPost

Function TestPost

calnex/api/api_test.go:517–545  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

515}
516
517func TestPost(t *testing.T) {
518 sampleResp := "{\n\"result\" : true,\n\"message\" : \"LGTM\"\n}"
519 expected := &Result{
520 Result: true,
521 Message: "LGTM",
522 }
523 postData := []byte("Whatever")
524 serverReceived := &bytes.Buffer{}
525
526 ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter,
527 r *http.Request) {
528 defer r.Body.Close()
529 _, err := serverReceived.ReadFrom(r.Body)
530 require.NoError(t, err)
531 fmt.Fprintln(w, sampleResp)
532 }))
533 defer ts.Close()
534
535 parsed, _ := url.Parse(ts.URL)
536 calnexAPI, err := NewAPI(parsed.Host, true, time.Second)
537 require.NoError(t, err)
538 calnexAPI.Client = ts.Client()
539
540 buf := bytes.NewBuffer(postData)
541 r, err := calnexAPI.post(parsed.String(), buf)
542 require.NoError(t, err)
543 require.Equal(t, expected, r)
544 require.Equal(t, postData, serverReceived.Bytes())
545}
546
547func TestGet(t *testing.T) {
548 ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter,

Callers

nothing calls this directly

Calls 5

postMethod · 0.95
NewAPIFunction · 0.85
CloseMethod · 0.65
StringMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…