service_client_test.go 922 B

1234567891011121314151617181920212223242526272829303132333435
  1. package testing
  2. import (
  3. "fmt"
  4. "net/http"
  5. "testing"
  6. "devel.mephi.ru/iacherepanov/openstack-gophercloud"
  7. th "devel.mephi.ru/iacherepanov/openstack-gophercloud/testhelper"
  8. )
  9. func TestServiceURL(t *testing.T) {
  10. c := &gophercloud.ServiceClient{Endpoint: "http://123.45.67.8/"}
  11. expected := "http://123.45.67.8/more/parts/here"
  12. actual := c.ServiceURL("more", "parts", "here")
  13. th.CheckEquals(t, expected, actual)
  14. }
  15. func TestMoreHeaders(t *testing.T) {
  16. th.SetupHTTP()
  17. defer th.TeardownHTTP()
  18. th.Mux.HandleFunc("/route", func(w http.ResponseWriter, r *http.Request) {
  19. w.WriteHeader(http.StatusOK)
  20. })
  21. c := new(gophercloud.ServiceClient)
  22. c.MoreHeaders = map[string]string{
  23. "custom": "header",
  24. }
  25. c.ProviderClient = new(gophercloud.ProviderClient)
  26. resp, err := c.Get(fmt.Sprintf("%s/route", th.Endpoint()), nil, nil)
  27. th.AssertNoErr(t, err)
  28. th.AssertEquals(t, resp.Request.Header.Get("custom"), "header")
  29. }