github.com/gophercloud/gophercloud@v1.11.0/openstack/blockstorage/extensions/schedulerstats/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"math"
     6  	"net/http"
     7  	"testing"
     8  
     9  	"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats"
    10  	"github.com/gophercloud/gophercloud/testhelper"
    11  	"github.com/gophercloud/gophercloud/testhelper/client"
    12  )
    13  
    14  const StoragePoolsListBody = `
    15  {
    16      "pools": [
    17          {
    18              "name": "rbd:cinder.volumes.ssd@cinder.volumes.ssd#cinder.volumes.ssd"
    19          },
    20          {
    21              "name": "rbd:cinder.volumes.hdd@cinder.volumes#cinder.volumes.hdd"
    22          }
    23      ]
    24  }
    25  `
    26  
    27  const StoragePoolsListBodyDetail = `
    28  {
    29      "pools": [
    30          {
    31              "capabilities": {
    32                  "driver_version": "1.2.0",
    33                  "filter_function": null,
    34                  "free_capacity_gb": 64765,
    35                  "goodness_function": null,
    36                  "max_over_subscription_ratio": "1.5",
    37                  "multiattach": false,
    38                  "reserved_percentage": 0,
    39                  "storage_protocol": "ceph",
    40                  "timestamp": "2016-11-24T10:33:51.248360",
    41                  "total_capacity_gb": 787947.93,
    42                  "vendor_name": "Open Source",
    43                  "volume_backend_name": "cinder.volumes.ssd"
    44              },
    45              "name": "rbd:cinder.volumes.ssd@cinder.volumes.ssd#cinder.volumes.ssd"
    46          },
    47          {
    48              "capabilities": {
    49                  "driver_version": "1.2.0",
    50                  "filter_function": null,
    51                  "free_capacity_gb": "unknown",
    52                  "goodness_function": null,
    53                  "max_over_subscription_ratio": 1.5,
    54                  "multiattach": false,
    55                  "reserved_percentage": 0,
    56                  "storage_protocol": "ceph",
    57                  "timestamp": "2016-11-24T10:33:43.138628",
    58                  "total_capacity_gb": "infinite",
    59                  "vendor_name": "Open Source",
    60                  "volume_backend_name": "cinder.volumes.hdd"
    61              },
    62              "name": "rbd:cinder.volumes.hdd@cinder.volumes.hdd#cinder.volumes.hdd"
    63          }
    64      ]
    65  }
    66  `
    67  
    68  var (
    69  	StoragePoolFake1 = schedulerstats.StoragePool{
    70  		Name: "rbd:cinder.volumes.ssd@cinder.volumes.ssd#cinder.volumes.ssd",
    71  		Capabilities: schedulerstats.Capabilities{
    72  			DriverVersion:            "1.2.0",
    73  			FreeCapacityGB:           64765,
    74  			MaxOverSubscriptionRatio: "1.5",
    75  			StorageProtocol:          "ceph",
    76  			TotalCapacityGB:          787947.93,
    77  			VendorName:               "Open Source",
    78  			VolumeBackendName:        "cinder.volumes.ssd",
    79  		},
    80  	}
    81  
    82  	StoragePoolFake2 = schedulerstats.StoragePool{
    83  		Name: "rbd:cinder.volumes.hdd@cinder.volumes.hdd#cinder.volumes.hdd",
    84  		Capabilities: schedulerstats.Capabilities{
    85  			DriverVersion:            "1.2.0",
    86  			FreeCapacityGB:           0.0,
    87  			MaxOverSubscriptionRatio: "1.5",
    88  			StorageProtocol:          "ceph",
    89  			TotalCapacityGB:          math.Inf(1),
    90  			VendorName:               "Open Source",
    91  			VolumeBackendName:        "cinder.volumes.hdd",
    92  		},
    93  	}
    94  )
    95  
    96  func HandleStoragePoolsListSuccessfully(t *testing.T) {
    97  	testhelper.Mux.HandleFunc("/scheduler-stats/get_pools", func(w http.ResponseWriter, r *http.Request) {
    98  		testhelper.TestMethod(t, r, "GET")
    99  		testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   100  
   101  		w.Header().Add("Content-Type", "application/json")
   102  
   103  		r.ParseForm()
   104  		if r.FormValue("detail") == "true" {
   105  			fmt.Fprintf(w, StoragePoolsListBodyDetail)
   106  		} else {
   107  			fmt.Fprintf(w, StoragePoolsListBody)
   108  		}
   109  	})
   110  }