github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/services/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/services"
    10  	th "github.com/gophercloud/gophercloud/testhelper"
    11  	"github.com/gophercloud/gophercloud/testhelper/client"
    12  )
    13  
    14  // ServiceListBody is sample response to the List call
    15  const ServiceListBody = `
    16  {
    17  	"services": [
    18  			{
    19  					"status": "enabled",
    20  					"binary": "manila-share",
    21  					"zone": "manila",
    22  					"host": "manila2@generic1",
    23  					"updated_at": "2015-09-07T13:03:57.000000",
    24  					"state": "up",
    25  					"id": 1
    26  			},
    27  			{
    28  					"status": "enabled",
    29  					"binary": "manila-scheduler",
    30  					"zone": "manila",
    31  					"host": "manila2",
    32  					"updated_at": "2015-09-07T13:03:57.000000",
    33  					"state": "up",
    34  					"id": 2
    35  			}
    36  	]
    37  }
    38  `
    39  
    40  // First service from the ServiceListBody
    41  var FirstFakeService = services.Service{
    42  	Binary:    "manila-share",
    43  	Host:      "manila2@generic1",
    44  	ID:        1,
    45  	State:     "up",
    46  	Status:    "enabled",
    47  	UpdatedAt: time.Date(2015, 9, 7, 13, 3, 57, 0, time.UTC),
    48  	Zone:      "manila",
    49  }
    50  
    51  // Second service from the ServiceListBody
    52  var SecondFakeService = services.Service{
    53  	Binary:    "manila-scheduler",
    54  	Host:      "manila2",
    55  	ID:        2,
    56  	State:     "up",
    57  	Status:    "enabled",
    58  	UpdatedAt: time.Date(2015, 9, 7, 13, 3, 57, 0, time.UTC),
    59  	Zone:      "manila",
    60  }
    61  
    62  // HandleListSuccessfully configures the test server to respond to a List request.
    63  func HandleListSuccessfully(t *testing.T) {
    64  	th.Mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) {
    65  		th.TestMethod(t, r, "GET")
    66  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    67  
    68  		w.Header().Add("Content-Type", "application/json")
    69  		fmt.Fprintf(w, ServiceListBody)
    70  	})
    71  }