github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dws/v1/cluster/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	th "github.com/chnsz/golangsdk/testhelper"
     9  	"github.com/chnsz/golangsdk/testhelper/client"
    10  )
    11  
    12  //mock response body string
    13  var (
    14  	mockListResponse = `
    15  {
    16      "clusters": [
    17          {
    18              "id": "7d85f602-a948-4a30-afd4-e84f47471c15",
    19              "status": "AVAILABLE",
    20              "sub_status": "READONLY",
    21              "task_status": "SNAPSHOTTING",
    22              "action_progress": {
    23                  "SNAPSHOTTING": "20%"
    24              },
    25              "node_type": "dws.d1.xlarge.ultrahigh",
    26              "subnet_id": "374eca02-cfc4-4de7-8ab5-dbebf7d9a720",
    27              "security_group_id": "dc3ec145-9029-4b39-b5a3-ace5a01f772b",
    28              "number_of_node": 3,
    29              "availability_zone": "cn-north-4b",
    30              "port": 8000,
    31              "name": "dws-1",
    32              "version": "1.2.0",
    33              "vpc_id": "85b20d7e-9eb7-4b2a-98f3-3c8843ea3574",
    34              "user_name": "dbadmin",
    35              "public_ip": {
    36                  "public_bind_type": "auto_assign",
    37                  "eip_id": "85b20d7e-9eb7-4b2a-98f3-3c8843ea3574"
    38              },
    39              "public_endpoints": [
    40                  {
    41                      "public_connect_info": "dws-1.cn-north-4.myhuaweicloud.com",
    42                      "jdbc_url": "jdbc:postgresql://dws-1.cn-north-4.myhuaweicloud.com/<YOUR_DATABASE_name>"
    43                  }
    44              ],
    45              "endpoints": [
    46                  {
    47                      "connect_info": "dws-1.cn-north-4.myhuaweicloud.com",
    48                      "jdbc_url": "jdbc:postgresql://dws-1.cn-north-4.myhuaweicloud.com/<YOUR_DATABASE_name>"
    49                  }
    50              ],
    51              "updated": "2016-02-10T14:28:14Z",
    52              "created": "2016-02-10T14:26:14Z",
    53              "enterprise_project_id": "aca4e50a-266f-4786-827c-f8d6cc3fbada",
    54              "recent_event": 6
    55          }
    56      ]
    57  }
    58  `
    59  
    60  	mockGetResponse = `
    61  {
    62      "cluster": {
    63          "id": "7d85f602-a948-4a30-afd4-e84f47471c15",
    64          "status": "AVAILABLE",
    65          "name": "dws-1",
    66          "updated": "2018-02-10T14:28:14Z",
    67          "created": "2018-02-10T14:28:14Z",
    68          "user_name": "dbadmin",
    69          "sub_status": "READONLY",
    70          "task_status": "SNAPSHOTTING",
    71          "action_progress": {
    72              "SNAPSHOTTING": "20%"
    73          },
    74          "node_type": "dws.m1.xlarge.ultrahigh",
    75          "subnet_id": "374eca02-cfc4-4de7-8ab5-dbebf7d9a720",
    76          "security_group_id": "dc3ec145-9029-4b39-b5a3-ace5a01f772b",
    77          "number_of_node": 3,
    78          "availability_zone": "cn-north-4b",
    79          "port": 8000,
    80          "vpc_id": "85b20d7e-9eb7-4b2a-98f3-3c8843ea3574",
    81          "public_ip": {
    82              "public_bind_type": "auto_assign",
    83              "eip_id": "85b20d7e-9etypeb2a-98f3-3c8843ea3574",
    84              "eip_address": "100.95.157.20"
    85          },
    86          "private_ip": [
    87              "192.168.0.12",
    88              "192.168.0.66"
    89          ],
    90          "public_endpoints": [
    91              {
    92                  "public_connect_info": "dws-1.cn-north-4.myhuaweicloud.com",
    93                  "jdbc_url": "jdbc:postgresql://dws-1.cn-north-4.myhuaweicloud.com/<YOUR_DATABASE_name>"
    94              }
    95          ],
    96          "endpoints": [
    97              {
    98                  "connect_info": "dws-1.cn-north-4.myhuaweicloud.com",
    99                  "jdbc_url": "jdbc:postgresql://dws-1.cn-north-4.myhuaweicloud.com/<YOUR_DATABASE_name>"
   100              }
   101          ],
   102          "version": "1.2.0",
   103          "maintain_window": {
   104              "day": "Wed",
   105              "start_time": "22:00",
   106              "end_time": "02:00"
   107          },
   108          "resize_info": {
   109              "target_node_num": 6,
   110              "origin_node_num": 3,
   111              "status": "GROWING",
   112              "start_time": "2018-02-14T14:28:14Z",
   113              "origin_node_type": "dws.m1.xlarge.ultrahigh",
   114              "target_node_type": "dws.d2.xlarge"
   115          },
   116          "enterprise_project_id": "6a6a18fe-417a-4188-9214-75fd08c22065",
   117          "recent_event": 6,
   118          "tags": [
   119              {
   120                  "key": "key1",
   121                  "value": "value1"
   122              },
   123              {
   124                  "key": "key2",
   125                  "value": "value2"
   126              }
   127          ],
   128          "parameter_group": {
   129              "id": "157e9cc4-64a8-11e8-adc0-fa7ae01bbebc",
   130              "name": "Default-Parameter-Group-dws ",
   131              "status": "In-Sync"
   132          }
   133      }
   134  }
   135  `
   136  	mockNodeTypeResponse = `
   137  {
   138      "node_types": [
   139          {
   140              "spec_name": "dws.d2.xlarge",
   141              "id": "ebe532d6-665f-40e6-a4d4-3c51545b6a67",
   142              "detail": [
   143                  {
   144                      "type": "vCPU",
   145                      "value": "4"
   146                  },
   147                  {
   148                      "value": "1675",
   149                      "type": "LOCAL_DISK",
   150                      "unit": "GB"
   151                  },
   152                  {
   153                      "type": "mem",
   154                      "value": "32",
   155                      "unit": "GB"
   156                  }
   157              ]
   158          },
   159          {
   160              "spec_name": "dws.m1.xlarge.ultrahigh",
   161              "id": "ebe532d6-665f-40e6-a4d4-3c51545b4f71",
   162              "detail": [
   163                  {
   164                      "type": "vCPU",
   165                      "value": "4"
   166                  },
   167                  {
   168                      "value": "512",
   169                      "type": "SSD",
   170                      "unit": "GB"
   171                  },
   172                  {
   173                      "type": "mem",
   174                      "value": "32",
   175                      "unit": "GB"
   176                  }
   177              ]
   178          }
   179      ]
   180  }
   181  `
   182  )
   183  
   184  func handleList(t *testing.T) {
   185  	th.Mux.HandleFunc("/clusters", func(w http.ResponseWriter, r *http.Request) {
   186  		th.TestMethod(t, r, "GET")
   187  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   188  		w.Header().Add("Content-Type", "application/json")
   189  		w.WriteHeader(http.StatusOK)
   190  		_, _ = fmt.Fprint(w, mockListResponse)
   191  	})
   192  }
   193  
   194  func handleGet(t *testing.T) {
   195  	th.Mux.HandleFunc("/clusters/7d85f602-a948-4a30-afd4-e84f47471c15", func(w http.ResponseWriter, r *http.Request) {
   196  		th.TestMethod(t, r, "GET")
   197  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   198  		w.Header().Add("Content-Type", "application/json")
   199  		w.WriteHeader(http.StatusOK)
   200  		_, _ = fmt.Fprint(w, mockGetResponse)
   201  	})
   202  }
   203  
   204  func handleNodeType(t *testing.T) {
   205  	th.Mux.HandleFunc("/node-types", func(w http.ResponseWriter, r *http.Request) {
   206  		th.TestMethod(t, r, "GET")
   207  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   208  		w.Header().Add("Content-Type", "application/json")
   209  		w.WriteHeader(http.StatusOK)
   210  		_, _ = fmt.Fprint(w, mockNodeTypeResponse)
   211  	})
   212  }