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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/huaweicloud/golangsdk"
    10  	"github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/networks"
    11  	th "github.com/huaweicloud/golangsdk/testhelper"
    12  	"github.com/huaweicloud/golangsdk/testhelper/client"
    13  )
    14  
    15  // ListOutput is a sample response to a List call.
    16  const ListOutput = `
    17  {
    18      "networks": [
    19          {
    20              "bridge": "br100",
    21              "bridge_interface": "eth0",
    22              "broadcast": "10.0.0.7",
    23              "cidr": "10.0.0.0/29",
    24              "cidr_v6": null,
    25              "created_at": "2011-08-15T06:19:19.387525",
    26              "deleted": false,
    27              "dhcp_start": "10.0.0.3",
    28              "dns1": null,
    29              "dns2": null,
    30              "gateway": "10.0.0.1",
    31              "gateway_v6": null,
    32              "host": "nsokolov-desktop",
    33              "id": "20c8acc0-f747-4d71-a389-46d078ebf047",
    34              "injected": false,
    35              "label": "mynet_0",
    36              "multi_host": false,
    37              "netmask": "255.255.255.248",
    38              "netmask_v6": null,
    39              "priority": null,
    40              "project_id": "1234",
    41              "rxtx_base": null,
    42              "updated_at": "2011-08-16T09:26:13.048257",
    43              "vlan": 100,
    44              "vpn_private_address": "10.0.0.2",
    45              "vpn_public_address": "127.0.0.1",
    46              "vpn_public_port": 1000
    47          },
    48          {
    49              "bridge": "br101",
    50              "bridge_interface": "eth0",
    51              "broadcast": "10.0.0.15",
    52              "cidr": "10.0.0.10/29",
    53              "cidr_v6": null,
    54              "created_at": "2011-08-15T06:19:19.387525",
    55              "deleted": false,
    56              "dhcp_start": "10.0.0.11",
    57              "dns1": null,
    58              "dns2": null,
    59              "gateway": "10.0.0.9",
    60              "gateway_v6": null,
    61              "host": null,
    62              "id": "20c8acc0-f747-4d71-a389-46d078ebf000",
    63              "injected": false,
    64              "label": "mynet_1",
    65              "multi_host": false,
    66              "netmask": "255.255.255.248",
    67              "netmask_v6": null,
    68              "priority": null,
    69              "project_id": null,
    70              "rxtx_base": null,
    71              "vlan": 101,
    72              "vpn_private_address": "10.0.0.10",
    73              "vpn_public_address": null,
    74              "vpn_public_port": 1001
    75          }
    76      ]
    77  }
    78  `
    79  
    80  // GetOutput is a sample response to a Get call.
    81  const GetOutput = `
    82  {
    83      "network": {
    84  			"bridge": "br101",
    85  			"bridge_interface": "eth0",
    86  			"broadcast": "10.0.0.15",
    87  			"cidr": "10.0.0.10/29",
    88  			"cidr_v6": null,
    89  			"created_at": "2011-08-15T06:19:19.387525",
    90  			"deleted": false,
    91  			"dhcp_start": "10.0.0.11",
    92  			"dns1": null,
    93  			"dns2": null,
    94  			"gateway": "10.0.0.9",
    95  			"gateway_v6": null,
    96  			"host": null,
    97  			"id": "20c8acc0-f747-4d71-a389-46d078ebf000",
    98  			"injected": false,
    99  			"label": "mynet_1",
   100  			"multi_host": false,
   101  			"netmask": "255.255.255.248",
   102  			"netmask_v6": null,
   103  			"priority": null,
   104  			"project_id": null,
   105  			"rxtx_base": null,
   106  			"vlan": 101,
   107  			"vpn_private_address": "10.0.0.10",
   108  			"vpn_public_address": null,
   109  			"vpn_public_port": 1001
   110  		}
   111  }
   112  `
   113  
   114  // FirstNetwork is the first result in ListOutput.
   115  var nilTime time.Time
   116  var FirstNetwork = networks.Network{
   117  	Bridge:            "br100",
   118  	BridgeInterface:   "eth0",
   119  	Broadcast:         "10.0.0.7",
   120  	CIDR:              "10.0.0.0/29",
   121  	CIDRv6:            "",
   122  	CreatedAt:         golangsdk.JSONRFC3339MilliNoZ(time.Date(2011, 8, 15, 6, 19, 19, 387525000, time.UTC)),
   123  	Deleted:           false,
   124  	DeletedAt:         golangsdk.JSONRFC3339MilliNoZ(nilTime),
   125  	DHCPStart:         "10.0.0.3",
   126  	DNS1:              "",
   127  	DNS2:              "",
   128  	Gateway:           "10.0.0.1",
   129  	Gatewayv6:         "",
   130  	Host:              "nsokolov-desktop",
   131  	ID:                "20c8acc0-f747-4d71-a389-46d078ebf047",
   132  	Injected:          false,
   133  	Label:             "mynet_0",
   134  	MultiHost:         false,
   135  	Netmask:           "255.255.255.248",
   136  	Netmaskv6:         "",
   137  	Priority:          0,
   138  	ProjectID:         "1234",
   139  	RXTXBase:          0,
   140  	UpdatedAt:         golangsdk.JSONRFC3339MilliNoZ(time.Date(2011, 8, 16, 9, 26, 13, 48257000, time.UTC)),
   141  	VLAN:              100,
   142  	VPNPrivateAddress: "10.0.0.2",
   143  	VPNPublicAddress:  "127.0.0.1",
   144  	VPNPublicPort:     1000,
   145  }
   146  
   147  // SecondNetwork is the second result in ListOutput.
   148  var SecondNetwork = networks.Network{
   149  	Bridge:            "br101",
   150  	BridgeInterface:   "eth0",
   151  	Broadcast:         "10.0.0.15",
   152  	CIDR:              "10.0.0.10/29",
   153  	CIDRv6:            "",
   154  	CreatedAt:         golangsdk.JSONRFC3339MilliNoZ(time.Date(2011, 8, 15, 6, 19, 19, 387525000, time.UTC)),
   155  	Deleted:           false,
   156  	DeletedAt:         golangsdk.JSONRFC3339MilliNoZ(nilTime),
   157  	DHCPStart:         "10.0.0.11",
   158  	DNS1:              "",
   159  	DNS2:              "",
   160  	Gateway:           "10.0.0.9",
   161  	Gatewayv6:         "",
   162  	Host:              "",
   163  	ID:                "20c8acc0-f747-4d71-a389-46d078ebf000",
   164  	Injected:          false,
   165  	Label:             "mynet_1",
   166  	MultiHost:         false,
   167  	Netmask:           "255.255.255.248",
   168  	Netmaskv6:         "",
   169  	Priority:          0,
   170  	ProjectID:         "",
   171  	RXTXBase:          0,
   172  	UpdatedAt:         golangsdk.JSONRFC3339MilliNoZ(nilTime),
   173  	VLAN:              101,
   174  	VPNPrivateAddress: "10.0.0.10",
   175  	VPNPublicAddress:  "",
   176  	VPNPublicPort:     1001,
   177  }
   178  
   179  // ExpectedNetworkSlice is the slice of results that should be parsed
   180  // from ListOutput, in the expected order.
   181  var ExpectedNetworkSlice = []networks.Network{FirstNetwork, SecondNetwork}
   182  
   183  // HandleListSuccessfully configures the test server to respond to a List request.
   184  func HandleListSuccessfully(t *testing.T) {
   185  	th.Mux.HandleFunc("/os-networks", func(w http.ResponseWriter, r *http.Request) {
   186  		th.TestMethod(t, r, "GET")
   187  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   188  
   189  		w.Header().Add("Content-Type", "application/json")
   190  		fmt.Fprintf(w, ListOutput)
   191  	})
   192  }
   193  
   194  // HandleGetSuccessfully configures the test server to respond to a Get request
   195  // for an existing network.
   196  func HandleGetSuccessfully(t *testing.T) {
   197  	th.Mux.HandleFunc("/os-networks/20c8acc0-f747-4d71-a389-46d078ebf000", func(w http.ResponseWriter, r *http.Request) {
   198  		th.TestMethod(t, r, "GET")
   199  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   200  
   201  		w.Header().Add("Content-Type", "application/json")
   202  		fmt.Fprintf(w, GetOutput)
   203  	})
   204  }