github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/extensions/quotasets/testing/fixtures.go (about)

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