github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/compute/v2/remoteconsoles/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/http"
     7  	"testing"
     8  
     9  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/compute/v2/remoteconsoles"
    10  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    11  	fake "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    12  )
    13  
    14  func TestCreate(t *testing.T) {
    15  	th.SetupHTTP()
    16  	defer th.TeardownHTTP()
    17  
    18  	th.Mux.HandleFunc("/servers/b16ba811-199d-4ffd-8839-ba96c1185a67/remote-consoles", func(w http.ResponseWriter, r *http.Request) {
    19  		th.TestMethod(t, r, "POST")
    20  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    21  		th.TestHeader(t, r, "Content-Type", "application/json")
    22  		th.TestHeader(t, r, "Accept", "application/json")
    23  		th.TestJSONRequest(t, r, RemoteConsoleCreateRequest)
    24  
    25  		w.Header().Add("Content-Type", "application/json")
    26  		w.WriteHeader(http.StatusOK)
    27  
    28  		fmt.Fprint(w, RemoteConsoleCreateResult)
    29  	})
    30  
    31  	opts := remoteconsoles.CreateOpts{
    32  		Protocol: remoteconsoles.ConsoleProtocolVNC,
    33  		Type:     remoteconsoles.ConsoleTypeNoVNC,
    34  	}
    35  	s, err := remoteconsoles.Create(context.TODO(), fake.ServiceClient(), "b16ba811-199d-4ffd-8839-ba96c1185a67", opts).Extract()
    36  	th.AssertNoErr(t, err)
    37  
    38  	th.AssertEquals(t, s.Protocol, string(remoteconsoles.ConsoleProtocolVNC))
    39  	th.AssertEquals(t, s.Type, string(remoteconsoles.ConsoleTypeNoVNC))
    40  	th.AssertEquals(t, s.URL, "http://192.168.0.4:6080/vnc_auto.html?token=9a2372b9-6a0e-4f71-aca1-56020e6bb677")
    41  }