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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	th "github.com/huaweicloud/golangsdk/testhelper"
     9  	"github.com/huaweicloud/golangsdk/testhelper/client"
    10  )
    11  
    12  func MockListResponse(t *testing.T) {
    13  	th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    14  		th.TestMethod(t, r, "GET")
    15  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    16  
    17  		w.Header().Add("Content-Type", "application/json")
    18  		w.WriteHeader(http.StatusOK)
    19  
    20  		fmt.Fprintf(w, `{
    21  			"versions": [
    22  				{
    23  					"status": "CURRENT",
    24  					"updated": "2012-01-04T11:33:21Z",
    25  					"id": "v1.0",
    26  					"links": [
    27  						{
    28  							"href": "http://23.253.228.211:8776/v1/",
    29  							"rel": "self"
    30  						}
    31  					]
    32  			    },
    33  				{
    34  					"status": "CURRENT",
    35  					"updated": "2012-11-21T11:33:21Z",
    36  					"id": "v2.0",
    37  					"links": [
    38  						{
    39  							"href": "http://23.253.228.211:8776/v2/",
    40  							"rel": "self"
    41  						}
    42  					]
    43  				}
    44  			]
    45  		}`)
    46  	})
    47  }
    48  
    49  func MockGetResponse(t *testing.T) {
    50  	th.Mux.HandleFunc("/v1/", func(w http.ResponseWriter, r *http.Request) {
    51  		th.TestMethod(t, r, "GET")
    52  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    53  
    54  		w.Header().Add("Content-Type", "application/json")
    55  		w.WriteHeader(http.StatusOK)
    56  
    57  		fmt.Fprintf(w, `{
    58  			"version": {
    59  				"status": "CURRENT",
    60  				"updated": "2012-01-04T11:33:21Z",
    61  				"media-types": [
    62  					{
    63  						"base": "application/xml",
    64  						"type": "application/vnd.openstack.volume+xml;version=1"
    65  					},
    66  					{
    67  						"base": "application/json",
    68  						"type": "application/vnd.openstack.volume+json;version=1"
    69  					}
    70  				],
    71  				"id": "v1.0",
    72  				"links": [
    73  					{
    74  						"href": "http://23.253.228.211:8776/v1/",
    75  						"rel": "self"
    76  					},
    77  					{
    78  						"href": "http://jorgew.github.com/block-storage-api/content/os-block-storage-1.0.pdf",
    79  						"type": "application/pdf",
    80  						"rel": "describedby"
    81  					},
    82  					{
    83  						"href": "http://docs.rackspacecloud.com/servers/api/v1.1/application.wadl",
    84  						"type": "application/vnd.sun.wadl+xml",
    85  						"rel": "describedby"
    86  					}
    87  				]
    88  			}
    89  		}`)
    90  	})
    91  }