github.com/gophercloud/gophercloud@v1.11.0/openstack/orchestration/v1/buildinfo/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/gophercloud/gophercloud/openstack/orchestration/v1/buildinfo"
     9  	th "github.com/gophercloud/gophercloud/testhelper"
    10  	fake "github.com/gophercloud/gophercloud/testhelper/client"
    11  )
    12  
    13  // GetExpected represents the expected object from a Get request.
    14  var GetExpected = &buildinfo.BuildInfo{
    15  	API: buildinfo.Revision{
    16  		Revision: "2.4.5",
    17  	},
    18  	Engine: buildinfo.Revision{
    19  		Revision: "1.2.1",
    20  	},
    21  }
    22  
    23  // GetOutput represents the response body from a Get request.
    24  const GetOutput = `
    25  {
    26    "api": {
    27      "revision": "2.4.5"
    28    },
    29    "engine": {
    30      "revision": "1.2.1"
    31    }
    32  }`
    33  
    34  // HandleGetSuccessfully creates an HTTP handler at `/build_info`
    35  // on the test handler mux that responds with a `Get` response.
    36  func HandleGetSuccessfully(t *testing.T, output string) {
    37  	th.Mux.HandleFunc("/build_info", func(w http.ResponseWriter, r *http.Request) {
    38  		th.TestMethod(t, r, "GET")
    39  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    40  		th.TestHeader(t, r, "Accept", "application/json")
    41  
    42  		w.Header().Set("Content-Type", "application/json")
    43  		w.WriteHeader(http.StatusOK)
    44  		fmt.Fprintf(w, output)
    45  	})
    46  }