github.com/gophercloud/gophercloud@v1.11.0/openstack/orchestration/v1/stacktemplates/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacktemplates"
     9  	th "github.com/gophercloud/gophercloud/testhelper"
    10  	fake "github.com/gophercloud/gophercloud/testhelper/client"
    11  )
    12  
    13  // GetExpected represents the expected object from a Get request.
    14  var GetExpected = "{\n  \"description\": \"Simple template to test heat commands\",\n  \"heat_template_version\": \"2013-05-23\",\n  \"parameters\": {\n    \"flavor\": {\n      \"default\": \"m1.tiny\",\n      \"type\": \"string\"\n    }\n  },\n  \"resources\": {\n    \"hello_world\": {\n      \"properties\": {\n        \"flavor\": {\n          \"get_param\": \"flavor\"\n        },\n        \"image\": \"ad091b52-742f-469e-8f3c-fd81cadf0743\",\n        \"key_name\": \"heat_key\"\n      },\n      \"type\": \"OS::Nova::Server\"\n    }\n  }\n}"
    15  
    16  // GetOutput represents the response body from a Get request.
    17  const GetOutput = `
    18  {
    19    "heat_template_version": "2013-05-23",
    20    "description": "Simple template to test heat commands",
    21    "parameters": {
    22      "flavor": {
    23        "default": "m1.tiny",
    24        "type": "string"
    25      }
    26    },
    27    "resources": {
    28      "hello_world": {
    29        "type": "OS::Nova::Server",
    30        "properties": {
    31          "key_name": "heat_key",
    32          "flavor": {
    33            "get_param": "flavor"
    34          },
    35          "image": "ad091b52-742f-469e-8f3c-fd81cadf0743"
    36        }
    37      }
    38    }
    39  }`
    40  
    41  // HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/template`
    42  // on the test handler mux that responds with a `Get` response.
    43  func HandleGetSuccessfully(t *testing.T, output string) {
    44  	th.Mux.HandleFunc("/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/template", func(w http.ResponseWriter, r *http.Request) {
    45  		th.TestMethod(t, r, "GET")
    46  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    47  		th.TestHeader(t, r, "Accept", "application/json")
    48  
    49  		w.Header().Set("Content-Type", "application/json")
    50  		w.WriteHeader(http.StatusOK)
    51  		fmt.Fprintf(w, output)
    52  	})
    53  }
    54  
    55  // ValidateExpected represents the expected object from a Validate request.
    56  var ValidateExpected = &stacktemplates.ValidatedTemplate{
    57  	Description: "Simple template to test heat commands",
    58  	Parameters: map[string]interface{}{
    59  		"flavor": map[string]interface{}{
    60  			"Default":     "m1.tiny",
    61  			"Type":        "String",
    62  			"NoEcho":      "false",
    63  			"Description": "",
    64  			"Label":       "flavor",
    65  		},
    66  	},
    67  }
    68  
    69  // ValidateOutput represents the response body from a Validate request.
    70  const ValidateOutput = `
    71  {
    72  	"Description": "Simple template to test heat commands",
    73  	"Parameters": {
    74  		"flavor": {
    75  			"Default": "m1.tiny",
    76  			"Type": "String",
    77  			"NoEcho": "false",
    78  			"Description": "",
    79  			"Label": "flavor"
    80  		}
    81  	}
    82  }`
    83  
    84  // HandleValidateSuccessfully creates an HTTP handler at `/validate`
    85  // on the test handler mux that responds with a `Validate` response.
    86  func HandleValidateSuccessfully(t *testing.T, output string) {
    87  	th.Mux.HandleFunc("/validate", func(w http.ResponseWriter, r *http.Request) {
    88  		th.TestMethod(t, r, "POST")
    89  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    90  		th.TestHeader(t, r, "Accept", "application/json")
    91  
    92  		w.Header().Set("Content-Type", "application/json")
    93  		w.WriteHeader(http.StatusOK)
    94  		fmt.Fprintf(w, output)
    95  	})
    96  }