helper.go 696 B

1234567891011121314151617181920212223242526272829303132
  1. package fixture
  2. import (
  3. "fmt"
  4. "net/http"
  5. "testing"
  6. th "devel.mephi.ru/iacherepanov/openstack-gophercloud/testhelper"
  7. "devel.mephi.ru/iacherepanov/openstack-gophercloud/testhelper/client"
  8. )
  9. func SetupHandler(t *testing.T, url, method, requestBody, responseBody string, status int) {
  10. th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
  11. th.TestMethod(t, r, method)
  12. th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
  13. if requestBody != "" {
  14. th.TestJSONRequest(t, r, requestBody)
  15. }
  16. if responseBody != "" {
  17. w.Header().Add("Content-Type", "application/json")
  18. }
  19. w.WriteHeader(status)
  20. if responseBody != "" {
  21. fmt.Fprintf(w, responseBody)
  22. }
  23. })
  24. }