github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/apiversions/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/openstack/sharedfilesystems/apiversions"
    10  	th "github.com/gophercloud/gophercloud/testhelper"
    11  	"github.com/gophercloud/gophercloud/testhelper/client"
    12  )
    13  
    14  const ManilaAPIVersionResponse = `
    15  {
    16      "versions": [
    17          {
    18              "id": "v2.0",
    19              "links": [
    20                  {
    21                      "href": "http://docs.openstack.org/",
    22                      "rel": "describedby",
    23                      "type": "text/html"
    24                  },
    25                  {
    26                      "href": "http://localhost:8786/v2/",
    27                      "rel": "self"
    28                  }
    29              ],
    30              "media-types": [
    31                  {
    32                      "base": "application/json",
    33                      "type": "application/vnd.openstack.share+json;version=1"
    34                  }
    35              ],
    36              "min_version": "2.0",
    37              "status": "CURRENT",
    38              "updated": "2015-08-27T11:33:21Z",
    39              "version": "2.32"
    40          }
    41      ]
    42  }
    43  `
    44  
    45  const ManilaAPIInvalidVersionResponse_1 = `
    46  {
    47      "versions": [
    48      ]
    49  }
    50  `
    51  
    52  const ManilaAPIInvalidVersionResponse_2 = `
    53  {
    54      "versions": [
    55          {
    56              "id": "v2.0",
    57              "links": [
    58                  {
    59                      "href": "http://docs.openstack.org/",
    60                      "rel": "describedby",
    61                      "type": "text/html"
    62                  },
    63                  {
    64                      "href": "http://localhost:8786/v2/",
    65                      "rel": "self"
    66                  }
    67              ],
    68              "media-types": [
    69                  {
    70                      "base": "application/json",
    71                      "type": "application/vnd.openstack.share+json;version=1"
    72                  }
    73              ],
    74              "min_version": "2.0",
    75              "status": "CURRENT",
    76              "updated": "2015-08-27T11:33:21Z",
    77              "version": "2.32"
    78          },
    79          {
    80              "id": "v2.9",
    81              "links": [
    82                  {
    83                      "href": "http://docs.openstack.org/",
    84                      "rel": "describedby",
    85                      "type": "text/html"
    86                  },
    87                  {
    88                      "href": "http://localhost:8786/v2/",
    89                      "rel": "self"
    90                  }
    91              ],
    92              "media-types": [
    93                  {
    94                      "base": "application/json",
    95                      "type": "application/vnd.openstack.share+json;version=1"
    96                  }
    97              ],
    98              "min_version": "2.9",
    99              "status": "CURRENT",
   100              "updated": "2015-08-27T11:33:21Z",
   101              "version": "2.99"
   102          }
   103      ]
   104  }
   105  `
   106  
   107  const ManilaAllAPIVersionsResponse = `
   108  {
   109      "versions": [
   110          {
   111              "id": "v1.0",
   112              "links": [
   113                  {
   114                      "href": "http://docs.openstack.org/",
   115                      "rel": "describedby",
   116                      "type": "text/html"
   117                  },
   118                  {
   119                      "href": "http://localhost:8786/v1/",
   120                      "rel": "self"
   121                  }
   122              ],
   123              "media-types": [
   124                  {
   125                      "base": "application/json",
   126                      "type": "application/vnd.openstack.share+json;version=1"
   127                  }
   128              ],
   129              "min_version": "",
   130              "status": "DEPRECATED",
   131              "updated": "2015-08-27T11:33:21Z",
   132              "version": ""
   133          },
   134          {
   135              "id": "v2.0",
   136              "links": [
   137                  {
   138                      "href": "http://docs.openstack.org/",
   139                      "rel": "describedby",
   140                      "type": "text/html"
   141                  },
   142                  {
   143                      "href": "http://localhost:8786/v2/",
   144                      "rel": "self"
   145                  }
   146              ],
   147              "media-types": [
   148                  {
   149                      "base": "application/json",
   150                      "type": "application/vnd.openstack.share+json;version=1"
   151                  }
   152              ],
   153              "min_version": "2.0",
   154              "status": "CURRENT",
   155              "updated": "2015-08-27T11:33:21Z",
   156              "version": "2.32"
   157          }
   158      ]
   159  }
   160  `
   161  
   162  var ManilaAPIVersion1Result = apiversions.APIVersion{
   163  	ID:      "v1.0",
   164  	Status:  "DEPRECATED",
   165  	Updated: time.Date(2015, 8, 27, 11, 33, 21, 0, time.UTC),
   166  }
   167  
   168  var ManilaAPIVersion2Result = apiversions.APIVersion{
   169  	ID:         "v2.0",
   170  	Status:     "CURRENT",
   171  	Updated:    time.Date(2015, 8, 27, 11, 33, 21, 0, time.UTC),
   172  	MinVersion: "2.0",
   173  	Version:    "2.32",
   174  }
   175  
   176  var ManilaAllAPIVersionResults = []apiversions.APIVersion{
   177  	ManilaAPIVersion1Result,
   178  	ManilaAPIVersion2Result,
   179  }
   180  
   181  func MockListResponse(t *testing.T) {
   182  	th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
   183  		th.TestMethod(t, r, "GET")
   184  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   185  
   186  		w.Header().Add("Content-Type", "application/json")
   187  		w.WriteHeader(http.StatusOK)
   188  
   189  		fmt.Fprintf(w, ManilaAllAPIVersionsResponse)
   190  	})
   191  }
   192  
   193  func MockGetResponse(t *testing.T) {
   194  	th.Mux.HandleFunc("/v2/", func(w http.ResponseWriter, r *http.Request) {
   195  		th.TestMethod(t, r, "GET")
   196  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   197  
   198  		w.Header().Add("Content-Type", "application/json")
   199  		w.WriteHeader(http.StatusOK)
   200  
   201  		fmt.Fprintf(w, ManilaAPIVersionResponse)
   202  	})
   203  }
   204  
   205  func MockGetNoResponse(t *testing.T) {
   206  	th.Mux.HandleFunc("/v2/", func(w http.ResponseWriter, r *http.Request) {
   207  		th.TestMethod(t, r, "GET")
   208  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   209  
   210  		w.Header().Add("Content-Type", "application/json")
   211  		w.WriteHeader(http.StatusOK)
   212  
   213  		fmt.Fprintf(w, ManilaAPIInvalidVersionResponse_1)
   214  	})
   215  }
   216  
   217  func MockGetMultipleResponses(t *testing.T) {
   218  	th.Mux.HandleFunc("/v2/", func(w http.ResponseWriter, r *http.Request) {
   219  		th.TestMethod(t, r, "GET")
   220  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   221  
   222  		w.Header().Add("Content-Type", "application/json")
   223  		w.WriteHeader(http.StatusOK)
   224  
   225  		fmt.Fprintf(w, ManilaAPIInvalidVersionResponse_2)
   226  	})
   227  }