AdhityaRamadhanus / httpstub

A wrapper package for an easier way to stub http request in golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

httpstub

A wrapper package for an easier way to stub http request in golang

Examples | License

Examples

  • see godoc for more detailed examples
  srv := httpstub.NewStubServer()
	srv.StubRequest(http.MethodGet, "/healthz")
	defer srv.Close()

	url := fmt.Sprintf("%s%s", srv.URL(), "/healthz")
	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		panic(err)
	}

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	respBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Response Body: %s\n", string(respBody))
	fmt.Printf("Response Status Code: %d\n", resp.StatusCode)

	// Output:
	// Response Body: OK
	// Response Status Code: 200
}

License

GPL © [Adhitya Ramadhanus]

About

A wrapper package for an easier way to stub http request in golang

License:GNU General Public License v3.0


Languages

Language:Go 100.0%