github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/rts/v1/stackresources/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/stackresources"
    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 = []stackresources.Resource{
    17  	{
    18  		Name: "hello_world",
    19  		Links: []golangsdk.Link{
    20  			{
    21  				Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
    22  				Rel:  "self",
    23  			},
    24  			{
    25  				Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
    26  				Rel:  "stack",
    27  			},
    28  		},
    29  		LogicalID:    "hello_world",
    30  		StatusReason: "state changed",
    31  		UpdatedTime:  time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
    32  		CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
    33  		RequiredBy:   []string{},
    34  		Status:       "CREATE_IN_PROGRESS",
    35  		PhysicalID:   "49181cd6-169a-4130-9455-31185bbfc5bf",
    36  		Type:         "OS::Nova::Server",
    37  	},
    38  }
    39  
    40  // ListOutput represents the response body from a List request.
    41  const ListOutput = `{
    42    "resources": [
    43    {
    44      "resource_name": "hello_world",
    45      "links": [
    46      {
    47        "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
    48        "rel": "self"
    49      },
    50      {
    51        "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
    52        "rel": "stack"
    53      }
    54      ],
    55      "logical_resource_id": "hello_world",
    56      "resource_status_reason": "state changed",
    57      "updated_time": "2015-02-05T21:33:11",
    58      "required_by": [],
    59      "resource_status": "CREATE_IN_PROGRESS",
    60      "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
    61  	"creation_time": "2015-02-05T21:33:10",
    62      "resource_type": "OS::Nova::Server",
    63  	"attributes": {"SXSW": "atx"},
    64  	"description": "Some resource"
    65    }
    66  ]
    67  }`
    68  
    69  // HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources`
    70  // on the test handler mux that responds with a `List` response.
    71  func HandleListSuccessfully(t *testing.T, output string) {
    72  	th.Mux.HandleFunc("/stacks/hello_world/resources", func(w http.ResponseWriter, r *http.Request) {
    73  		th.TestMethod(t, r, "GET")
    74  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    75  		th.TestHeader(t, r, "Accept", "application/json")
    76  
    77  		w.Header().Set("Content-Type", "application/json")
    78  		r.ParseForm()
    79  		marker := r.Form.Get("marker")
    80  		switch marker {
    81  		case "":
    82  			fmt.Fprintf(w, output)
    83  		case "49181cd6-169a-4130-9455-31185bbfc5bf":
    84  			fmt.Fprintf(w, `{"resources":[]}`)
    85  		default:
    86  			t.Fatalf("Unexpected marker: [%s]", marker)
    87  		}
    88  	})
    89  }