github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/apiversions/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/gophercloud/gophercloud/openstack/baremetal/apiversions"
     9  	th "github.com/gophercloud/gophercloud/testhelper"
    10  	"github.com/gophercloud/gophercloud/testhelper/client"
    11  )
    12  
    13  const IronicAPIAllVersionResponse = `
    14  {
    15    "default_version": {
    16      "status": "CURRENT",
    17      "min_version": "1.1",
    18      "version": "1.56",
    19      "id": "v1",
    20      "links": [
    21        {
    22          "href": "http://localhost:6385/v1/",
    23          "rel": "self"
    24        }
    25      ]
    26    },
    27    "versions": [
    28      {
    29        "status": "CURRENT",
    30        "min_version": "1.1",
    31        "version": "1.56",
    32        "id": "v1",
    33        "links": [
    34          {
    35            "href": "http://localhost:6385/v1/",
    36            "rel": "self"
    37          }
    38        ]
    39      }
    40    ],
    41    "name": "OpenStack Ironic API",
    42    "description": "Ironic is an OpenStack project which aims to provision baremetal machines."
    43  }
    44  `
    45  
    46  const IronicAPIVersionResponse = `
    47  {
    48    "media_types": [
    49      {
    50        "base": "application/json",
    51        "type": "application/vnd.openstack.ironic.v1+json"
    52      }
    53    ],
    54    "version": {
    55      "status": "CURRENT",
    56      "min_version": "1.1",
    57      "version": "1.56",
    58      "id": "v1",
    59      "links": [
    60        {
    61          "href": "http://localhost:6385/v1/",
    62          "rel": "self"
    63        }
    64      ]
    65    },
    66    "id": "v1"
    67  }
    68  `
    69  
    70  var IronicAPIVersion1Result = apiversions.APIVersion{
    71  	ID:         "v1",
    72  	Status:     "CURRENT",
    73  	MinVersion: "1.1",
    74  	Version:    "1.56",
    75  }
    76  
    77  var IronicAllAPIVersionResults = apiversions.APIVersions{
    78  	DefaultVersion: IronicAPIVersion1Result,
    79  	Versions: []apiversions.APIVersion{
    80  		IronicAPIVersion1Result,
    81  	},
    82  }
    83  
    84  func MockListResponse(t *testing.T) {
    85  	th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    86  		th.TestMethod(t, r, "GET")
    87  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    88  
    89  		w.Header().Add("Content-Type", "application/json")
    90  		w.WriteHeader(http.StatusOK)
    91  
    92  		fmt.Fprintf(w, IronicAPIAllVersionResponse)
    93  	})
    94  }
    95  
    96  func MockGetResponse(t *testing.T) {
    97  	th.Mux.HandleFunc("/v1/", func(w http.ResponseWriter, r *http.Request) {
    98  		th.TestMethod(t, r, "GET")
    99  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   100  
   101  		w.Header().Add("Content-Type", "application/json")
   102  		w.WriteHeader(http.StatusOK)
   103  
   104  		fmt.Fprintf(w, IronicAPIVersionResponse)
   105  	})
   106  }