github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/ecs/v1/powers/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/huaweicloud/golangsdk/openstack/ecs/v1/cloudservers"
     9  	"github.com/huaweicloud/golangsdk/openstack/ecs/v1/powers"
    10  	th "github.com/huaweicloud/golangsdk/testhelper"
    11  	"github.com/huaweicloud/golangsdk/testhelper/client"
    12  )
    13  
    14  const (
    15  	expectedPowerOnRequest = `
    16  {
    17  	"os-start": {
    18  		"servers": [
    19  			{
    20  				"id": "42ecde1c-d97d-40c6-ac84-39ed9c35dc90"
    21  			}
    22  		]
    23  	}
    24  }`
    25  
    26  	expectedPowerOffRequest = `
    27  {
    28  	"os-stop": {
    29  		"servers": [
    30  			{
    31  				"id": "42ecde1c-d97d-40c6-ac84-39ed9c35dc90"
    32  			}
    33  		]
    34  	}
    35  }`
    36  
    37  	expectedPowerOnResponse = `
    38  {
    39  	"job_id": "ff808081787e9f100179693fd6f92e39"
    40  }`
    41  
    42  	expectedPowerOffResponse = `
    43  {
    44  	"job_id": "ff808081787ea4b5017969510b0543e6"
    45  }`
    46  )
    47  
    48  var (
    49  	powerOpts = &powers.PowerOpts{
    50  		Servers: []powers.ServerInfo{
    51  			{
    52  				ID: "42ecde1c-d97d-40c6-ac84-39ed9c35dc90",
    53  			},
    54  		},
    55  	}
    56  
    57  	expectedPowerOnResponseData = &cloudservers.JobResponse{
    58  		JobID: "ff808081787e9f100179693fd6f92e39",
    59  	}
    60  
    61  	expectedPowerOffResponseData = &cloudservers.JobResponse{
    62  		JobID: "ff808081787ea4b5017969510b0543e6",
    63  	}
    64  )
    65  
    66  func handlePowerOn(t *testing.T) {
    67  	th.Mux.HandleFunc("/cloudservers/action", func(w http.ResponseWriter, r *http.Request) {
    68  		th.TestMethod(t, r, "POST")
    69  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    70  		w.Header().Add("Content-Type", "application/json")
    71  		w.WriteHeader(http.StatusOK)
    72  		_, _ = fmt.Fprint(w, expectedPowerOnResponse)
    73  	})
    74  }
    75  
    76  func handlePowerOff(t *testing.T) {
    77  	th.Mux.HandleFunc("/cloudservers/action", func(w http.ResponseWriter, r *http.Request) {
    78  		th.TestMethod(t, r, "POST")
    79  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    80  		w.Header().Add("Content-Type", "application/json")
    81  		w.WriteHeader(http.StatusOK)
    82  		_, _ = fmt.Fprint(w, expectedPowerOffResponse)
    83  	})
    84  }