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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/huaweicloud/golangsdk"
    10  	"github.com/huaweicloud/golangsdk/openstack/rts/v1/stackevents"
    11  	th "github.com/huaweicloud/golangsdk/testhelper"
    12  	fake "github.com/huaweicloud/golangsdk/testhelper/client"
    13  )
    14  
    15  // ListExpected represents the expected object from a List request.
    16  var ListExpected = []stackevents.Event{
    17  	{
    18  		ResourceName: "hello_world",
    19  		Time:         time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
    20  		Links: []golangsdk.Link{
    21  			{
    22  				Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a",
    23  				Rel:  "self",
    24  			},
    25  			{
    26  				Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
    27  				Rel:  "resource",
    28  			},
    29  			{
    30  				Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
    31  				Rel:  "stack",
    32  			},
    33  		},
    34  		LogicalResourceID:    "hello_world",
    35  		ResourceStatusReason: "state changed",
    36  		ResourceStatus:       "CREATE_IN_PROGRESS",
    37  		PhysicalResourceID:   "",
    38  		ID:                   "06feb26f-9298-4a9b-8749-9d770e5d577a",
    39  	},
    40  	{
    41  		ResourceName: "hello_world",
    42  		Time:         time.Date(2015, 2, 5, 21, 33, 27, 0, time.UTC),
    43  		Links: []golangsdk.Link{
    44  			{
    45  				Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
    46  				Rel:  "self",
    47  			},
    48  			{
    49  				Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
    50  				Rel:  "resource",
    51  			},
    52  			{
    53  				Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
    54  				Rel:  "stack",
    55  			},
    56  		},
    57  		LogicalResourceID:    "hello_world",
    58  		ResourceStatusReason: "state changed",
    59  		ResourceStatus:       "CREATE_COMPLETE",
    60  		PhysicalResourceID:   "49181cd6-169a-4130-9455-31185bbfc5bf",
    61  		ID:                   "93940999-7d40-44ae-8de4-19624e7b8d18",
    62  	},
    63  }
    64  
    65  // ListOutput represents the response body from a List request.
    66  const ListOutput = `
    67  {
    68    "events": [
    69    {
    70      "resource_name": "hello_world",
    71      "event_time": "2015-02-05T21:33:11",
    72      "links": [
    73      {
    74        "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/06feb26f-9298-4a9b-8749-9d770e5d577a",
    75        "rel": "self"
    76      },
    77      {
    78        "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
    79        "rel": "resource"
    80      },
    81      {
    82        "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
    83        "rel": "stack"
    84      }
    85      ],
    86      "logical_resource_id": "hello_world",
    87      "resource_status_reason": "state changed",
    88      "resource_status": "CREATE_IN_PROGRESS",
    89      "physical_resource_id": null,
    90      "id": "06feb26f-9298-4a9b-8749-9d770e5d577a"
    91      },
    92      {
    93        "resource_name": "hello_world",
    94        "event_time": "2015-02-05T21:33:27",
    95        "links": [
    96        {
    97          "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world/events/93940999-7d40-44ae-8de4-19624e7b8d18",
    98          "rel": "self"
    99        },
   100        {
   101          "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
   102          "rel": "resource"
   103        },
   104        {
   105          "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
   106          "rel": "stack"
   107        }
   108        ],
   109        "logical_resource_id": "hello_world",
   110        "resource_status_reason": "state changed",
   111        "resource_status": "CREATE_COMPLETE",
   112        "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
   113        "id": "93940999-7d40-44ae-8de4-19624e7b8d18"
   114      }
   115    ]
   116  }`
   117  
   118  // HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/events`
   119  // on the test handler mux that responds with a `List` response.
   120  func HandleListSuccessfully(t *testing.T, output string) {
   121  	th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/events", func(w http.ResponseWriter, r *http.Request) {
   122  		th.TestMethod(t, r, "GET")
   123  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   124  		th.TestHeader(t, r, "Accept", "application/json")
   125  
   126  		w.Header().Set("Content-Type", "application/json")
   127  		r.ParseForm()
   128  		marker := r.Form.Get("marker")
   129  		switch marker {
   130  		case "":
   131  			fmt.Fprintf(w, output)
   132  		case "93940999-7d40-44ae-8de4-19624e7b8d18":
   133  			fmt.Fprintf(w, `{"events":[]}`)
   134  		default:
   135  			t.Fatalf("Unexpected marker: [%s]", marker)
   136  		}
   137  	})
   138  }