github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/attachinterfaces/testing/fixtures.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/attachinterfaces"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  // ListInterfacesExpected represents an expected repsonse from a ListInterfaces request.
    14  var ListInterfacesExpected = []attachinterfaces.Interface{
    15  	{
    16  		PortState: "ACTIVE",
    17  		FixedIPs: []attachinterfaces.FixedIP{
    18  			{
    19  				SubnetID:  "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
    20  				IPAddress: "10.0.0.7",
    21  			},
    22  			{
    23  				SubnetID:  "45906d64-a548-4276-h1f8-kcffa80fjbnl",
    24  				IPAddress: "10.0.0.8",
    25  			},
    26  		},
    27  		PortID:  "0dde1598-b374-474e-986f-5b8dd1df1d4e",
    28  		NetID:   "8a5fe506-7e9f-4091-899b-96336909d93c",
    29  		MACAddr: "fa:16:3e:38:2d:80",
    30  	},
    31  }
    32  
    33  // GetInterfaceExpected represents an expected repsonse from a GetInterface request.
    34  var GetInterfaceExpected = attachinterfaces.Interface{
    35  	PortState: "ACTIVE",
    36  	FixedIPs: []attachinterfaces.FixedIP{
    37  		{
    38  			SubnetID:  "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
    39  			IPAddress: "10.0.0.7",
    40  		},
    41  		{
    42  			SubnetID:  "45906d64-a548-4276-h1f8-kcffa80fjbnl",
    43  			IPAddress: "10.0.0.8",
    44  		},
    45  	},
    46  	PortID:  "0dde1598-b374-474e-986f-5b8dd1df1d4e",
    47  	NetID:   "8a5fe506-7e9f-4091-899b-96336909d93c",
    48  	MACAddr: "fa:16:3e:38:2d:80",
    49  }
    50  
    51  // CreateInterfacesExpected represents an expected repsonse from a CreateInterface request.
    52  var CreateInterfacesExpected = attachinterfaces.Interface{
    53  	PortState: "ACTIVE",
    54  	FixedIPs: []attachinterfaces.FixedIP{
    55  		{
    56  			SubnetID:  "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
    57  			IPAddress: "10.0.0.7",
    58  		},
    59  	},
    60  	PortID:  "0dde1598-b374-474e-986f-5b8dd1df1d4e",
    61  	NetID:   "8a5fe506-7e9f-4091-899b-96336909d93c",
    62  	MACAddr: "fa:16:3e:38:2d:80",
    63  }
    64  
    65  // HandleInterfaceListSuccessfully sets up the test server to respond to a ListInterfaces request.
    66  func HandleInterfaceListSuccessfully(t *testing.T) {
    67  	th.Mux.HandleFunc("/servers/b07e7a3b-d951-4efc-a4f9-ac9f001afb7f/os-interface", func(w http.ResponseWriter, r *http.Request) {
    68  		th.TestMethod(t, r, "GET")
    69  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    70  
    71  		w.Header().Add("Content-Type", "application/json")
    72  		fmt.Fprintf(w, `{
    73  			"interfaceAttachments": [
    74  				{
    75  					"port_state":"ACTIVE",
    76  					"fixed_ips": [
    77  						{
    78  							"subnet_id": "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
    79  							"ip_address": "10.0.0.7"
    80  						},
    81  						{
    82  							"subnet_id": "45906d64-a548-4276-h1f8-kcffa80fjbnl",
    83  							"ip_address": "10.0.0.8"
    84  						}
    85  					],
    86  					"port_id": "0dde1598-b374-474e-986f-5b8dd1df1d4e",
    87  					"net_id": "8a5fe506-7e9f-4091-899b-96336909d93c",
    88  					"mac_addr": "fa:16:3e:38:2d:80"
    89  				}
    90  			]
    91  		}`)
    92  	})
    93  }
    94  
    95  // HandleInterfaceGetSuccessfully sets up the test server to respond to a GetInterface request.
    96  func HandleInterfaceGetSuccessfully(t *testing.T) {
    97  	th.Mux.HandleFunc("/servers/b07e7a3b-d951-4efc-a4f9-ac9f001afb7f/os-interface/0dde1598-b374-474e-986f-5b8dd1df1d4e", func(w http.ResponseWriter, r *http.Request) {
    98  		th.TestMethod(t, r, "GET")
    99  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   100  
   101  		w.Header().Add("Content-Type", "application/json")
   102  		fmt.Fprintf(w, `{
   103  			"interfaceAttachment":
   104  				{
   105  					"port_state":"ACTIVE",
   106  					"fixed_ips": [
   107  						{
   108  							"subnet_id": "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
   109  							"ip_address": "10.0.0.7"
   110  						},
   111  						{
   112  							"subnet_id": "45906d64-a548-4276-h1f8-kcffa80fjbnl",
   113  							"ip_address": "10.0.0.8"
   114  						}
   115  					],
   116  					"port_id": "0dde1598-b374-474e-986f-5b8dd1df1d4e",
   117  					"net_id": "8a5fe506-7e9f-4091-899b-96336909d93c",
   118  					"mac_addr": "fa:16:3e:38:2d:80"
   119  				}
   120  		}`)
   121  	})
   122  }
   123  
   124  // HandleInterfaceCreateSuccessfully sets up the test server to respond to a CreateInterface request.
   125  func HandleInterfaceCreateSuccessfully(t *testing.T) {
   126  	th.Mux.HandleFunc("/servers/b07e7a3b-d951-4efc-a4f9-ac9f001afb7f/os-interface", func(w http.ResponseWriter, r *http.Request) {
   127  		th.TestMethod(t, r, "POST")
   128  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   129  		th.TestJSONRequest(t, r, `{
   130  			  "interfaceAttachment": {
   131  				"net_id": "8a5fe506-7e9f-4091-899b-96336909d93c"
   132  			  }
   133  		}`)
   134  
   135  		w.Header().Add("Content-Type", "application/json")
   136  		fmt.Fprintf(w, `{
   137  			"interfaceAttachment":
   138  				{
   139  					"port_state":"ACTIVE",
   140  					"fixed_ips": [
   141  						{
   142  							"subnet_id": "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
   143  							"ip_address": "10.0.0.7"
   144  						}
   145  					],
   146  					"port_id": "0dde1598-b374-474e-986f-5b8dd1df1d4e",
   147  					"net_id": "8a5fe506-7e9f-4091-899b-96336909d93c",
   148  					"mac_addr": "fa:16:3e:38:2d:80"
   149  				}
   150  		}`)
   151  	})
   152  }
   153  
   154  // HandleInterfaceDeleteSuccessfully sets up the test server to respond to a DeleteInterface request.
   155  func HandleInterfaceDeleteSuccessfully(t *testing.T) {
   156  	th.Mux.HandleFunc("/servers/b07e7a3b-d951-4efc-a4f9-ac9f001afb7f/os-interface/0dde1598-b374-474e-986f-5b8dd1df1d4e", func(w http.ResponseWriter, r *http.Request) {
   157  		th.TestMethod(t, r, "DELETE")
   158  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   159  
   160  		w.WriteHeader(http.StatusAccepted)
   161  	})
   162  }