github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/identity/v3/catalog/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/identity/v3/tokens"
     9  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    10  	"github.com/opentelekomcloud/gophertelekomcloud/testhelper/client"
    11  )
    12  
    13  // ListOutput provides a single page of ServiceCatalog results.
    14  const ListOutput = `
    15  {
    16      "catalog": [
    17          {
    18              "endpoints": [
    19                  {
    20                      "id": "39dc322ce86c4111b4f06c2eeae0841b",
    21                      "interface": "public",
    22                      "region": "RegionOne",
    23                      "url": "http://localhost:5000"
    24                  },
    25                  {
    26                      "id": "ec642f27474842e78bf059f6c48f4e99",
    27                      "interface": "internal",
    28                      "region": "RegionOne",
    29                      "url": "http://localhost:5000"
    30                  },
    31                  {
    32                      "id": "c609fc430175452290b62a4242e8a7e8",
    33                      "interface": "admin",
    34                      "region": "RegionOne",
    35                      "url": "http://localhost:5000"
    36                  }
    37              ],
    38              "id": "4363ae44bdf34a3981fde3b823cb9aa2",
    39              "type": "identity",
    40              "name": "keystone"
    41          }
    42      ],
    43      "links": {
    44          "self": "https://example.com/identity/v3/catalog",
    45          "previous": null,
    46          "next": null
    47      }
    48  }
    49  `
    50  
    51  // ExpectedCatalogSlice is the slice of domains expected to be returned from ListOutput.
    52  var ExpectedCatalogSlice = []tokens.CatalogEntry{{
    53  	ID:   "4363ae44bdf34a3981fde3b823cb9aa2",
    54  	Name: "keystone",
    55  	Type: "identity",
    56  	Endpoints: []tokens.Endpoint{
    57  		{
    58  			ID:        "39dc322ce86c4111b4f06c2eeae0841b",
    59  			Interface: "public",
    60  			Region:    "RegionOne",
    61  			URL:       "http://localhost:5000",
    62  		},
    63  		{
    64  			ID:        "ec642f27474842e78bf059f6c48f4e99",
    65  			Interface: "internal",
    66  			Region:    "RegionOne",
    67  			URL:       "http://localhost:5000",
    68  		},
    69  		{
    70  			ID:        "c609fc430175452290b62a4242e8a7e8",
    71  			Region:    "RegionOne",
    72  			Interface: "admin",
    73  			URL:       "http://localhost:5000",
    74  		},
    75  	},
    76  }}
    77  
    78  // HandleListCatalogSuccessfully creates an HTTP handler at `/domains` on the
    79  // test handler mux that responds with a list of two domains.
    80  func HandleListCatalogSuccessfully(t *testing.T) {
    81  	th.Mux.HandleFunc("/auth/catalog", func(w http.ResponseWriter, r *http.Request) {
    82  		th.TestMethod(t, r, "GET")
    83  		th.TestHeader(t, r, "Accept", "application/json")
    84  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    85  
    86  		w.Header().Set("Content-Type", "application/json")
    87  		w.WriteHeader(http.StatusOK)
    88  		_, _ = fmt.Fprint(w, ListOutput)
    89  	})
    90  }