github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/v2/channels/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/channels"
     9  
    10  	th "github.com/huaweicloud/golangsdk/testhelper"
    11  	"github.com/huaweicloud/golangsdk/testhelper/client"
    12  )
    13  
    14  const (
    15  	expectedCreateResponse = `
    16  {
    17  	"balance_strategy": 1,
    18  	"create_time": "2021-07-05T09:29:38Z",
    19  	"id": "328d1d563eba4ff084533188b84b9f8d",
    20  	"member_type": "ecs",
    21  	"name": "terraform_test",
    22  	"port": 8080,
    23  	"status": 1,
    24  	"type": 2
    25  }`
    26  	expectedGetResponse = `
    27  {
    28  	"balance_strategy": 1,
    29  	"create_time": "2021-07-05T09:29:38Z",
    30  	"id": "328d1d563eba4ff084533188b84b9f8d",
    31  	"member_type": "ecs",
    32  	"members": [
    33  		{
    34  			"ecs_id": "dfe1f776-dd07-4ec0-912f-47525679d76a",
    35  			"ecs_name": "terraform_test",
    36  			"host": "192.168.9.195",
    37  			"weight": 1
    38  		}
    39  	],
    40  	"name": "terraform_test",
    41  	"port": 8080,
    42  	"status": 1,
    43  	"type": 2,
    44  	"vpc_health_config": {
    45  		"http_code": "201,202,203",
    46  		"method": "GET",
    47  		"path": "/",
    48  		"port": 8080,
    49  		"protocol": "https",
    50  		"threshold_abnormal": 5,
    51  		"threshold_normal": 2,
    52  		"time_interval": 10,
    53  		"timeout": 5
    54  	}
    55  }`
    56  	expectedListResponse = `
    57  {
    58  	"vpc_channels": [
    59  		{
    60  			"balance_strategy": 1,
    61  			"create_time": "2021-07-05T09:29:38Z",
    62  			"id": "328d1d563eba4ff084533188b84b9f8d",
    63  			"member_type": "ecs",
    64  			"members": [
    65  				{
    66  					"create_time": "2021-07-05T09:29:38Z",
    67  					"ecs_id": "dfe1f776-dd07-4ec0-912f-47525679d76a",
    68  					"ecs_name": "terraform_test",
    69  					"host": "192.168.9.195",
    70  					"id": "a4ffcf94477a4e3697deb5700313d861",
    71  					"status": 1,
    72  					"vpc_channel_id": "328d1d563eba4ff084533188b84b9f8d",
    73  					"weight": 1
    74  				}
    75  			],
    76  			"name": "terraform_test",
    77  			"port": 8080,
    78  			"status": 1,
    79  			"type": 2,
    80  			"vpc_health_config": {
    81  				"create_time": "2021-07-05T09:29:38Z",
    82  				"http_code": "201,202,203",
    83  				"id": "caa3f8122eef4ce98794e84cf9fc5543",
    84  				"method": "GET",
    85  				"path": "/",
    86  				"port": 8080,
    87  				"protocol": "https",
    88  				"threshold_abnormal": 5,
    89  				"threshold_normal": 2,
    90  				"time_interval": 10,
    91  				"timeout": 5,
    92  				"vpc_channel_id": "328d1d563eba4ff084533188b84b9f8d"
    93  			}
    94  		}
    95  	]
    96  }
    97  `
    98  )
    99  
   100  var (
   101  	createOpts = &channels.ChannelOpts{
   102  		Name: "terraform_test",
   103  		Type: 2,
   104  		Members: []channels.MemberInfo{
   105  			{
   106  				EcsId:   "dfe1f776-dd07-4ec0-912f-47525679d76a",
   107  				EcsName: "terraform_test",
   108  				Weight:  1,
   109  			},
   110  		},
   111  		VpcHealthConfig: channels.VpcHealthConfig{
   112  			Protocol:          "https",
   113  			Path:              "/",
   114  			Method:            "GET",
   115  			Port:              8080,
   116  			ThresholdAbnormal: 5,
   117  			ThresholdNormal:   2,
   118  			TimeInterval:      10,
   119  			Timeout:           5,
   120  			HttpCodes:         "201,202,203",
   121  			EnableClientSsl:   false,
   122  		},
   123  		Port:            8080,
   124  		BalanceStrategy: 1,
   125  		MemberType:      "ecs",
   126  	}
   127  
   128  	expectedCreateResponseData = &channels.VpcChannel{
   129  		Id:              "328d1d563eba4ff084533188b84b9f8d",
   130  		Name:            "terraform_test",
   131  		CreateTime:      "2021-07-05T09:29:38Z",
   132  		MemberType:      "ecs",
   133  		Status:          1,
   134  		Type:            2,
   135  		BalanceStrategy: 1,
   136  		Port:            8080,
   137  	}
   138  
   139  	expectedGetResponseData = &channels.VpcChannel{
   140  		Id:              "328d1d563eba4ff084533188b84b9f8d",
   141  		BalanceStrategy: 1,
   142  		CreateTime:      "2021-07-05T09:29:38Z",
   143  		MemberType:      "ecs",
   144  		Members: []channels.MemberInfo{
   145  			{
   146  				EcsId:   "dfe1f776-dd07-4ec0-912f-47525679d76a",
   147  				EcsName: "terraform_test",
   148  				Weight:  1,
   149  				Host:    "192.168.9.195",
   150  			},
   151  		},
   152  		Name:   "terraform_test",
   153  		Port:   8080,
   154  		Status: 1,
   155  		Type:   2,
   156  		VpcHealthConfig: channels.VpcHealthConfig{
   157  			Protocol:          "https",
   158  			Path:              "/",
   159  			Method:            "GET",
   160  			Port:              8080,
   161  			ThresholdNormal:   2,
   162  			ThresholdAbnormal: 5,
   163  			HttpCodes:         "201,202,203",
   164  			TimeInterval:      10,
   165  			Timeout:           5,
   166  		},
   167  	}
   168  
   169  	expectedListResponseData = []channels.VpcChannel{
   170  		{
   171  			Id:              "328d1d563eba4ff084533188b84b9f8d",
   172  			BalanceStrategy: 1,
   173  			CreateTime:      "2021-07-05T09:29:38Z",
   174  			MemberType:      "ecs",
   175  			Members: []channels.MemberInfo{
   176  				{
   177  					EcsId:   "dfe1f776-dd07-4ec0-912f-47525679d76a",
   178  					EcsName: "terraform_test",
   179  					Weight:  1,
   180  					Host:    "192.168.9.195",
   181  				},
   182  			},
   183  			Name:   "terraform_test",
   184  			Port:   8080,
   185  			Status: 1,
   186  			Type:   2,
   187  			VpcHealthConfig: channels.VpcHealthConfig{
   188  				Protocol:          "https",
   189  				Path:              "/",
   190  				Method:            "GET",
   191  				Port:              8080,
   192  				ThresholdNormal:   2,
   193  				ThresholdAbnormal: 5,
   194  				HttpCodes:         "201,202,203",
   195  				TimeInterval:      10,
   196  				Timeout:           5,
   197  			},
   198  		},
   199  	}
   200  )
   201  
   202  func handleV2VpcChannelCreate(t *testing.T) {
   203  	th.Mux.HandleFunc("/instances/b510b8e8ef1442c0a94cdfc551af0ec3/vpc-channels",
   204  		func(w http.ResponseWriter, r *http.Request) {
   205  			th.TestMethod(t, r, "POST")
   206  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   207  			w.Header().Add("Content-Type", "application/json")
   208  			w.WriteHeader(http.StatusCreated)
   209  			_, _ = fmt.Fprint(w, expectedCreateResponse)
   210  		})
   211  }
   212  
   213  func handleV2VpcChannelGet(t *testing.T) {
   214  	th.Mux.HandleFunc("/instances/b510b8e8ef1442c0a94cdfc551af0ec3/vpc-channels/328d1d563eba4ff084533188b84b9f8d",
   215  		func(w http.ResponseWriter, r *http.Request) {
   216  			th.TestMethod(t, r, "GET")
   217  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   218  			w.Header().Add("Content-Type", "application/json")
   219  			w.WriteHeader(http.StatusOK)
   220  			_, _ = fmt.Fprint(w, expectedGetResponse)
   221  		})
   222  }
   223  
   224  func handleV2VpcChannelList(t *testing.T) {
   225  	th.Mux.HandleFunc("/instances/b510b8e8ef1442c0a94cdfc551af0ec3/vpc-channels",
   226  		func(w http.ResponseWriter, r *http.Request) {
   227  			th.TestMethod(t, r, "GET")
   228  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   229  			w.Header().Add("Content-Type", "application/json")
   230  			w.WriteHeader(http.StatusOK)
   231  			_, _ = fmt.Fprint(w, expectedListResponse)
   232  		})
   233  }
   234  
   235  func handleV2VpcChannelUpdate(t *testing.T) {
   236  	th.Mux.HandleFunc("/instances/b510b8e8ef1442c0a94cdfc551af0ec3/vpc-channels/328d1d563eba4ff084533188b84b9f8d",
   237  		func(w http.ResponseWriter, r *http.Request) {
   238  			th.TestMethod(t, r, "PUT")
   239  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   240  			w.Header().Add("Content-Type", "application/json")
   241  			w.WriteHeader(http.StatusOK)
   242  			_, _ = fmt.Fprint(w, expectedGetResponse)
   243  		})
   244  }
   245  
   246  func handleV2VpcChannelDelete(t *testing.T) {
   247  	th.Mux.HandleFunc("/instances/b510b8e8ef1442c0a94cdfc551af0ec3/vpc-channels/328d1d563eba4ff084533188b84b9f8d",
   248  		func(w http.ResponseWriter, r *http.Request) {
   249  			th.TestMethod(t, r, "DELETE")
   250  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   251  			w.Header().Add("Content-Type", "application/json")
   252  			w.WriteHeader(http.StatusNoContent)
   253  		})
   254  }