github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/availabilityzones/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	az "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/availabilityzones"
    10  	th "github.com/huaweicloud/golangsdk/testhelper"
    11  	"github.com/huaweicloud/golangsdk/testhelper/client"
    12  )
    13  
    14  const GetOutput = `
    15  {
    16      "availabilityZoneInfo": [
    17          {
    18              "hosts": null,
    19              "zoneName": "nova",
    20              "zoneState": {
    21                  "available": true
    22              }
    23          }
    24      ]
    25  }
    26  `
    27  
    28  const GetDetailOutput = `
    29  {
    30      "availabilityZoneInfo": [
    31          {
    32              "hosts": {
    33                  "localhost": {
    34                      "nova-cert": {
    35                          "active": true,
    36                          "available": false,
    37                          "updated_at": "2017-10-14T17:03:39.000000"
    38                      },
    39                      "nova-conductor": {
    40                          "active": true,
    41                          "available": false,
    42                          "updated_at": "2017-10-14T17:04:09.000000"
    43                      },
    44                      "nova-consoleauth": {
    45                          "active": true,
    46                          "available": false,
    47                          "updated_at": "2017-10-14T17:04:18.000000"
    48                      },
    49                      "nova-scheduler": {
    50                          "active": true,
    51                          "available": false,
    52                          "updated_at": "2017-10-14T17:04:30.000000"
    53                      }
    54                  },
    55                  "openstack-acc-tests.novalocal": {
    56                      "nova-cert": {
    57                          "active": true,
    58                          "available": true,
    59                          "updated_at": "2018-01-04T04:11:19.000000"
    60                      },
    61                      "nova-conductor": {
    62                          "active": true,
    63                          "available": true,
    64                          "updated_at": "2018-01-04T04:11:22.000000"
    65                      },
    66                      "nova-consoleauth": {
    67                          "active": true,
    68                          "available": true,
    69                          "updated_at": "2018-01-04T04:11:20.000000"
    70                      },
    71                      "nova-scheduler": {
    72                          "active": true,
    73                          "available": true,
    74                          "updated_at": "2018-01-04T04:11:23.000000"
    75                      }
    76                  }
    77              },
    78              "zoneName": "internal",
    79              "zoneState": {
    80                  "available": true
    81              }
    82          },
    83          {
    84              "hosts": {
    85                  "openstack-acc-tests.novalocal": {
    86                      "nova-compute": {
    87                          "active": true,
    88                          "available": true,
    89                          "updated_at": "2018-01-04T04:11:23.000000"
    90                      }
    91                  }
    92              },
    93              "zoneName": "nova",
    94              "zoneState": {
    95                  "available": true
    96              }
    97          }
    98      ]
    99  }`
   100  
   101  var AZResult = []az.AvailabilityZone{
   102  	{
   103  		Hosts:     nil,
   104  		ZoneName:  "nova",
   105  		ZoneState: az.ZoneState{Available: true},
   106  	},
   107  }
   108  
   109  var AZDetailResult = []az.AvailabilityZone{
   110  	{
   111  		Hosts: az.Hosts{
   112  			"localhost": az.Services{
   113  				"nova-cert": az.ServiceState{
   114  					Active:    true,
   115  					Available: false,
   116  					UpdatedAt: time.Date(2017, 10, 14, 17, 3, 39, 0, time.UTC),
   117  				},
   118  				"nova-conductor": az.ServiceState{
   119  					Active:    true,
   120  					Available: false,
   121  					UpdatedAt: time.Date(2017, 10, 14, 17, 4, 9, 0, time.UTC),
   122  				},
   123  				"nova-consoleauth": az.ServiceState{
   124  					Active:    true,
   125  					Available: false,
   126  					UpdatedAt: time.Date(2017, 10, 14, 17, 4, 18, 0, time.UTC),
   127  				},
   128  				"nova-scheduler": az.ServiceState{
   129  					Active:    true,
   130  					Available: false,
   131  					UpdatedAt: time.Date(2017, 10, 14, 17, 4, 30, 0, time.UTC),
   132  				},
   133  			},
   134  			"openstack-acc-tests.novalocal": az.Services{
   135  				"nova-cert": az.ServiceState{
   136  					Active:    true,
   137  					Available: true,
   138  					UpdatedAt: time.Date(2018, 1, 4, 4, 11, 19, 0, time.UTC),
   139  				},
   140  				"nova-conductor": az.ServiceState{
   141  					Active:    true,
   142  					Available: true,
   143  					UpdatedAt: time.Date(2018, 1, 4, 4, 11, 22, 0, time.UTC),
   144  				},
   145  				"nova-consoleauth": az.ServiceState{
   146  					Active:    true,
   147  					Available: true,
   148  					UpdatedAt: time.Date(2018, 1, 4, 4, 11, 20, 0, time.UTC),
   149  				},
   150  				"nova-scheduler": az.ServiceState{
   151  					Active:    true,
   152  					Available: true,
   153  					UpdatedAt: time.Date(2018, 1, 4, 4, 11, 23, 0, time.UTC),
   154  				},
   155  			},
   156  		},
   157  		ZoneName:  "internal",
   158  		ZoneState: az.ZoneState{Available: true},
   159  	},
   160  	{
   161  		Hosts: az.Hosts{
   162  			"openstack-acc-tests.novalocal": az.Services{
   163  				"nova-compute": az.ServiceState{
   164  					Active:    true,
   165  					Available: true,
   166  					UpdatedAt: time.Date(2018, 1, 4, 4, 11, 23, 0, time.UTC),
   167  				},
   168  			},
   169  		},
   170  		ZoneName:  "nova",
   171  		ZoneState: az.ZoneState{Available: true},
   172  	},
   173  }
   174  
   175  // HandleGetSuccessfully configures the test server to respond to a Get request
   176  // for availability zone information.
   177  func HandleGetSuccessfully(t *testing.T) {
   178  	th.Mux.HandleFunc("/os-availability-zone", func(w http.ResponseWriter, r *http.Request) {
   179  		th.TestMethod(t, r, "GET")
   180  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   181  
   182  		w.Header().Add("Content-Type", "application/json")
   183  		fmt.Fprintf(w, GetOutput)
   184  	})
   185  }
   186  
   187  // HandleGetDetailSuccessfully configures the test server to respond to a Get request
   188  // for detailed availability zone information.
   189  func HandleGetDetailSuccessfully(t *testing.T) {
   190  	th.Mux.HandleFunc("/os-availability-zone/detail", func(w http.ResponseWriter, r *http.Request) {
   191  		th.TestMethod(t, r, "GET")
   192  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   193  
   194  		w.Header().Add("Content-Type", "application/json")
   195  		fmt.Fprintf(w, GetDetailOutput)
   196  	})
   197  }