github.com/gophercloud/gophercloud@v1.11.0/openstack/cdn/v1/base/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	th "github.com/gophercloud/gophercloud/testhelper"
     9  	fake "github.com/gophercloud/gophercloud/testhelper/client"
    10  )
    11  
    12  // HandleGetSuccessfully creates an HTTP handler at `/` on the test handler mux
    13  // that responds with a `Get` response.
    14  func HandleGetSuccessfully(t *testing.T) {
    15  	th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    16  		th.TestMethod(t, r, "GET")
    17  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    18  		th.TestHeader(t, r, "Accept", "application/json")
    19  		w.WriteHeader(http.StatusOK)
    20  		fmt.Fprintf(w, `
    21      {
    22          "resources": {
    23              "rel/cdn": {
    24                  "href-template": "services{?marker,limit}",
    25                  "href-vars": {
    26                      "marker": "param/marker",
    27                      "limit": "param/limit"
    28                  },
    29                  "hints": {
    30                      "allow": [
    31                          "GET"
    32                      ],
    33                      "formats": {
    34                          "application/json": {}
    35                      }
    36                  }
    37              }
    38          }
    39      }
    40      `)
    41  
    42  	})
    43  }
    44  
    45  // HandlePingSuccessfully creates an HTTP handler at `/ping` on the test handler
    46  // mux that responds with a `Ping` response.
    47  func HandlePingSuccessfully(t *testing.T) {
    48  	th.Mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
    49  		th.TestMethod(t, r, "GET")
    50  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    51  		w.WriteHeader(http.StatusNoContent)
    52  	})
    53  }