github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/v2/apigroups/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/apigroups"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  const (
    14  	expectedCreateResponse = `
    15  {
    16  	"id": "1c1acdd2f4d14eb886ecd2370cdb9c1a",
    17  	"is_default": 2,
    18  	"name": "terraform_test",
    19  	"on_sell_status": 2,
    20  	"register_time": "2021-06-22T07:02:20.133688796Z",
    21  	"remark": "Created by script",
    22  	"sl_domain": "1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com",
    23  	"sl_domains": [
    24  		"1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com"
    25  	],
    26  	"status": 1,
    27  	"update_time": "2021-06-22T07:02:20.133688906Z"
    28  }`
    29  
    30  	expectedListResponse = `
    31  {
    32  	"groups": [
    33  		{
    34  			"id": "1c1acdd2f4d14eb886ecd2370cdb9c1a",
    35  			"is_default": 2,
    36  			"name": "terraform_test",
    37  			"on_sell_status": 2,
    38  			"register_time": "2021-06-22T07:02:20.133688796Z",
    39  			"remark": "Created by script",
    40  			"sl_domain": "1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com",
    41  			"sl_domains": [
    42  				"1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com"
    43  			],
    44  			"status": 1,
    45  			"update_time": "2021-06-22T07:02:20.133688906Z"
    46  		}
    47  	]
    48  }`
    49  
    50  	expectedUpdateResponse = `
    51  {
    52  	"id": "1c1acdd2f4d14eb886ecd2370cdb9c1a",
    53  	"is_default": 2,
    54  	"name": "terraform_test_update",
    55  	"on_sell_status": 2,
    56  	"register_time": "2021-06-22T07:02:20.133688796Z",
    57  	"remark": "Updated by script",
    58  	"sl_domain": "1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com",
    59  	"sl_domains": [
    60  		"1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com"
    61  	],
    62  	"status": 1,
    63  	"update_time": "2021-06-22T07:02:20.133688906Z"
    64  }`
    65  )
    66  
    67  var (
    68  	createDesc = "Created by script"
    69  	createOpts = &apigroups.GroupOpts{
    70  		Name:        "terraform_test",
    71  		Description: &createDesc,
    72  	}
    73  
    74  	expectedCreateResponseData = &apigroups.Group{
    75  		Id:              "1c1acdd2f4d14eb886ecd2370cdb9c1a",
    76  		IsDefault:       2,
    77  		Name:            "terraform_test",
    78  		OnSellStatus:    2,
    79  		RegistraionTime: "2021-06-22T07:02:20.133688796Z",
    80  		Description:     "Created by script",
    81  		Subdomain:       "1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com",
    82  		Subdomains: []string{
    83  			"1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com",
    84  		},
    85  		Status:     1,
    86  		UpdateTime: "2021-06-22T07:02:20.133688906Z",
    87  	}
    88  
    89  	expectedUpdateResponseData = &apigroups.Group{
    90  		Id:              "1c1acdd2f4d14eb886ecd2370cdb9c1a",
    91  		IsDefault:       2,
    92  		Name:            "terraform_test_update",
    93  		OnSellStatus:    2,
    94  		RegistraionTime: "2021-06-22T07:02:20.133688796Z",
    95  		Description:     "Updated by script",
    96  		Subdomain:       "1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com",
    97  		Subdomains: []string{
    98  			"1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com",
    99  		},
   100  		Status:     1,
   101  		UpdateTime: "2021-06-22T07:02:20.133688906Z",
   102  	}
   103  
   104  	expectedListResponseData = []apigroups.Group{
   105  		{
   106  			Id:              "1c1acdd2f4d14eb886ecd2370cdb9c1a",
   107  			IsDefault:       2,
   108  			Name:            "terraform_test",
   109  			OnSellStatus:    2,
   110  			RegistraionTime: "2021-06-22T07:02:20.133688796Z",
   111  			Description:     "Created by script",
   112  			Subdomain:       "1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com",
   113  			Subdomains: []string{
   114  				"1c1acdd2f4d14eb886ecd2370cdb9c1a.apigw-cn-north-4-myhuaweicloud.com",
   115  			},
   116  			Status:     1,
   117  			UpdateTime: "2021-06-22T07:02:20.133688906Z",
   118  		},
   119  	}
   120  
   121  	updateDesc = "Updated by script"
   122  	updateOpts = apigroups.GroupOpts{
   123  		Name:        "terraform_test_update",
   124  		Description: &updateDesc,
   125  	}
   126  )
   127  
   128  func handleV2GroupCreate(t *testing.T) {
   129  	th.Mux.HandleFunc("/instances/9750f26518a54da8bea1a7c41790c26d/api-groups",
   130  		func(w http.ResponseWriter, r *http.Request) {
   131  			th.TestMethod(t, r, "POST")
   132  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   133  			w.Header().Add("Content-Type", "application/json")
   134  			w.WriteHeader(http.StatusAccepted)
   135  			_, _ = fmt.Fprint(w, expectedCreateResponse)
   136  		})
   137  }
   138  
   139  func handleV2GroupGet(t *testing.T) {
   140  	th.Mux.HandleFunc("/instances/9750f26518a54da8bea1a7c41790c26d/api-groups/1c1acdd2f4d14eb886ecd2370cdb9c1a",
   141  		func(w http.ResponseWriter, r *http.Request) {
   142  			th.TestMethod(t, r, "GET")
   143  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   144  			w.Header().Add("Content-Type", "application/json")
   145  			w.WriteHeader(http.StatusOK)
   146  			_, _ = fmt.Fprint(w, expectedCreateResponse)
   147  		})
   148  }
   149  
   150  func handleV2GroupList(t *testing.T) {
   151  	th.Mux.HandleFunc("/instances/9750f26518a54da8bea1a7c41790c26d/api-groups", func(w http.ResponseWriter, r *http.Request) {
   152  		th.TestMethod(t, r, "GET")
   153  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   154  		w.Header().Add("Content-Type", "application/json")
   155  		w.WriteHeader(http.StatusOK)
   156  		_, _ = fmt.Fprint(w, expectedListResponse)
   157  	})
   158  }
   159  
   160  func handleV2GroupUpdate(t *testing.T) {
   161  	th.Mux.HandleFunc("/instances/9750f26518a54da8bea1a7c41790c26d/api-groups/1c1acdd2f4d14eb886ecd2370cdb9c1a",
   162  		func(w http.ResponseWriter, r *http.Request) {
   163  			th.TestMethod(t, r, "PUT")
   164  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   165  			w.Header().Add("Content-Type", "application/json")
   166  			w.WriteHeader(http.StatusOK)
   167  			_, _ = fmt.Fprint(w, expectedUpdateResponse)
   168  		})
   169  }
   170  
   171  func handleV2GroupDelete(t *testing.T) {
   172  	th.Mux.HandleFunc("/instances/9750f26518a54da8bea1a7c41790c26d/api-groups/1c1acdd2f4d14eb886ecd2370cdb9c1a",
   173  		func(w http.ResponseWriter, r *http.Request) {
   174  			th.TestMethod(t, r, "DELETE")
   175  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   176  			w.Header().Add("Content-Type", "application/json")
   177  			w.WriteHeader(http.StatusNoContent)
   178  		})
   179  }