github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/rts/v1/softwareconfig/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/softwareconfig"
     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 = &softwareconfig.SoftwareConfig{
    15  	Inputs: []map[string]interface{}{{"type": "String", "name": "foo"},
    16  		{"type": "String", "name": "bar"}},
    17  	Group:   "script",
    18  	Name:    "test-cong",
    19  	Outputs: []map[string]interface{}{{"type": "String", "name": "result", "error_output": "false"}},
    20  	Config:  "#!/bin/sh -x\necho \"Writing to /tmp/$bar\"\necho $foo > /tmp/$bar\necho -n \"The file /tmp/$bar contains cat /tmp/$bar for server $deploy_server_id during $deploy_action\" > $heat_outputs_path.result\necho \"Written to /tmp/$bar\"\necho \"Output to stderr\" 1>&2",
    21  	Id:      "e0be7e37-a581-4b24-bfb1-df4f3048c090",
    22  }
    23  
    24  // CreateOutput represents the response body from a Create request.
    25  const CreateOutput = `
    26  {
    27      "software_config": {
    28          "inputs": [
    29              {
    30                  "type": "String",
    31                  "name": "foo"
    32              },
    33              {
    34                  "type": "String",
    35                  "name": "bar"
    36              }
    37          ],
    38          "group": "script",
    39          "name": "test-cong",
    40          "outputs": [
    41              {
    42                  "type": "String",
    43                  "name": "result",
    44                  "error_output": "false"
    45              }
    46          ],
    47          "config": "#!/bin/sh -x\necho \"Writing to /tmp/$bar\"\necho $foo > /tmp/$bar\necho -n \"The file /tmp/$bar contains cat /tmp/$bar for server $deploy_server_id during $deploy_action\" > $heat_outputs_path.result\necho \"Written to /tmp/$bar\"\necho \"Output to stderr\" 1>&2",
    48          "id": "e0be7e37-a581-4b24-bfb1-df4f3048c090"
    49      }
    50  }`
    51  
    52  // HandleCreateSuccessfully creates an HTTP handler at `/stacks` on the test handler mux
    53  // that responds with a `Create` response.
    54  func HandleCreateSuccessfully(t *testing.T, output string) {
    55  	th.Mux.HandleFunc("/software_configs", func(w http.ResponseWriter, r *http.Request) {
    56  		th.TestMethod(t, r, "POST")
    57  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    58  		th.TestHeader(t, r, "Accept", "application/json")
    59  		w.WriteHeader(http.StatusOK)
    60  		fmt.Fprintf(w, output)
    61  	})
    62  }
    63  
    64  // ListExpected represents the expected object from a List request.
    65  var ListExpected = []softwareconfig.SoftwareConfig{
    66  	{
    67  		Group: "script",
    68  		Name:  "test-cong",
    69  		Id:    "e0be7e37-a581-4b24-bfb1-df4f3048c090",
    70  	},
    71  	{
    72  		Group: "script",
    73  		Name:  "test-cong1",
    74  		Id:    "743a15f6-9a55-49fe-80bb-a9188f39fc07",
    75  	},
    76  	{
    77  		Group: "script",
    78  		Name:  "a-config-we5zpvyu7b5o",
    79  		Id:    "a6ff3598-f2e0-4111-81b0-aa3e1cac2529",
    80  	},
    81  }
    82  
    83  // FullListOutput represents the response body from a List request without a marker.
    84  const FullListOutput = `
    85  {
    86      "software_configs": [
    87          {
    88              "group": "script",
    89              "id": "e0be7e37-a581-4b24-bfb1-df4f3048c090",
    90              "name": "test-cong"
    91          },
    92          {
    93              "group": "script",
    94              "id": "743a15f6-9a55-49fe-80bb-a9188f39fc07",
    95              "name": "test-cong1"
    96          },
    97          {
    98              "group": "script",
    99              "id": "a6ff3598-f2e0-4111-81b0-aa3e1cac2529",
   100              "name": "a-config-we5zpvyu7b5o"
   101          }
   102      ]
   103  }`
   104  
   105  // HandleListSuccessfully creates an HTTP handler at `/stacks` on the test handler mux
   106  // that responds with a `List` response.
   107  func HandleListSuccessfully(t *testing.T, output string) {
   108  	th.Mux.HandleFunc("/software_configs", func(w http.ResponseWriter, r *http.Request) {
   109  		th.TestMethod(t, r, "GET")
   110  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   111  		th.TestHeader(t, r, "Accept", "application/json")
   112  
   113  		w.Header().Set("Content-Type", "application/json")
   114  
   115  		w.WriteHeader(http.StatusOK)
   116  		fmt.Fprintf(w, output)
   117  		//r.ParseForm()
   118  	})
   119  }
   120  
   121  // GetExpected represents the expected object from a Get request.
   122  var GetExpected = &softwareconfig.SoftwareConfig{
   123  	Inputs: []map[string]interface{}{{"type": "String", "name": "foo"},
   124  		{"type": "String", "name": "bar"}},
   125  	Group:   "script",
   126  	Name:    "test-cong",
   127  	Outputs: []map[string]interface{}{{"type": "String", "name": "result", "error_output": "false"}},
   128  	Config:  "#!/bin/sh -x\necho \"Writing to /tmp/$bar\"\necho $foo > /tmp/$bar\necho -n \"The file /tmp/$bar contains cat /tmp/$bar for server $deploy_server_id during $deploy_action\" > $heat_outputs_path.result\necho \"Written to /tmp/$bar\"\necho \"Output to stderr\" 1>&2",
   129  	Id:      "e0be7e37-a581-4b24-bfb1-df4f3048c090",
   130  }
   131  
   132  // GetOutput represents the response body from a Get request.
   133  const GetOutput = `
   134  {
   135      "software_config": {
   136          "inputs": [
   137              {
   138                  "type": "String",
   139                  "name": "foo"
   140              },
   141              {
   142                  "type": "String",
   143                  "name": "bar"
   144              }
   145          ],
   146          "group": "script",
   147          "name": "test-cong",
   148          "outputs": [
   149              {
   150                  "type": "String",
   151                  "name": "result",
   152                  "error_output": "false"
   153              }
   154          ],
   155          "config": "#!/bin/sh -x\necho \"Writing to /tmp/$bar\"\necho $foo > /tmp/$bar\necho -n \"The file /tmp/$bar contains cat /tmp/$bar for server $deploy_server_id during $deploy_action\" > $heat_outputs_path.result\necho \"Written to /tmp/$bar\"\necho \"Output to stderr\" 1>&2",
   156          "id": "e0be7e37-a581-4b24-bfb1-df4f3048c090"
   157      }
   158  }`
   159  
   160  // HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   161  // on the test handler mux that responds with a `Get` response.
   162  func HandleGetSuccessfully(t *testing.T, output string) {
   163  	th.Mux.HandleFunc("/software_configs/e0be7e37-a581-4b24-bfb1-df4f3048c090", func(w http.ResponseWriter, r *http.Request) {
   164  		th.TestMethod(t, r, "GET")
   165  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   166  		th.TestHeader(t, r, "Accept", "application/json")
   167  
   168  		w.Header().Set("Content-Type", "application/json")
   169  		w.WriteHeader(http.StatusOK)
   170  		fmt.Fprintf(w, output)
   171  	})
   172  }
   173  
   174  // HandleDeleteSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   175  // on the test handler mux that responds with a `Delete` response.
   176  func HandleDeleteSuccessfully(t *testing.T) {
   177  	th.Mux.HandleFunc("/software_configs/e2fe5553-a481-4549-9d0f-e208de3d98d1", func(w http.ResponseWriter, r *http.Request) {
   178  		th.TestMethod(t, r, "DELETE")
   179  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   180  		th.TestHeader(t, r, "Accept", "application/json")
   181  
   182  		w.Header().Set("Content-Type", "application/json")
   183  		w.WriteHeader(http.StatusNoContent)
   184  	})
   185  }