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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/huaweicloud/golangsdk/openstack/apigw/v2/instances"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  const (
    14  	expectedCreateRequest = `
    15  {
    16  	"available_zone_ids": [
    17  		"ap-southeast-2a",
    18  		"ap-southeast-2b"
    19  	],
    20  	"bandwidth_size": 6,
    21  	"description": "Created by script",
    22  	"eip_id": "9361e906-340d-4603-9e67-dadecc6c95ad",
    23  	"enterprise_project_id": "4a52b236-2644-4c10-b31c-7d53a58f75a3",
    24  	"instance_name": "terraform-test",
    25  	"maintain_begin": "22:00:00",
    26  	"maintain_end": "02:00:00",
    27  	"security_group_id": "0f3fa672-e3f1-4e8d-b4d1-d160d408eca8",
    28  	"spec_id": "BASIC",
    29  	"subnet_id": "8149c60b-939f-4eec-a667-6d40aa1e14df",
    30  	"vpc_id": "faf4d1ae-350a-45b5-9d4b-5754b6720cce"
    31  }`
    32  	expectedCreateResponse = `
    33  {
    34  	"instance_id": "e6a5871bfb5b47d19c5874790f639ef8"
    35  }`
    36  	expectedGetResponse = `
    37  {
    38  	"available_zone_ids": "[cn-north-4a]",
    39  	"bandwidth_size": 5,
    40  	"charging_mode": 0,
    41  	"create_time": 1623742314452,
    42  	"enterprise_project_id": "4a52b236-2644-4c10-b31c-7d53a58f75",
    43  	"id": "3fb0bdaa8b27480c971f78734497cd17",
    44  	"ingress_ip": "192.168.155.102",
    45  	"instance_name": "terraform-test",
    46  	"instance_status": 6,
    47  	"instance_version": "fe97b022e6cf401c9e6679f35cf7b130",
    48  	"maintain_begin": "22:00:00",
    49  	"maintain_end": "02:00:00",
    50  	"nat_eip_address": "94.74.112.175",
    51  	"security_group_id": "4b23c9b9-f941-477b-92f0-3adc6eb76124",
    52  	"spec": "BASIC",
    53  	"status": "Running",
    54  	"subnet_id": "7fd65ff0-3ccb-4756-a98c-e2bfe91d3c69",
    55  	"supported_features": [
    56  		"gateway_responses",
    57  		"ratelimit",
    58  		"request_body_size",
    59  		"backend_timeout",
    60  		"app_token",
    61  		"app_basic",
    62  		"app_secret",
    63  		"multi_auth",
    64  		"route",
    65  		"sign_basic",
    66  		"app_route",
    67  		"backend_client_certificate",
    68  		"ssl_ciphers",
    69  		"cors",
    70  		"app_quota",
    71  		"app_acl",
    72  		"real_ip_from_xff",
    73  		"set_resp_headers"
    74  	],
    75  	"user_id": "05602623488025011f3bc015b70b16c3",
    76  	"vpc_id": "1c105033-5b68-4cfe-b58b-b1000e517908"
    77  }`
    78  	expectedListResponse = `
    79  {
    80  	"instances": [
    81  		{
    82  			"charging_mode": 0,
    83  			"create_time": 1623816488875,
    84  			"eip_address": null,
    85  			"enterprise_project_id": "4a52b236-2644-4c10-b31c-7d53a58f75a3",
    86  			"id": "de379eed30aa4d31a84f426ea3c7ef4e",
    87  			"instance_name": "tf-acc-test-0616",
    88  			"instance_status": 6,
    89  			"project_id": "0581b95a0b8010e32f81c015009f6587",
    90  			"spec": "BASIC",
    91  			"status": "Running",
    92  			"type": "apig"
    93  		}
    94  	]
    95  }`
    96  )
    97  
    98  var (
    99  	createOpts = &instances.CreateOpts{
   100  		AvailableZoneIds:    []string{"ap-southeast-2a", "ap-southeast-2b"},
   101  		BandwidthSize:       6,
   102  		Description:         "Created by script",
   103  		EipId:               "9361e906-340d-4603-9e67-dadecc6c95ad",
   104  		EnterpriseProjectId: "4a52b236-2644-4c10-b31c-7d53a58f75a3",
   105  		Name:                "terraform-test",
   106  		MaintainBegin:       "22:00:00",
   107  		MaintainEnd:         "02:00:00",
   108  		SecurityGroupId:     "0f3fa672-e3f1-4e8d-b4d1-d160d408eca8",
   109  		Edition:             "BASIC",
   110  		SubnetId:            "8149c60b-939f-4eec-a667-6d40aa1e14df",
   111  		VpcId:               "faf4d1ae-350a-45b5-9d4b-5754b6720cce",
   112  	}
   113  
   114  	expectedCreateResponseData = &instances.CreateResp{
   115  		Id: "e6a5871bfb5b47d19c5874790f639ef8",
   116  	}
   117  
   118  	expectedListResponseData = []instances.BaseInstance{
   119  		{
   120  			ChargeMode:          0,
   121  			CreateTimestamp:     1623816488875,
   122  			EnterpriseProjectId: "4a52b236-2644-4c10-b31c-7d53a58f75a3",
   123  			Id:                  "de379eed30aa4d31a84f426ea3c7ef4e",
   124  			Name:                "tf-acc-test-0616",
   125  			StatusId:            6,
   126  			ProjectId:           "0581b95a0b8010e32f81c015009f6587",
   127  			Edition:             "BASIC",
   128  			Status:              "Running",
   129  			Type:                "apig",
   130  		},
   131  	}
   132  
   133  	updateOpts = instances.UpdateOpts{
   134  		Description:   "Updated by script",
   135  		Name:          "terraform-update",
   136  		MaintainBegin: "18:00:00",
   137  		MaintainEnd:   "22:00:00",
   138  	}
   139  
   140  	updateEgressOpts = instances.EgressAccessOpts{
   141  		BandwidthSize: "10",
   142  	}
   143  
   144  	updateIngressOpts = instances.IngressAccessOpts{
   145  		EipId: "706673d2-e36b-4577-87bc-e6d6e71812f7",
   146  	}
   147  
   148  	expectedGetResponseData = &instances.Instance{
   149  		AvailableZoneIds:      "[cn-north-4a]",
   150  		BandwidthSize:         5,
   151  		ChargeMode:            0,
   152  		CreateTimestamp:       1623742314452,
   153  		EnterpriseProjectId:   "4a52b236-2644-4c10-b31c-7d53a58f75",
   154  		Id:                    "3fb0bdaa8b27480c971f78734497cd17",
   155  		Ipv4VpcIngressAddress: "192.168.155.102",
   156  		Name:                  "terraform-test",
   157  		StatusId:              6,
   158  		Version:               "fe97b022e6cf401c9e6679f35cf7b130",
   159  		MaintainBegin:         "22:00:00",
   160  		MaintainEnd:           "02:00:00",
   161  		Ipv4EgressAddress:     "94.74.112.175",
   162  		SecurityGroupId:       "4b23c9b9-f941-477b-92f0-3adc6eb76124",
   163  		Edition:               "BASIC",
   164  		Status:                "Running",
   165  		SubnetId:              "7fd65ff0-3ccb-4756-a98c-e2bfe91d3c69",
   166  		SupportedFeatures: []string{
   167  			"gateway_responses",
   168  			"ratelimit",
   169  			"request_body_size",
   170  			"backend_timeout",
   171  			"app_token",
   172  			"app_basic",
   173  			"app_secret",
   174  			"multi_auth",
   175  			"route",
   176  			"sign_basic",
   177  			"app_route",
   178  			"backend_client_certificate",
   179  			"ssl_ciphers",
   180  			"cors",
   181  			"app_quota",
   182  			"app_acl",
   183  			"real_ip_from_xff",
   184  			"set_resp_headers",
   185  		},
   186  		VpcId:  "1c105033-5b68-4cfe-b58b-b1000e517908",
   187  		UserId: "05602623488025011f3bc015b70b16c3",
   188  	}
   189  )
   190  
   191  func handleV2InstanceCreate(t *testing.T) {
   192  	th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) {
   193  		th.TestMethod(t, r, "POST")
   194  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   195  		w.Header().Add("Content-Type", "application/json")
   196  		w.WriteHeader(http.StatusAccepted)
   197  		_, _ = fmt.Fprint(w, expectedCreateResponse)
   198  	})
   199  }
   200  
   201  func handleV2InstanceGet(t *testing.T) {
   202  	th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8", func(w http.ResponseWriter, r *http.Request) {
   203  		th.TestMethod(t, r, "GET")
   204  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   205  		w.Header().Add("Content-Type", "application/json")
   206  		w.WriteHeader(http.StatusOK)
   207  		_, _ = fmt.Fprint(w, expectedGetResponse)
   208  	})
   209  }
   210  
   211  func handleV2InstanceList(t *testing.T) {
   212  	th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) {
   213  		th.TestMethod(t, r, "GET")
   214  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   215  		w.Header().Add("Content-Type", "application/json")
   216  		w.WriteHeader(http.StatusOK)
   217  		_, _ = fmt.Fprint(w, expectedListResponse)
   218  	})
   219  }
   220  
   221  func handleV2InstanceUpdate(t *testing.T) {
   222  	th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8", func(w http.ResponseWriter, r *http.Request) {
   223  		th.TestMethod(t, r, "PUT")
   224  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   225  		w.Header().Add("Content-Type", "application/json")
   226  		w.WriteHeader(http.StatusOK)
   227  		_, _ = fmt.Fprint(w, expectedGetResponse)
   228  	})
   229  }
   230  
   231  func handleV2InstanceDelete(t *testing.T) {
   232  	th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8", func(w http.ResponseWriter, r *http.Request) {
   233  		th.TestMethod(t, r, "DELETE")
   234  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   235  		w.Header().Add("Content-Type", "application/json")
   236  		w.WriteHeader(http.StatusNoContent)
   237  	})
   238  }
   239  
   240  func handleV2InstanceEgressDisable(t *testing.T) {
   241  	th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8/nat-eip", func(w http.ResponseWriter, r *http.Request) {
   242  		th.TestMethod(t, r, "DELETE")
   243  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   244  		w.Header().Add("Content-Type", "application/json")
   245  		w.WriteHeader(http.StatusNoContent)
   246  		_, _ = fmt.Fprint(w, expectedGetResponse)
   247  	})
   248  }
   249  
   250  func handleV2InstanceIngressDisable(t *testing.T) {
   251  	th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8/eip", func(w http.ResponseWriter, r *http.Request) {
   252  		th.TestMethod(t, r, "DELETE")
   253  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   254  		w.Header().Add("Content-Type", "application/json")
   255  		w.WriteHeader(http.StatusOK)
   256  	})
   257  }