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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/gophercloud/gophercloud"
     9  	"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets"
    10  	th "github.com/gophercloud/gophercloud/testhelper"
    11  	"github.com/gophercloud/gophercloud/testhelper/client"
    12  )
    13  
    14  const FirstTenantID = "555544443333222211110000ffffeeee"
    15  
    16  var getExpectedJSONBody = `
    17  {
    18      "quota_set" : {
    19          "volumes" : 8,
    20          "snapshots" : 9,
    21          "gigabytes" : 10,
    22          "per_volume_gigabytes" : 11,
    23          "backups" : 12,
    24          "backup_gigabytes" : 13,
    25          "groups": 14
    26      }
    27  }`
    28  
    29  var getExpectedQuotaSet = quotasets.QuotaSet{
    30  	Volumes:            8,
    31  	Snapshots:          9,
    32  	Gigabytes:          10,
    33  	PerVolumeGigabytes: 11,
    34  	Backups:            12,
    35  	BackupGigabytes:    13,
    36  	Groups:             14,
    37  	Extra:              make(map[string]interface{}),
    38  }
    39  
    40  var getUsageExpectedJSONBody = `
    41  {
    42      "quota_set" : {
    43          "id": "555544443333222211110000ffffeeee",
    44          "volumes" : {
    45              "in_use": 15,
    46              "limit": 16,
    47              "reserved": 17
    48          },
    49          "snapshots" : {
    50              "in_use": 18,
    51              "limit": 19,
    52              "reserved": 20
    53          },
    54          "gigabytes" : {
    55              "in_use": 21,
    56              "limit": 22,
    57              "reserved": 23
    58          },
    59          "per_volume_gigabytes" : {
    60              "in_use": 24,
    61              "limit": 25,
    62              "reserved": 26
    63          },
    64          "backups" : {
    65              "in_use": 27,
    66              "limit": 28,
    67              "reserved": 29
    68          },
    69          "backup_gigabytes" : {
    70              "in_use": 30,
    71              "limit": 31,
    72              "reserved": 32
    73          },
    74          "groups" : {
    75              "in_use": 40,
    76              "limit": 41,
    77              "reserved": 42
    78          }
    79  	}
    80  }`
    81  
    82  var getUsageExpectedQuotaSet = quotasets.QuotaUsageSet{
    83  	ID:                 FirstTenantID,
    84  	Volumes:            quotasets.QuotaUsage{InUse: 15, Limit: 16, Reserved: 17},
    85  	Snapshots:          quotasets.QuotaUsage{InUse: 18, Limit: 19, Reserved: 20},
    86  	Gigabytes:          quotasets.QuotaUsage{InUse: 21, Limit: 22, Reserved: 23},
    87  	PerVolumeGigabytes: quotasets.QuotaUsage{InUse: 24, Limit: 25, Reserved: 26},
    88  	Backups:            quotasets.QuotaUsage{InUse: 27, Limit: 28, Reserved: 29},
    89  	BackupGigabytes:    quotasets.QuotaUsage{InUse: 30, Limit: 31, Reserved: 32},
    90  	Groups:             quotasets.QuotaUsage{InUse: 40, Limit: 41, Reserved: 42},
    91  }
    92  
    93  var fullUpdateExpectedJSONBody = `
    94  {
    95      "quota_set": {
    96          "volumes": 8,
    97          "snapshots": 9,
    98          "gigabytes": 10,
    99          "per_volume_gigabytes": 11,
   100          "backups": 12,
   101          "backup_gigabytes": 13,
   102          "groups": 14
   103      }
   104  }`
   105  
   106  var fullUpdateOpts = quotasets.UpdateOpts{
   107  	Volumes:            gophercloud.IntToPointer(8),
   108  	Snapshots:          gophercloud.IntToPointer(9),
   109  	Gigabytes:          gophercloud.IntToPointer(10),
   110  	PerVolumeGigabytes: gophercloud.IntToPointer(11),
   111  	Backups:            gophercloud.IntToPointer(12),
   112  	BackupGigabytes:    gophercloud.IntToPointer(13),
   113  	Groups:             gophercloud.IntToPointer(14),
   114  	Extra:              make(map[string]interface{}),
   115  }
   116  
   117  var fullUpdateExpectedQuotaSet = quotasets.QuotaSet{
   118  	Volumes:            8,
   119  	Snapshots:          9,
   120  	Gigabytes:          10,
   121  	PerVolumeGigabytes: 11,
   122  	Backups:            12,
   123  	BackupGigabytes:    13,
   124  	Groups:             14,
   125  	Extra:              make(map[string]interface{}),
   126  }
   127  
   128  var partialUpdateExpectedJSONBody = `
   129  {
   130      "quota_set": {
   131          "volumes": 200,
   132          "snapshots": 0,
   133          "gigabytes": 0,
   134          "per_volume_gigabytes": 0,
   135          "backups": 0,
   136          "backup_gigabytes": 0
   137      }
   138  }`
   139  
   140  var partialUpdateOpts = quotasets.UpdateOpts{
   141  	Volumes:            gophercloud.IntToPointer(200),
   142  	Snapshots:          gophercloud.IntToPointer(0),
   143  	Gigabytes:          gophercloud.IntToPointer(0),
   144  	PerVolumeGigabytes: gophercloud.IntToPointer(0),
   145  	Backups:            gophercloud.IntToPointer(0),
   146  	BackupGigabytes:    gophercloud.IntToPointer(0),
   147  	Extra:              make(map[string]interface{}),
   148  }
   149  
   150  var partiualUpdateExpectedQuotaSet = quotasets.QuotaSet{
   151  	Volumes: 200,
   152  	Extra:   make(map[string]interface{}),
   153  }
   154  
   155  // HandleSuccessfulRequest configures the test server to respond to an HTTP request.
   156  func HandleSuccessfulRequest(t *testing.T, httpMethod, uriPath, jsonOutput string, uriQueryParams map[string]string) {
   157  
   158  	th.Mux.HandleFunc(uriPath, func(w http.ResponseWriter, r *http.Request) {
   159  		th.TestMethod(t, r, httpMethod)
   160  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   161  		w.Header().Add("Content-Type", "application/json")
   162  
   163  		if uriQueryParams != nil {
   164  			th.TestFormValues(t, r, uriQueryParams)
   165  		}
   166  
   167  		fmt.Fprintf(w, jsonOutput)
   168  	})
   169  }
   170  
   171  // HandleDeleteSuccessfully tests quotaset deletion.
   172  func HandleDeleteSuccessfully(t *testing.T) {
   173  	th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
   174  		th.TestMethod(t, r, "DELETE")
   175  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   176  
   177  		w.WriteHeader(http.StatusOK)
   178  	})
   179  }