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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/rescueunrescue"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	fake "github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  func TestRescue(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  
    17  	th.Mux.HandleFunc("/servers/3f54d05f-3430-4d80-aa07-63e6af9e2488/action", func(w http.ResponseWriter, r *http.Request) {
    18  		th.TestMethod(t, r, "POST")
    19  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    20  		th.TestJSONRequest(t, r, RescueRequest)
    21  
    22  		w.WriteHeader(http.StatusOK)
    23  		fmt.Fprintf(w, RescueResult)
    24  	})
    25  
    26  	s, err := rescueunrescue.Rescue(fake.ServiceClient(), "3f54d05f-3430-4d80-aa07-63e6af9e2488", rescueunrescue.RescueOpts{
    27  		AdminPass:      "aUPtawPzE9NU",
    28  		RescueImageRef: "115e5c5b-72f0-4a0a-9067-60706545248c",
    29  	}).Extract()
    30  	th.AssertNoErr(t, err)
    31  
    32  	th.AssertEquals(t, "aUPtawPzE9NU", s)
    33  }
    34  
    35  func TestUnrescue(t *testing.T) {
    36  	th.SetupHTTP()
    37  	defer th.TeardownHTTP()
    38  
    39  	th.Mux.HandleFunc("/servers/3f54d05f-3430-4d80-aa07-63e6af9e2488/action", func(w http.ResponseWriter, r *http.Request) {
    40  		th.TestMethod(t, r, "POST")
    41  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    42  		th.TestJSONRequest(t, r, UnrescueRequest)
    43  
    44  		w.WriteHeader(http.StatusAccepted)
    45  	})
    46  
    47  	err := rescueunrescue.Unrescue(fake.ServiceClient(), "3f54d05f-3430-4d80-aa07-63e6af9e2488").ExtractErr()
    48  	th.AssertNoErr(t, err)
    49  }