github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/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/compute/v2/extensions/services"
    10  	th "github.com/gophercloud/gophercloud/testhelper"
    11  	"github.com/gophercloud/gophercloud/testhelper/client"
    12  )
    13  
    14  // ServiceListBodyPre253 represents a raw service list from the Compute API
    15  // with microversion older than 2.53.
    16  const ServiceListBodyPre253 = `
    17  {
    18      "services": [
    19          {
    20              "id": 1,
    21              "binary": "nova-scheduler",
    22              "disabled_reason": "test1",
    23              "host": "host1",
    24              "state": "up",
    25              "status": "disabled",
    26              "updated_at": "2012-10-29T13:42:02.000000",
    27              "forced_down": false,
    28              "zone": "internal"
    29          },
    30          {
    31              "id": 2,
    32              "binary": "nova-compute",
    33              "disabled_reason": "test2",
    34              "host": "host1",
    35              "state": "up",
    36              "status": "disabled",
    37              "updated_at": "2012-10-29T13:42:05.000000",
    38              "forced_down": false,
    39              "zone": "nova"
    40          },
    41          {
    42              "id": 3,
    43              "binary": "nova-scheduler",
    44              "disabled_reason": null,
    45              "host": "host2",
    46              "state": "down",
    47              "status": "enabled",
    48              "updated_at": "2012-09-19T06:55:34.000000",
    49              "forced_down": false,
    50              "zone": "internal"
    51          },
    52          {
    53              "id": 4,
    54              "binary": "nova-compute",
    55              "disabled_reason": "test4",
    56              "host": "host2",
    57              "state": "down",
    58              "status": "disabled",
    59              "updated_at": "2012-09-18T08:03:38.000000",
    60              "forced_down": false,
    61              "zone": "nova"
    62          }
    63      ]
    64  }
    65  `
    66  
    67  var (
    68  	// FirstFakeServicePre253 represents the first service from the
    69  	// ServiceListBodyPre253.
    70  	FirstFakeServicePre253 = services.Service{
    71  		Binary:         "nova-scheduler",
    72  		DisabledReason: "test1",
    73  		Host:           "host1",
    74  		ID:             "1",
    75  		State:          "up",
    76  		Status:         "disabled",
    77  		UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 2, 0, time.UTC),
    78  		Zone:           "internal",
    79  	}
    80  
    81  	// SecondFakeServicePre253 represents the second service from the
    82  	// ServiceListBodyPre253.
    83  	SecondFakeServicePre253 = services.Service{
    84  		Binary:         "nova-compute",
    85  		DisabledReason: "test2",
    86  		Host:           "host1",
    87  		ID:             "2",
    88  		State:          "up",
    89  		Status:         "disabled",
    90  		UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 5, 0, time.UTC),
    91  		Zone:           "nova",
    92  	}
    93  
    94  	// ThirdFakeServicePre253 represents the third service from the
    95  	// ServiceListBodyPre253.
    96  	ThirdFakeServicePre253 = services.Service{
    97  		Binary:         "nova-scheduler",
    98  		DisabledReason: "",
    99  		Host:           "host2",
   100  		ID:             "3",
   101  		State:          "down",
   102  		Status:         "enabled",
   103  		UpdatedAt:      time.Date(2012, 9, 19, 6, 55, 34, 0, time.UTC),
   104  		Zone:           "internal",
   105  	}
   106  
   107  	// FourthFakeServicePre253 represents the fourth service from the
   108  	// ServiceListBodyPre253.
   109  	FourthFakeServicePre253 = services.Service{
   110  		Binary:         "nova-compute",
   111  		DisabledReason: "test4",
   112  		Host:           "host2",
   113  		ID:             "4",
   114  		State:          "down",
   115  		Status:         "disabled",
   116  		UpdatedAt:      time.Date(2012, 9, 18, 8, 3, 38, 0, time.UTC),
   117  		Zone:           "nova",
   118  	}
   119  )
   120  
   121  // ServiceListBody represents a raw service list result with Pike+ release.
   122  const ServiceListBody = `
   123  {
   124      "services": [
   125          {
   126              "id": "4c720fa0-02c3-4834-8279-9eecf9edb6cb",
   127              "binary": "nova-scheduler",
   128              "disabled_reason": "test1",
   129              "host": "host1",
   130              "state": "up",
   131              "status": "disabled",
   132              "updated_at": "2012-10-29T13:42:02.000000",
   133              "forced_down": false,
   134              "zone": "internal"
   135          },
   136          {
   137              "id": "1fdfec3e-ee03-4e36-b99b-71cf2967b70c",
   138              "binary": "nova-compute",
   139              "disabled_reason": "test2",
   140              "host": "host1",
   141              "state": "up",
   142              "status": "disabled",
   143              "updated_at": "2012-10-29T13:42:05.000000",
   144              "forced_down": false,
   145              "zone": "nova"
   146          },
   147          {
   148              "id": "bd0b2e30-809e-4160-bd3d-f23ca30e9b68",
   149              "binary": "nova-scheduler",
   150              "disabled_reason": null,
   151              "host": "host2",
   152              "state": "down",
   153              "status": "enabled",
   154              "updated_at": "2012-09-19T06:55:34.000000",
   155              "forced_down": false,
   156              "zone": "internal"
   157          },
   158          {
   159              "id": "fe41c476-33e2-4ac3-ad21-3ffaf1b9c644",
   160              "binary": "nova-compute",
   161              "disabled_reason": "test4",
   162              "host": "host2",
   163              "state": "down",
   164              "status": "disabled",
   165              "updated_at": "2012-09-18T08:03:38.000000",
   166              "forced_down": false,
   167              "zone": "nova"
   168          }
   169      ]
   170  }
   171  `
   172  
   173  var (
   174  	// FirstFakeService represents the first service from the ServiceListBody.
   175  	FirstFakeService = services.Service{
   176  		Binary:         "nova-scheduler",
   177  		DisabledReason: "test1",
   178  		Host:           "host1",
   179  		ID:             "4c720fa0-02c3-4834-8279-9eecf9edb6cb",
   180  		State:          "up",
   181  		Status:         "disabled",
   182  		UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 2, 0, time.UTC),
   183  		Zone:           "internal",
   184  	}
   185  
   186  	// SecondFakeService represents the second service from the ServiceListBody.
   187  	SecondFakeService = services.Service{
   188  		Binary:         "nova-compute",
   189  		DisabledReason: "test2",
   190  		Host:           "host1",
   191  		ID:             "1fdfec3e-ee03-4e36-b99b-71cf2967b70c",
   192  		State:          "up",
   193  		Status:         "disabled",
   194  		UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 5, 0, time.UTC),
   195  		Zone:           "nova",
   196  	}
   197  
   198  	// ThirdFakeService represents the third service from the ServiceListBody.
   199  	ThirdFakeService = services.Service{
   200  		Binary:         "nova-scheduler",
   201  		DisabledReason: "",
   202  		Host:           "host2",
   203  		ID:             "bd0b2e30-809e-4160-bd3d-f23ca30e9b68",
   204  		State:          "down",
   205  		Status:         "enabled",
   206  		UpdatedAt:      time.Date(2012, 9, 19, 6, 55, 34, 0, time.UTC),
   207  		Zone:           "internal",
   208  	}
   209  
   210  	// FourthFakeService represents the fourth service from the ServiceListBody.
   211  	FourthFakeService = services.Service{
   212  		Binary:         "nova-compute",
   213  		DisabledReason: "test4",
   214  		Host:           "host2",
   215  		ID:             "fe41c476-33e2-4ac3-ad21-3ffaf1b9c644",
   216  		State:          "down",
   217  		Status:         "disabled",
   218  		UpdatedAt:      time.Date(2012, 9, 18, 8, 3, 38, 0, time.UTC),
   219  		Zone:           "nova",
   220  	}
   221  )
   222  
   223  // ServiceUpdate represents a raw service from the Compute service update API
   224  const ServiceUpdate = `
   225  {
   226  	"service":
   227  	{
   228  		"id": 1,
   229  		"binary": "nova-scheduler",
   230  		"disabled_reason": "test1",
   231  		"host": "host1",
   232  		"state": "up",
   233  		"status": "disabled",
   234  		"updated_at": "2012-10-29T13:42:02.000000",
   235  		"forced_down": false,
   236  		"zone": "internal"
   237  	}
   238  }
   239  `
   240  
   241  // FakeServiceUpdateBody represents the updated service
   242  var FakeServiceUpdateBody = services.Service{
   243  	Binary:         "nova-scheduler",
   244  	DisabledReason: "test1",
   245  	ForcedDown:     false,
   246  	Host:           "host1",
   247  	ID:             "1",
   248  	State:          "up",
   249  	Status:         "disabled",
   250  	UpdatedAt:      time.Date(2012, 10, 29, 13, 42, 2, 0, time.UTC),
   251  	Zone:           "internal",
   252  }
   253  
   254  // HandleListPre253Successfully configures the test server to respond to a List
   255  // request to a Compute server API pre 2.53 microversion release.
   256  func HandleListPre253Successfully(t *testing.T) {
   257  	th.Mux.HandleFunc("/os-services", func(w http.ResponseWriter, r *http.Request) {
   258  		th.TestMethod(t, r, "GET")
   259  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   260  
   261  		w.Header().Add("Content-Type", "application/json")
   262  		fmt.Fprintf(w, ServiceListBodyPre253)
   263  	})
   264  }
   265  
   266  // HandleListSuccessfully configures the test server to respond to a List
   267  // request to a Compute server with Pike+ release.
   268  func HandleListSuccessfully(t *testing.T) {
   269  	th.Mux.HandleFunc("/os-services", func(w http.ResponseWriter, r *http.Request) {
   270  		th.TestMethod(t, r, "GET")
   271  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   272  
   273  		w.Header().Add("Content-Type", "application/json")
   274  		fmt.Fprintf(w, ServiceListBody)
   275  	})
   276  }
   277  
   278  // HandleUpdateSuccessfully configures the test server to respond to a Update
   279  // request to a Compute server with Pike+ release.
   280  func HandleUpdateSuccessfully(t *testing.T) {
   281  	th.Mux.HandleFunc("/os-services/fake-service-id", func(w http.ResponseWriter, r *http.Request) {
   282  		th.TestMethod(t, r, "PUT")
   283  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   284  		th.TestHeader(t, r, "Accept", "application/json")
   285  		th.TestHeader(t, r, "Content-Type", "application/json")
   286  		th.TestJSONRequest(t, r, `{"status": "disabled"}`)
   287  
   288  		fmt.Fprintf(w, ServiceUpdate)
   289  	})
   290  }
   291  
   292  // HandleDeleteSuccessfully configures the test server to respond to a Delete
   293  // request to a Compute server with Pike+ release.
   294  func HandleDeleteSuccessfully(t *testing.T) {
   295  	th.Mux.HandleFunc("/os-services/fake-service-id", func(w http.ResponseWriter, r *http.Request) {
   296  		th.TestMethod(t, r, "DELETE")
   297  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   298  		w.WriteHeader(http.StatusNoContent)
   299  	})
   300  }