github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/v2/throttles/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/throttles"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  const (
    14  	expectedCreateResponse = `
    15  {
    16  	"api_call_limits": 50,
    17  	"app_call_limits": 20,
    18  	"bind_num": 0,
    19  	"create_time": "2021-07-19T08:46:39.799181829Z",
    20  	"id": "c481043838f64bcd82c7b0c38907d59d",
    21  	"ip_call_limits": 15,
    22  	"name": "terraform_test",
    23  	"remark": "Created by script",
    24  	"time_interval": 10,
    25  	"time_unit": "MINUTE",
    26  	"type": 1,
    27  	"user_call_limits": 20
    28  }`
    29  
    30  	expectedListResponse = `
    31  {
    32  	"throttles": [
    33  		{
    34  			"api_call_limits": 50,
    35  			"app_call_limits": 20,
    36  			"bind_num": 0,
    37  			"create_time": "2021-07-19T08:46:39.799181829Z",
    38  			"id": "c481043838f64bcd82c7b0c38907d59d",
    39  			"ip_call_limits": 15,
    40  			"name": "terraform_test",
    41  			"remark": "Created by script",
    42  			"time_interval": 10,
    43  			"time_unit": "MINUTE",
    44  			"type": 1,
    45  			"user_call_limits": 20
    46  		}
    47  	]
    48  }`
    49  
    50  	expectedSpecCreateResponse = `
    51  {
    52  	"app_id": "ba985f3d4fd347c3aee686fd749659fc",
    53  	"app_name": "terraform_app",
    54  	"apply_time": "2021-07-21T06:48:03.618383329Z",
    55  	"call_limits": 30,
    56  	"id": "aec8d27e3e034f4293bc766942ed60fd",
    57  	"object_id": "ba985f3d4fd347c3aee686fd749659fc",
    58  	"object_name": "terraform_app",
    59  	"object_type": "APP",
    60  	"throttle_id": "c481043838f64bcd82c7b0c38907d59d"
    61  }`
    62  
    63  	expectedSpecListResponse = `
    64  {
    65  	"throttle_specials": [
    66  		{
    67  			"app_id": "ba985f3d4fd347c3aee686fd749659fc",
    68  			"app_name": "terraform_app",
    69  			"apply_time": "2021-07-21T06:48:03.618383329Z",
    70  			"call_limits": 30,
    71  			"id": "aec8d27e3e034f4293bc766942ed60fd",
    72  			"object_id": "ba985f3d4fd347c3aee686fd749659fc",
    73  			"object_name": "terraform_app",
    74  			"object_type": "APP",
    75  			"throttle_id": "c481043838f64bcd82c7b0c38907d59d"
    76  		}
    77  	],
    78  	"size": 1,
    79  	"total": 1
    80  }`
    81  )
    82  
    83  var (
    84  	createOpts = &throttles.ThrottlingPolicyOpts{
    85  		Name:           "terraform_test",
    86  		Type:           1,
    87  		TimeInterval:   10,
    88  		TimeUnit:       "MINUTE",
    89  		ApiCallLimits:  50,
    90  		UserCallLimits: 20,
    91  		AppCallLimits:  20,
    92  		IpCallLimits:   15,
    93  		Description:    "Created by script",
    94  	}
    95  
    96  	expectedCreateResponseData = &throttles.ThrottlingPolicy{
    97  		Name:           "terraform_test",
    98  		Type:           1,
    99  		TimeInterval:   10,
   100  		TimeUnit:       "MINUTE",
   101  		ApiCallLimits:  50,
   102  		UserCallLimits: 20,
   103  		AppCallLimits:  20,
   104  		IpCallLimits:   15,
   105  		Description:    "Created by script",
   106  		BindNum:        0,
   107  		CreateTime:     "2021-07-19T08:46:39.799181829Z",
   108  		Id:             "c481043838f64bcd82c7b0c38907d59d",
   109  	}
   110  
   111  	listOpts = throttles.ListOpts{
   112  		Name: "terraform_test",
   113  	}
   114  
   115  	expectedListResponseData = []throttles.ThrottlingPolicy{
   116  		{
   117  			Name:           "terraform_test",
   118  			Type:           1,
   119  			TimeInterval:   10,
   120  			TimeUnit:       "MINUTE",
   121  			ApiCallLimits:  50,
   122  			UserCallLimits: 20,
   123  			AppCallLimits:  20,
   124  			IpCallLimits:   15,
   125  			Description:    "Created by script",
   126  			BindNum:        0,
   127  			CreateTime:     "2021-07-19T08:46:39.799181829Z",
   128  			Id:             "c481043838f64bcd82c7b0c38907d59d",
   129  		},
   130  	}
   131  
   132  	specThrottleCreateOpts = &throttles.SpecThrottleCreateOpts{
   133  		CallLimits: 30,
   134  		ObjectId:   "ba985f3d4fd347c3aee686fd749659fc",
   135  		ObjectType: "APP",
   136  	}
   137  
   138  	expectedSpecCreateResponseData = &throttles.SpecThrottle{
   139  		AppId:      "ba985f3d4fd347c3aee686fd749659fc",
   140  		AppName:    "terraform_app",
   141  		ApplyTime:  "2021-07-21T06:48:03.618383329Z",
   142  		CallLimits: 30,
   143  		ID:         "aec8d27e3e034f4293bc766942ed60fd",
   144  		ObjectId:   "ba985f3d4fd347c3aee686fd749659fc",
   145  		ObjectName: "terraform_app",
   146  		ObjectType: "APP",
   147  		ThrottleId: "c481043838f64bcd82c7b0c38907d59d",
   148  	}
   149  
   150  	specThrottleListOpts = &throttles.SpecThrottlesListOpts{
   151  		AppName: "terraform_app",
   152  	}
   153  
   154  	expectedSpecListResponseData = []throttles.SpecThrottle{
   155  		{
   156  			AppId:      "ba985f3d4fd347c3aee686fd749659fc",
   157  			AppName:    "terraform_app",
   158  			ApplyTime:  "2021-07-21T06:48:03.618383329Z",
   159  			CallLimits: 30,
   160  			ID:         "aec8d27e3e034f4293bc766942ed60fd",
   161  			ObjectId:   "ba985f3d4fd347c3aee686fd749659fc",
   162  			ObjectName: "terraform_app",
   163  			ObjectType: "APP",
   164  			ThrottleId: "c481043838f64bcd82c7b0c38907d59d",
   165  		},
   166  	}
   167  
   168  	specThrottleUpdateOpts = &throttles.SpecThrottleUpdateOpts{
   169  		CallLimits: 30,
   170  	}
   171  )
   172  
   173  func handleV2ThrottlingPolicyCreate(t *testing.T) {
   174  	th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/throttles",
   175  		func(w http.ResponseWriter, r *http.Request) {
   176  			th.TestMethod(t, r, "POST")
   177  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   178  			w.Header().Add("Content-Type", "application/json")
   179  			w.WriteHeader(http.StatusCreated)
   180  			_, _ = fmt.Fprint(w, expectedCreateResponse)
   181  		})
   182  }
   183  
   184  func handleV2ThrottlingPolicyGet(t *testing.T) {
   185  	th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/throttles/c481043838f64bcd82c7b0c38907d59d",
   186  		func(w http.ResponseWriter, r *http.Request) {
   187  			th.TestMethod(t, r, "GET")
   188  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   189  			w.Header().Add("Content-Type", "application/json")
   190  			w.WriteHeader(http.StatusOK)
   191  			_, _ = fmt.Fprint(w, expectedCreateResponse)
   192  		})
   193  }
   194  
   195  func handleV2ThrottlingPolicyList(t *testing.T) {
   196  	th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/throttles", func(w http.ResponseWriter, r *http.Request) {
   197  		th.TestMethod(t, r, "GET")
   198  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   199  		w.Header().Add("Content-Type", "application/json")
   200  		w.WriteHeader(http.StatusOK)
   201  		_, _ = fmt.Fprint(w, expectedListResponse)
   202  	})
   203  }
   204  
   205  func handleV2ThrottlingPolicyUpdate(t *testing.T) {
   206  	th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/throttles/c481043838f64bcd82c7b0c38907d59d",
   207  		func(w http.ResponseWriter, r *http.Request) {
   208  			th.TestMethod(t, r, "PUT")
   209  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   210  			w.Header().Add("Content-Type", "application/json")
   211  			w.WriteHeader(http.StatusOK)
   212  			_, _ = fmt.Fprint(w, expectedCreateResponse)
   213  		})
   214  }
   215  
   216  func handleV2ThrottlingPolicyDelete(t *testing.T) {
   217  	th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/throttles/c481043838f64bcd82c7b0c38907d59d",
   218  		func(w http.ResponseWriter, r *http.Request) {
   219  			th.TestMethod(t, r, "DELETE")
   220  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   221  			w.Header().Add("Content-Type", "application/json")
   222  			w.WriteHeader(http.StatusNoContent)
   223  		})
   224  }
   225  
   226  func handleV2SpecThrottlingPolicyCreate(t *testing.T) {
   227  	th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/throttles/c481043838f64bcd82c7b0c38907d59d/"+
   228  		"throttle-specials",
   229  		func(w http.ResponseWriter, r *http.Request) {
   230  			th.TestMethod(t, r, "POST")
   231  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   232  			w.Header().Add("Content-Type", "application/json")
   233  			w.WriteHeader(http.StatusCreated)
   234  			_, _ = fmt.Fprint(w, expectedSpecCreateResponse)
   235  		})
   236  }
   237  
   238  func handleV2SpecThrottlingPolicyList(t *testing.T) {
   239  	th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/throttles/c481043838f64bcd82c7b0c38907d59d/"+
   240  		"throttle-specials",
   241  		func(w http.ResponseWriter, r *http.Request) {
   242  			th.TestMethod(t, r, "GET")
   243  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   244  			w.Header().Add("Content-Type", "application/json")
   245  			w.WriteHeader(http.StatusOK)
   246  			_, _ = fmt.Fprint(w, expectedSpecListResponse)
   247  		})
   248  }
   249  
   250  func handleV2SpecThrottlingPolicyUpdate(t *testing.T) {
   251  	th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/throttles/c481043838f64bcd82c7b0c38907d59d/"+
   252  		"throttle-specials/aec8d27e3e034f4293bc766942ed60fd",
   253  		func(w http.ResponseWriter, r *http.Request) {
   254  			th.TestMethod(t, r, "PUT")
   255  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   256  			w.Header().Add("Content-Type", "application/json")
   257  			w.WriteHeader(http.StatusOK)
   258  			_, _ = fmt.Fprint(w, expectedSpecCreateResponse)
   259  		})
   260  }
   261  
   262  func handleV2SpecThrottlingPolicyDelete(t *testing.T) {
   263  	th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/throttles/c481043838f64bcd82c7b0c38907d59d/"+
   264  		"throttle-specials/aec8d27e3e034f4293bc766942ed60fd",
   265  		func(w http.ResponseWriter, r *http.Request) {
   266  			th.TestMethod(t, r, "DELETE")
   267  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   268  			w.Header().Add("Content-Type", "application/json")
   269  			w.WriteHeader(http.StatusNoContent)
   270  		})
   271  }