github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/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/opentelekomcloud/gophertelekomcloud/openstack/rts/v1/softwaredeployment"
     9  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    10  	fake "github.com/opentelekomcloud/gophertelekomcloud/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.Fprint(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.Fprint(w, output)
   101  	})
   102  }
   103  
   104  // GetExpected represents the expected object from a Get request.
   105  var GetExpected = &softwaredeployment.Deployment{
   106  	Id:           "43489279-7b12-4fc5-90ed-320f29e89419",
   107  	ConfigId:     "69070672-d37d-4095-a19c-52ab1fde9a24",
   108  	ServerId:     "a161a111-03a0-4204-b5c9-5df46587df5e",
   109  	Status:       "IN_PROGRESS",
   110  	Action:       "CREATE",
   111  	StatusReason: "Deploy data available",
   112  }
   113  
   114  // GetOutput represents the response body from a Get request.
   115  const GetOutput = `
   116  {
   117      "software_deployment": {
   118          "status": "IN_PROGRESS",
   119          "server_id": "a161a111-03a0-4204-b5c9-5df46587df5e",
   120          "config_id": "69070672-d37d-4095-a19c-52ab1fde9a24",
   121          "action": "CREATE",
   122          "status_reason": "Deploy data available",
   123          "id": "43489279-7b12-4fc5-90ed-320f29e89419"
   124      }
   125  }`
   126  
   127  // HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   128  // on the test handler mux that responds with a `Get` response.
   129  func HandleGetSuccessfully(t *testing.T, output string) {
   130  	th.Mux.HandleFunc("/software_deployments/43489279-7b12-4fc5-90ed-320f29e89419", func(w http.ResponseWriter, r *http.Request) {
   131  		th.TestMethod(t, r, "GET")
   132  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   133  		th.TestHeader(t, r, "Accept", "application/json")
   134  
   135  		w.Header().Set("Content-Type", "application/json")
   136  		w.WriteHeader(http.StatusOK)
   137  		_, _ = fmt.Fprint(w, output)
   138  	})
   139  }
   140  
   141  // GetExpected represents the expected object from a Get request.
   142  var UpdateExpected = &softwaredeployment.Deployment{
   143  	Id:           "43489279-7b12-4fc5-90ed-320f29e89419",
   144  	ConfigId:     "69070672-d37d-4095-a19c-52ab1fde9a24",
   145  	ServerId:     "a161a111-03a0-4204-b5c9-5df46587df5e",
   146  	Status:       "COMPLETE",
   147  	Action:       "CREATE",
   148  	StatusReason: "Outputs received",
   149  	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",
   150  		"deploy_status_code": "0", "result": "The file /tmp/baaaaa contains fooooo for server ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5 during CREATE"},
   151  }
   152  
   153  // GetOutput represents the response body from a Get request.
   154  const UpdateOutput = `
   155  {
   156      "software_deployment": {
   157          "status": "COMPLETE",
   158          "server_id": "a161a111-03a0-4204-b5c9-5df46587df5e",
   159          "config_id": "69070672-d37d-4095-a19c-52ab1fde9a24",
   160          "output_values": {
   161              "deploy_stdout": "Writing to /tmp/baaaaa\nWritten to /tmp/baaaaa\n",
   162              "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",
   163              "deploy_status_code": "0",
   164              "result": "The file /tmp/baaaaa contains fooooo for server ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5 during CREATE"
   165          },
   166          "action": "CREATE",
   167          "status_reason": "Outputs received",
   168          "id": "43489279-7b12-4fc5-90ed-320f29e89419"
   169      }
   170  }`
   171  
   172  // HandleUpdateSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   173  // on the test handler mux that responds with a `Get` response.
   174  func HandleUpdateSuccessfully(t *testing.T, output string) {
   175  	th.Mux.HandleFunc("/software_deployments/43489279-7b12-4fc5-90ed-320f29e89419", func(w http.ResponseWriter, r *http.Request) {
   176  		th.TestMethod(t, r, "PUT")
   177  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   178  		th.TestHeader(t, r, "Accept", "application/json")
   179  
   180  		w.Header().Set("Content-Type", "application/json")
   181  		w.WriteHeader(http.StatusOK)
   182  		_, _ = fmt.Fprint(w, output)
   183  	})
   184  }
   185  
   186  // HandleDeleteSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   187  // on the test handler mux that responds with a `Delete` response.
   188  func HandleDeleteSuccessfully(t *testing.T) {
   189  	th.Mux.HandleFunc("/software_deployments/43489279-7b12-4fc5-90ed-320f29e89419", func(w http.ResponseWriter, r *http.Request) {
   190  		th.TestMethod(t, r, "DELETE")
   191  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   192  		th.TestHeader(t, r, "Accept", "application/json")
   193  
   194  		w.Header().Set("Content-Type", "application/json")
   195  		w.WriteHeader(http.StatusNoContent)
   196  	})
   197  }