github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/evs/extensions/schedulerstats/testing/fixtures.go (about)

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