github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/rts/v1/softwaredeployment/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/huaweicloud/golangsdk/openstack/rts/v1/softwaredeployment"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	fake "github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  // CreateExpected represents the expected object from a Create request.
    14  var CreateExpected = &softwaredeployment.Deployment{
    15  	Id:           "43489279-7b12-4fc5-90ed-320f29e89419",
    16  	ConfigId:     "69070672-d37d-4095-a19c-52ab1fde9a24",
    17  	ServerId:     "a161a111-03a0-4204-b5c9-5df46587df5e",
    18  	Status:       "IN_PROGRESS",
    19  	Action:       "CREATE",
    20  	StatusReason: "Deploy data available",
    21  }
    22  
    23  // CreateOutput represents the response body from a Create request.
    24  const CreateOutput = `
    25  {
    26      "software_deployment": {
    27          "status": "IN_PROGRESS",
    28          "server_id": "a161a111-03a0-4204-b5c9-5df46587df5e",
    29          "config_id": "69070672-d37d-4095-a19c-52ab1fde9a24",
    30          "action": "CREATE",
    31          "status_reason": "Deploy data available",
    32          "id": "43489279-7b12-4fc5-90ed-320f29e89419"
    33      }
    34  }`
    35  
    36  // HandleCreateSuccessfully creates an HTTP handler at `/stacks` on the test handler mux
    37  // that responds with a `Create` response.
    38  func HandleCreateSuccessfully(t *testing.T, output string) {
    39  	th.Mux.HandleFunc("/software_deployments", func(w http.ResponseWriter, r *http.Request) {
    40  		th.TestMethod(t, r, "POST")
    41  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    42  		th.TestHeader(t, r, "Accept", "application/json")
    43  		w.WriteHeader(http.StatusOK)
    44  		fmt.Fprintf(w, output)
    45  	})
    46  }
    47  
    48  // CreateExpected represents the expected object from a Create request.
    49  var ListExpected = []softwaredeployment.Deployment{
    50  	{
    51  		Id:           "b357fbe9-4af8-4d00-9499-a13f0d0150bb",
    52  		ConfigId:     "a6ff3598-f2e0-4111-81b0-aa3e1cac2529",
    53  		ServerId:     "e4b191b0-b80b-4782-994c-02abb094480e",
    54  		Status:       "IN_PROGRESS",
    55  		Action:       "CREATE",
    56  		StatusReason: "Deploy data available",
    57  	},
    58  	{
    59  		Id:           "43489279-7b12-4fc5-90ed-320f29e89419",
    60  		ConfigId:     "69070672-d37d-4095-a19c-52ab1fde9a24",
    61  		ServerId:     "a161a111-03a0-4204-b5c9-5df46587df5e",
    62  		Status:       "IN_PROGRESS",
    63  		Action:       "CREATE",
    64  		StatusReason: "Deploy data available",
    65  	},
    66  }
    67  
    68  // CreateOutput represents the response body from a Create request.
    69  const ListOutput = `
    70  {
    71      "software_deployments": [
    72          {
    73              "status": "IN_PROGRESS",
    74              "server_id": "e4b191b0-b80b-4782-994c-02abb094480e",
    75              "config_id": "a6ff3598-f2e0-4111-81b0-aa3e1cac2529",
    76              "action": "CREATE",
    77              "status_reason": "Deploy data available",
    78              "id": "b357fbe9-4af8-4d00-9499-a13f0d0150bb"
    79          },
    80          {
    81              "status": "IN_PROGRESS",
    82  			"server_id": "a161a111-03a0-4204-b5c9-5df46587df5e",
    83  			"config_id": "69070672-d37d-4095-a19c-52ab1fde9a24",
    84  			"action": "CREATE",
    85  			"status_reason": "Deploy data available",
    86  			"id": "43489279-7b12-4fc5-90ed-320f29e89419"
    87          }
    88           ]
    89  }`
    90  
    91  func HandleListSuccessfully(t *testing.T, output string) {
    92  	th.Mux.HandleFunc("/software_deployments", func(w http.ResponseWriter, r *http.Request) {
    93  		th.TestMethod(t, r, "GET")
    94  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    95  		th.TestHeader(t, r, "Accept", "application/json")
    96  
    97  		w.Header().Set("Content-Type", "application/json")
    98  
    99  		w.WriteHeader(http.StatusOK)
   100  		fmt.Fprintf(w, output)
   101  		//r.ParseForm()
   102  	})
   103  }
   104  
   105  // GetExpected represents the expected object from a Get request.
   106  var GetExpected = &softwaredeployment.Deployment{
   107  	Id:           "43489279-7b12-4fc5-90ed-320f29e89419",
   108  	ConfigId:     "69070672-d37d-4095-a19c-52ab1fde9a24",
   109  	ServerId:     "a161a111-03a0-4204-b5c9-5df46587df5e",
   110  	Status:       "IN_PROGRESS",
   111  	Action:       "CREATE",
   112  	StatusReason: "Deploy data available",
   113  }
   114  
   115  // GetOutput represents the response body from a Get request.
   116  const GetOutput = `
   117  {
   118      "software_deployment": {
   119          "status": "IN_PROGRESS",
   120          "server_id": "a161a111-03a0-4204-b5c9-5df46587df5e",
   121          "config_id": "69070672-d37d-4095-a19c-52ab1fde9a24",
   122          "action": "CREATE",
   123          "status_reason": "Deploy data available",
   124          "id": "43489279-7b12-4fc5-90ed-320f29e89419"
   125      }
   126  }`
   127  
   128  // HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   129  // on the test handler mux that responds with a `Get` response.
   130  func HandleGetSuccessfully(t *testing.T, output string) {
   131  	th.Mux.HandleFunc("/software_deployments/43489279-7b12-4fc5-90ed-320f29e89419", func(w http.ResponseWriter, r *http.Request) {
   132  		th.TestMethod(t, r, "GET")
   133  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   134  		th.TestHeader(t, r, "Accept", "application/json")
   135  
   136  		w.Header().Set("Content-Type", "application/json")
   137  		w.WriteHeader(http.StatusOK)
   138  		fmt.Fprintf(w, output)
   139  	})
   140  }
   141  
   142  // GetExpected represents the expected object from a Get request.
   143  var UpdateExpected = &softwaredeployment.Deployment{
   144  	Id:           "43489279-7b12-4fc5-90ed-320f29e89419",
   145  	ConfigId:     "69070672-d37d-4095-a19c-52ab1fde9a24",
   146  	ServerId:     "a161a111-03a0-4204-b5c9-5df46587df5e",
   147  	Status:       "COMPLETE",
   148  	Action:       "CREATE",
   149  	StatusReason: "Outputs received",
   150  	OutputValues: map[string]interface{}{"deploy_stdout": "Writing to /tmp/baaaaa\nWritten to /tmp/baaaaa\n", "deploy_stderr": "+ echo Writing to /tmp/baaaaa\n+ echo fooooo\n+ cat /tmp/baaaaa\n+ echo -n The file /tmp/baaaaa contains fooooo for server ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5 during CREATE\n+ echo Written to /tmp/baaaaa\n+ echo Output to stderr\nOutput to stderr\n",
   151  		"deploy_status_code": "0", "result": "The file /tmp/baaaaa contains fooooo for server ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5 during CREATE"},
   152  }
   153  
   154  // GetOutput represents the response body from a Get request.
   155  const UpdateOutput = `
   156  {
   157      "software_deployment": {
   158          "status": "COMPLETE",
   159          "server_id": "a161a111-03a0-4204-b5c9-5df46587df5e",
   160          "config_id": "69070672-d37d-4095-a19c-52ab1fde9a24",
   161          "output_values": {
   162              "deploy_stdout": "Writing to /tmp/baaaaa\nWritten to /tmp/baaaaa\n",
   163              "deploy_stderr": "+ echo Writing to /tmp/baaaaa\n+ echo fooooo\n+ cat /tmp/baaaaa\n+ echo -n The file /tmp/baaaaa contains fooooo for server ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5 during CREATE\n+ echo Written to /tmp/baaaaa\n+ echo Output to stderr\nOutput to stderr\n",
   164              "deploy_status_code": "0",
   165              "result": "The file /tmp/baaaaa contains fooooo for server ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5 during CREATE"
   166          },
   167          "action": "CREATE",
   168          "status_reason": "Outputs received",
   169          "id": "43489279-7b12-4fc5-90ed-320f29e89419"
   170      }
   171  }`
   172  
   173  // HandleUpdateSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   174  // on the test handler mux that responds with a `Get` response.
   175  func HandleUpdateSuccessfully(t *testing.T, output string) {
   176  	th.Mux.HandleFunc("/software_deployments/43489279-7b12-4fc5-90ed-320f29e89419", func(w http.ResponseWriter, r *http.Request) {
   177  		th.TestMethod(t, r, "PUT")
   178  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   179  		th.TestHeader(t, r, "Accept", "application/json")
   180  
   181  		w.Header().Set("Content-Type", "application/json")
   182  		w.WriteHeader(http.StatusOK)
   183  		fmt.Fprintf(w, output)
   184  	})
   185  }
   186  
   187  // HandleDeleteSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   188  // on the test handler mux that responds with a `Delete` response.
   189  func HandleDeleteSuccessfully(t *testing.T) {
   190  	th.Mux.HandleFunc("/software_deployments/43489279-7b12-4fc5-90ed-320f29e89419", func(w http.ResponseWriter, r *http.Request) {
   191  		th.TestMethod(t, r, "DELETE")
   192  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   193  		th.TestHeader(t, r, "Accept", "application/json")
   194  
   195  		w.Header().Set("Content-Type", "application/json")
   196  		w.WriteHeader(http.StatusNoContent)
   197  	})
   198  }