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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/gophercloud/gophercloud"
    10  	"github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks"
    11  	th "github.com/gophercloud/gophercloud/testhelper"
    12  	fake "github.com/gophercloud/gophercloud/testhelper/client"
    13  )
    14  
    15  var Create_time, _ = time.Parse(time.RFC3339, "2018-06-26T07:58:17Z")
    16  var Updated_time, _ = time.Parse(time.RFC3339, "2018-06-26T07:59:17Z")
    17  
    18  // CreateExpected represents the expected object from a Create request.
    19  var CreateExpected = &stacks.CreatedStack{
    20  	ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
    21  	Links: []gophercloud.Link{
    22  		{
    23  			Href: "http://168.28.170.117:8004/v1/98606384f58drad0bhdb7d02779549ac/stacks/stackcreated/16ef0584-4458-41eb-87c8-0dc8d5f66c87",
    24  			Rel:  "self",
    25  		},
    26  	},
    27  }
    28  
    29  // CreateOutput represents the response body from a Create request.
    30  const CreateOutput = `
    31  {
    32    "stack": {
    33      "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
    34      "links": [
    35      {
    36        "href": "http://168.28.170.117:8004/v1/98606384f58drad0bhdb7d02779549ac/stacks/stackcreated/16ef0584-4458-41eb-87c8-0dc8d5f66c87",
    37        "rel": "self"
    38      }
    39      ]
    40    }
    41  }`
    42  
    43  // HandleCreateSuccessfully creates an HTTP handler at `/stacks` on the test handler mux
    44  // that responds with a `Create` response.
    45  func HandleCreateSuccessfully(t *testing.T, output string) {
    46  	th.Mux.HandleFunc("/stacks", func(w http.ResponseWriter, r *http.Request) {
    47  		th.TestMethod(t, r, "POST")
    48  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    49  		th.TestHeader(t, r, "Accept", "application/json")
    50  		w.WriteHeader(http.StatusCreated)
    51  		fmt.Fprintf(w, output)
    52  	})
    53  }
    54  
    55  // ListExpected represents the expected object from a List request.
    56  var ListExpected = []stacks.ListedStack{
    57  	{
    58  		Description: "Simple template to test heat commands",
    59  		Links: []gophercloud.Link{
    60  			{
    61  				Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87",
    62  				Rel:  "self",
    63  			},
    64  		},
    65  		StatusReason: "Stack CREATE completed successfully",
    66  		Name:         "postman_stack",
    67  		CreationTime: Create_time,
    68  		Status:       "CREATE_COMPLETE",
    69  		ID:           "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
    70  		Tags:         []string{"rackspace", "atx"},
    71  	},
    72  	{
    73  		Description: "Simple template to test heat commands",
    74  		Links: []gophercloud.Link{
    75  			{
    76  				Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada",
    77  				Rel:  "self",
    78  			},
    79  		},
    80  		StatusReason: "Stack successfully updated",
    81  		Name:         "gophercloud-test-stack-2",
    82  		CreationTime: Create_time,
    83  		UpdatedTime:  Updated_time,
    84  		Status:       "UPDATE_COMPLETE",
    85  		ID:           "db6977b2-27aa-4775-9ae7-6213212d4ada",
    86  		Tags:         []string{"sfo", "satx"},
    87  	},
    88  }
    89  
    90  // FullListOutput represents the response body from a List request without a marker.
    91  const FullListOutput = `
    92  {
    93    "stacks": [
    94    {
    95      "description": "Simple template to test heat commands",
    96      "links": [
    97      {
    98        "href": "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87",
    99        "rel": "self"
   100      }
   101      ],
   102      "stack_status_reason": "Stack CREATE completed successfully",
   103      "stack_name": "postman_stack",
   104      "creation_time": "2018-06-26T07:58:17Z",
   105      "updated_time": null,
   106      "stack_status": "CREATE_COMPLETE",
   107      "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   108  	"tags": ["rackspace", "atx"]
   109    },
   110    {
   111      "description": "Simple template to test heat commands",
   112      "links": [
   113      {
   114        "href": "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada",
   115        "rel": "self"
   116      }
   117      ],
   118      "stack_status_reason": "Stack successfully updated",
   119      "stack_name": "gophercloud-test-stack-2",
   120      "creation_time": "2018-06-26T07:58:17Z",
   121      "updated_time": "2018-06-26T07:59:17Z",
   122      "stack_status": "UPDATE_COMPLETE",
   123      "id": "db6977b2-27aa-4775-9ae7-6213212d4ada",
   124  	"tags": ["sfo", "satx"]
   125    }
   126    ]
   127  }
   128  `
   129  
   130  // HandleListSuccessfully creates an HTTP handler at `/stacks` on the test handler mux
   131  // that responds with a `List` response.
   132  func HandleListSuccessfully(t *testing.T, output string) {
   133  	th.Mux.HandleFunc("/stacks", func(w http.ResponseWriter, r *http.Request) {
   134  		th.TestMethod(t, r, "GET")
   135  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   136  		th.TestHeader(t, r, "Accept", "application/json")
   137  
   138  		w.Header().Set("Content-Type", "application/json")
   139  		r.ParseForm()
   140  		marker := r.Form.Get("marker")
   141  		switch marker {
   142  		case "":
   143  			fmt.Fprintf(w, output)
   144  		case "db6977b2-27aa-4775-9ae7-6213212d4ada":
   145  			fmt.Fprintf(w, `[]`)
   146  		default:
   147  			t.Fatalf("Unexpected marker: [%s]", marker)
   148  		}
   149  	})
   150  }
   151  
   152  // GetExpected represents the expected object from a Get request.
   153  var GetExpected = &stacks.RetrievedStack{
   154  	DisableRollback: true,
   155  	Description:     "Simple template to test heat commands",
   156  	Parameters: map[string]string{
   157  		"flavor":         "m1.tiny",
   158  		"OS::stack_name": "postman_stack",
   159  		"OS::stack_id":   "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   160  	},
   161  	StatusReason: "Stack CREATE completed successfully",
   162  	Name:         "postman_stack",
   163  	Outputs:      []map[string]interface{}{},
   164  	CreationTime: Create_time,
   165  	Links: []gophercloud.Link{
   166  		{
   167  			Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   168  			Rel:  "self",
   169  		},
   170  	},
   171  	Capabilities:        []interface{}{},
   172  	NotificationTopics:  []interface{}{},
   173  	Status:              "CREATE_COMPLETE",
   174  	ID:                  "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   175  	TemplateDescription: "Simple template to test heat commands",
   176  	Tags:                []string{"rackspace", "atx"},
   177  }
   178  
   179  // GetOutput represents the response body from a Get request.
   180  const GetOutput = `
   181  {
   182    "stack": {
   183      "disable_rollback": true,
   184      "description": "Simple template to test heat commands",
   185      "parameters": {
   186        "flavor": "m1.tiny",
   187        "OS::stack_name": "postman_stack",
   188        "OS::stack_id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87"
   189      },
   190      "stack_status_reason": "Stack CREATE completed successfully",
   191      "stack_name": "postman_stack",
   192      "outputs": [],
   193      "creation_time": "2018-06-26T07:58:17Z",
   194      "links": [
   195      {
   196        "href": "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   197        "rel": "self"
   198      }
   199      ],
   200      "capabilities": [],
   201      "notification_topics": [],
   202      "timeout_mins": null,
   203      "stack_status": "CREATE_COMPLETE",
   204      "updated_time": null,
   205      "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   206      "template_description": "Simple template to test heat commands",
   207  	"tags": ["rackspace", "atx"]
   208    }
   209  }
   210  `
   211  
   212  // HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   213  // on the test handler mux that responds with a `Get` response.
   214  func HandleGetSuccessfully(t *testing.T, output string) {
   215  	th.Mux.HandleFunc("/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", func(w http.ResponseWriter, r *http.Request) {
   216  		th.TestMethod(t, r, "GET")
   217  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   218  		th.TestHeader(t, r, "Accept", "application/json")
   219  
   220  		w.Header().Set("Content-Type", "application/json")
   221  		w.WriteHeader(http.StatusOK)
   222  		fmt.Fprintf(w, output)
   223  	})
   224  }
   225  
   226  func HandleFindSuccessfully(t *testing.T, output string) {
   227  	th.Mux.HandleFunc("/stacks/16ef0584-4458-41eb-87c8-0dc8d5f66c87", func(w http.ResponseWriter, r *http.Request) {
   228  		th.TestMethod(t, r, "GET")
   229  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   230  		th.TestHeader(t, r, "Accept", "application/json")
   231  
   232  		w.Header().Set("Content-Type", "application/json")
   233  		w.WriteHeader(http.StatusOK)
   234  		fmt.Fprintf(w, output)
   235  	})
   236  }
   237  
   238  // HandleUpdateSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   239  // on the test handler mux that responds with an `Update` response.
   240  func HandleUpdateSuccessfully(t *testing.T) {
   241  	th.Mux.HandleFunc("/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", func(w http.ResponseWriter, r *http.Request) {
   242  		th.TestMethod(t, r, "PUT")
   243  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   244  		th.TestHeader(t, r, "Accept", "application/json")
   245  
   246  		w.Header().Set("Content-Type", "application/json")
   247  		w.WriteHeader(http.StatusAccepted)
   248  	})
   249  }
   250  
   251  // HandleUpdatePatchSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   252  // on the test handler mux that responds with an `Update` response.
   253  func HandleUpdatePatchSuccessfully(t *testing.T) {
   254  	th.Mux.HandleFunc("/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", func(w http.ResponseWriter, r *http.Request) {
   255  		th.TestMethod(t, r, "PATCH")
   256  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   257  		th.TestHeader(t, r, "Accept", "application/json")
   258  
   259  		w.Header().Set("Content-Type", "application/json")
   260  		w.WriteHeader(http.StatusAccepted)
   261  	})
   262  }
   263  
   264  // HandleDeleteSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87`
   265  // on the test handler mux that responds with a `Delete` response.
   266  func HandleDeleteSuccessfully(t *testing.T) {
   267  	th.Mux.HandleFunc("/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", func(w http.ResponseWriter, r *http.Request) {
   268  		th.TestMethod(t, r, "DELETE")
   269  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   270  		th.TestHeader(t, r, "Accept", "application/json")
   271  
   272  		w.Header().Set("Content-Type", "application/json")
   273  		w.WriteHeader(http.StatusNoContent)
   274  	})
   275  }
   276  
   277  // GetExpected represents the expected object from a Get request.
   278  var PreviewExpected = &stacks.PreviewedStack{
   279  	DisableRollback: true,
   280  	Description:     "Simple template to test heat commands",
   281  	Parameters: map[string]string{
   282  		"flavor":         "m1.tiny",
   283  		"OS::stack_name": "postman_stack",
   284  		"OS::stack_id":   "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   285  	},
   286  	Name:         "postman_stack",
   287  	CreationTime: Create_time,
   288  	Links: []gophercloud.Link{
   289  		{
   290  			Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   291  			Rel:  "self",
   292  		},
   293  	},
   294  	Capabilities:        []interface{}{},
   295  	NotificationTopics:  []interface{}{},
   296  	ID:                  "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   297  	TemplateDescription: "Simple template to test heat commands",
   298  }
   299  
   300  // HandlePreviewSuccessfully creates an HTTP handler at `/stacks/preview`
   301  // on the test handler mux that responds with a `Preview` response.
   302  func HandlePreviewSuccessfully(t *testing.T, output string) {
   303  	th.Mux.HandleFunc("/stacks/preview", func(w http.ResponseWriter, r *http.Request) {
   304  		th.TestMethod(t, r, "POST")
   305  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   306  		th.TestHeader(t, r, "Accept", "application/json")
   307  
   308  		w.Header().Set("Content-Type", "application/json")
   309  		w.WriteHeader(http.StatusOK)
   310  		fmt.Fprintf(w, output)
   311  	})
   312  }
   313  
   314  // AbandonExpected represents the expected object from an Abandon request.
   315  var AbandonExpected = &stacks.AbandonedStack{
   316  	Status: "COMPLETE",
   317  	Name:   "postman_stack",
   318  	Template: map[string]interface{}{
   319  		"heat_template_version": "2013-05-23",
   320  		"description":           "Simple template to test heat commands",
   321  		"parameters": map[string]interface{}{
   322  			"flavor": map[string]interface{}{
   323  				"default": "m1.tiny",
   324  				"type":    "string",
   325  			},
   326  		},
   327  		"resources": map[string]interface{}{
   328  			"hello_world": map[string]interface{}{
   329  				"type": "OS::Nova::Server",
   330  				"properties": map[string]interface{}{
   331  					"key_name": "heat_key",
   332  					"flavor": map[string]interface{}{
   333  						"get_param": "flavor",
   334  					},
   335  					"image":     "ad091b52-742f-469e-8f3c-fd81cadf0743",
   336  					"user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n",
   337  				},
   338  			},
   339  		},
   340  	},
   341  	Action: "CREATE",
   342  	ID:     "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   343  	Resources: map[string]interface{}{
   344  		"hello_world": map[string]interface{}{
   345  			"status":      "COMPLETE",
   346  			"name":        "hello_world",
   347  			"resource_id": "8a310d36-46fc-436f-8be4-37a696b8ac63",
   348  			"action":      "CREATE",
   349  			"type":        "OS::Nova::Server",
   350  		},
   351  	},
   352  	Files: map[string]string{
   353  		"file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml": "heat_template_version: 2014-10-16\nparameters:\n  flavor:\n    type: string\n    description: Flavor for the server to be created\n    default: 4353\n    hidden: true\nresources:\n  test_server:\n    type: \"OS::Nova::Server\"\n    properties:\n      name: test-server\n      flavor: 2 GB General Purpose v1\n image: Debian 7 (Wheezy) (PVHVM)\n",
   354  	},
   355  	StackUserProjectID: "897686",
   356  	ProjectID:          "897686",
   357  	Environment: map[string]interface{}{
   358  		"encrypted_param_names": make([]map[string]interface{}, 0),
   359  		"parameter_defaults":    make(map[string]interface{}),
   360  		"parameters":            make(map[string]interface{}),
   361  		"resource_registry": map[string]interface{}{
   362  			"file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml": "file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml",
   363  			"resources": make(map[string]interface{}),
   364  		},
   365  	},
   366  }
   367  
   368  // AbandonOutput represents the response body from an Abandon request.
   369  const AbandonOutput = `
   370  {
   371    "status": "COMPLETE",
   372    "name": "postman_stack",
   373    "template": {
   374      "heat_template_version": "2013-05-23",
   375      "description": "Simple template to test heat commands",
   376      "parameters": {
   377        "flavor": {
   378          "default": "m1.tiny",
   379          "type": "string"
   380        }
   381      },
   382      "resources": {
   383        "hello_world": {
   384          "type": "OS::Nova::Server",
   385          "properties": {
   386            "key_name": "heat_key",
   387            "flavor": {
   388              "get_param": "flavor"
   389            },
   390            "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
   391            "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
   392          }
   393        }
   394      }
   395    },
   396    "action": "CREATE",
   397    "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87",
   398    "resources": {
   399      "hello_world": {
   400        "status": "COMPLETE",
   401        "name": "hello_world",
   402        "resource_id": "8a310d36-46fc-436f-8be4-37a696b8ac63",
   403        "action": "CREATE",
   404        "type": "OS::Nova::Server"
   405      }
   406    },
   407    "files": {
   408      "file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml": "heat_template_version: 2014-10-16\nparameters:\n  flavor:\n    type: string\n    description: Flavor for the server to be created\n    default: 4353\n    hidden: true\nresources:\n  test_server:\n    type: \"OS::Nova::Server\"\n    properties:\n      name: test-server\n      flavor: 2 GB General Purpose v1\n image: Debian 7 (Wheezy) (PVHVM)\n"
   409  },
   410    "environment": {
   411  	"encrypted_param_names": [],
   412  	"parameter_defaults": {},
   413  	"parameters": {},
   414  	"resource_registry": {
   415  		"file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml": "file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml",
   416  		"resources": {}
   417  	}
   418    },
   419    "stack_user_project_id": "897686",
   420    "project_id": "897686"
   421  }`
   422  
   423  // HandleAbandonSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/abandon`
   424  // on the test handler mux that responds with an `Abandon` response.
   425  func HandleAbandonSuccessfully(t *testing.T, output string) {
   426  	th.Mux.HandleFunc("/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c8/abandon", func(w http.ResponseWriter, r *http.Request) {
   427  		th.TestMethod(t, r, "DELETE")
   428  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   429  		th.TestHeader(t, r, "Accept", "application/json")
   430  
   431  		w.Header().Set("Content-Type", "application/json")
   432  		w.WriteHeader(http.StatusOK)
   433  		fmt.Fprintf(w, output)
   434  	})
   435  }