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

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