github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/v2/environments/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/environments"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  const (
    14  	expectedCreateResponse = `
    15  {
    16  	"create_time": "2021-06-22T12:11:28.18948645Z",
    17  	"id": "3585fce96a5d44f8b445121b9440274a",
    18  	"name": "terraform_test",
    19  	"remark": "Created by script"
    20  }`
    21  	expectedListResponse = `
    22  {
    23  	"envs": [
    24  		{
    25  			"create_time": "2020-10-14T16:15:19.417962Z",
    26  			"id": "DEFAULT_ENVIRONMENT_RELEASE_ID",
    27  			"name": "RELEASE",
    28  			"remark": "生产环境"
    29  		},
    30  		{
    31  			"create_time": "2021-06-22T11:40:18Z",
    32  			"id": "3585fce96a5d44f8b445121b9440274a",
    33  			"name": "terraform_test_update",
    34  			"remark": "Updated by script"
    35  		}
    36  	]
    37  }`
    38  	expectedUpdateResponse = `
    39  {
    40  	"create_time": "2021-06-22T11:40:18Z",
    41  	"id": "3585fce96a5d44f8b445121b9440274a",
    42  	"name": "terraform_test_update",
    43  	"remark": "Updated by script"
    44  }`
    45  
    46  	expectedCreateVariableResponse = `
    47  {
    48  	"env_id": "3585fce96a5d44f8b445121b9440274a",
    49  	"group_id": "bd7c9608c05e4e93a6b44e47f19b6bed",
    50  	"id": "2dc48632332f4157804175175e71e3e8",
    51  	"variable_name": "Path",
    52  	"variable_value": "/stage/test"
    53  }`
    54  
    55  	expectedListVariablesResponse = `
    56  {
    57  	"variables": [
    58  		{
    59  			"env_id": "3585fce96a5d44f8b445121b9440274a",
    60  			"group_id": "bd7c9608c05e4e93a6b44e47f19b6bed",
    61  			"id": "2dc48632332f4157804175175e71e3e8",
    62  			"variable_name": "Path",
    63  			"variable_value": "/stage/test"
    64  		}
    65  	]
    66  }`
    67  )
    68  
    69  var (
    70  	createDesc = "Updated by script"
    71  	createOpts = &environments.EnvironmentOpts{
    72  		Name:        "terraform_test",
    73  		Description: &createDesc,
    74  	}
    75  
    76  	expectedCreateResponseData = &environments.Environment{
    77  		Id:          "3585fce96a5d44f8b445121b9440274a",
    78  		Name:        "terraform_test",
    79  		Description: "Created by script",
    80  		CreateTime:  "2021-06-22T12:11:28.18948645Z",
    81  	}
    82  
    83  	updateDesc = "Updated by script"
    84  	updateOpts = &environments.EnvironmentOpts{
    85  		Name:        "terraform_test",
    86  		Description: &updateDesc,
    87  	}
    88  
    89  	expectedUpdateResponseData = &environments.Environment{
    90  		Id:          "3585fce96a5d44f8b445121b9440274a",
    91  		Name:        "terraform_test_update",
    92  		Description: "Updated by script",
    93  		CreateTime:  "2021-06-22T11:40:18Z",
    94  	}
    95  
    96  	expectedListResponseData = []environments.Environment{
    97  		{
    98  			CreateTime:  "2020-10-14T16:15:19.417962Z",
    99  			Id:          "DEFAULT_ENVIRONMENT_RELEASE_ID",
   100  			Name:        "RELEASE",
   101  			Description: "生产环境",
   102  		},
   103  		{
   104  			CreateTime:  "2021-06-22T11:40:18Z",
   105  			Id:          "3585fce96a5d44f8b445121b9440274a",
   106  			Name:        "terraform_test_update",
   107  			Description: "Updated by script",
   108  		},
   109  	}
   110  
   111  	variableCreateOpts = &environments.CreateVariableOpts{
   112  		EnvId:   "3585fce96a5d44f8b445121b9440274a",
   113  		GroupId: "bd7c9608c05e4e93a6b44e47f19b6bed",
   114  		Name:    "Path",
   115  		Value:   "/stage/test",
   116  	}
   117  
   118  	expectedCreateVariableResponseData = &environments.Variable{
   119  		EnvId:   "3585fce96a5d44f8b445121b9440274a",
   120  		GroupId: "bd7c9608c05e4e93a6b44e47f19b6bed",
   121  		Name:    "Path",
   122  		Value:   "/stage/test",
   123  		Id:      "2dc48632332f4157804175175e71e3e8",
   124  	}
   125  
   126  	expectedListVariableResponseData = []environments.Variable{
   127  		{
   128  			EnvId:   "3585fce96a5d44f8b445121b9440274a",
   129  			GroupId: "bd7c9608c05e4e93a6b44e47f19b6bed",
   130  			Name:    "Path",
   131  			Value:   "/stage/test",
   132  			Id:      "2dc48632332f4157804175175e71e3e8",
   133  		},
   134  	}
   135  )
   136  
   137  func handleV2EnvironmentCreate(t *testing.T) {
   138  	th.Mux.HandleFunc("/instances/cc4ea721cc6747f7969e06bd21121c52/envs",
   139  		func(w http.ResponseWriter, r *http.Request) {
   140  			th.TestMethod(t, r, "POST")
   141  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   142  			w.Header().Add("Content-Type", "application/json")
   143  			w.WriteHeader(http.StatusAccepted)
   144  			_, _ = fmt.Fprint(w, expectedCreateResponse)
   145  		})
   146  }
   147  
   148  func handleV2EnvironmentList(t *testing.T) {
   149  	th.Mux.HandleFunc("/instances/cc4ea721cc6747f7969e06bd21121c52/envs",
   150  		func(w http.ResponseWriter, r *http.Request) {
   151  			th.TestMethod(t, r, "GET")
   152  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   153  			w.Header().Add("Content-Type", "application/json")
   154  			w.WriteHeader(http.StatusOK)
   155  			_, _ = fmt.Fprint(w, expectedListResponse)
   156  		})
   157  }
   158  
   159  func handleV2EnvironmentUpdate(t *testing.T) {
   160  	th.Mux.HandleFunc("/instances/cc4ea721cc6747f7969e06bd21121c52/envs/3585fce96a5d44f8b445121b9440274a",
   161  		func(w http.ResponseWriter, r *http.Request) {
   162  			th.TestMethod(t, r, "PUT")
   163  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   164  			w.Header().Add("Content-Type", "application/json")
   165  			w.WriteHeader(http.StatusOK)
   166  			_, _ = fmt.Fprint(w, expectedUpdateResponse)
   167  		})
   168  }
   169  
   170  func handleV2EnvironmentDelete(t *testing.T) {
   171  	th.Mux.HandleFunc("/instances/cc4ea721cc6747f7969e06bd21121c52/envs/3585fce96a5d44f8b445121b9440274a",
   172  		func(w http.ResponseWriter, r *http.Request) {
   173  			th.TestMethod(t, r, "DELETE")
   174  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   175  			w.Header().Add("Content-Type", "application/json")
   176  			w.WriteHeader(http.StatusNoContent)
   177  		})
   178  }
   179  
   180  func handleV2EnvironmentVariableCreate(t *testing.T) {
   181  	th.Mux.HandleFunc("/instances/cc4ea721cc6747f7969e06bd21121c52/env-variables",
   182  		func(w http.ResponseWriter, r *http.Request) {
   183  			th.TestMethod(t, r, "POST")
   184  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   185  			w.Header().Add("Content-Type", "application/json")
   186  			w.WriteHeader(http.StatusCreated)
   187  			_, _ = fmt.Fprint(w, expectedCreateVariableResponse)
   188  		})
   189  }
   190  
   191  func handleV2EnvironmentVariableGet(t *testing.T) {
   192  	th.Mux.HandleFunc("/instances/cc4ea721cc6747f7969e06bd21121c52/env-variables"+
   193  		"/2dc48632332f4157804175175e71e3e8", func(w http.ResponseWriter, r *http.Request) {
   194  		th.TestMethod(t, r, "GET")
   195  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   196  		w.Header().Add("Content-Type", "application/json")
   197  		w.WriteHeader(http.StatusOK)
   198  		_, _ = fmt.Fprint(w, expectedCreateVariableResponse)
   199  	})
   200  }
   201  
   202  func handleV2EnvironmentVariableList(t *testing.T) {
   203  	th.Mux.HandleFunc("/instances/cc4ea721cc6747f7969e06bd21121c52/env-variables",
   204  		func(w http.ResponseWriter, r *http.Request) {
   205  			th.TestMethod(t, r, "GET")
   206  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   207  			w.Header().Add("Content-Type", "application/json")
   208  			w.WriteHeader(http.StatusOK)
   209  			_, _ = fmt.Fprint(w, expectedListVariablesResponse)
   210  		})
   211  }
   212  
   213  func handleV2EnvironmentVariableDelete(t *testing.T) {
   214  	th.Mux.HandleFunc("/instances/cc4ea721cc6747f7969e06bd21121c52/env-variables"+
   215  		"/2dc48632332f4157804175175e71e3e8", func(w http.ResponseWriter, r *http.Request) {
   216  		th.TestMethod(t, r, "DELETE")
   217  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   218  		w.Header().Add("Content-Type", "application/json")
   219  		w.WriteHeader(http.StatusNoContent)
   220  	})
   221  }