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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/limits"
     9  	th "github.com/gophercloud/gophercloud/testhelper"
    10  	"github.com/gophercloud/gophercloud/testhelper/client"
    11  )
    12  
    13  // GetOutput is a sample response to a Get call.
    14  const GetOutput = `
    15  {
    16  	"limits": {
    17  		"rate": [
    18  			{
    19  				"regex": ".*",
    20  				"uri": "*",
    21  				"limit": [
    22  					{
    23  						"verb": "GET",
    24  						"next-available": "1970-01-01T00:00:00",
    25  						"unit": "MINUTE",
    26  						"value": 10,
    27  						"remaining": 10
    28  					},
    29  					{
    30  						"verb": "POST",
    31  						"next-available": "1970-01-01T00:00:00",
    32  						"unit": "HOUR",
    33  						"value": 5,
    34  						"remaining": 5
    35  					}
    36  				]
    37  			},
    38  			{
    39  				"regex": "changes-since",
    40  				"uri": "changes-since*",
    41  				"limit": [
    42  					{
    43  						"verb": "GET",
    44  						"next-available": "1970-01-01T00:00:00",
    45  						"unit": "MINUTE",
    46  						"value": 5,
    47  						"remaining": 5
    48  					}
    49  				]
    50  			}
    51  		],
    52  	  	"absolute": {
    53  			"maxTotalVolumes": 40,
    54  			"maxTotalSnapshots": 40,
    55  			"maxTotalVolumeGigabytes": 1000,
    56  			"maxTotalBackups": 10,
    57  			"maxTotalBackupGigabytes": 1000,
    58  			"totalVolumesUsed": 1,
    59  			"totalGigabytesUsed": 100,
    60  			"totalSnapshotsUsed": 1,
    61  			"totalBackupsUsed": 1,
    62  			"totalBackupGigabytesUsed": 50
    63  		}
    64  	}
    65  }
    66  `
    67  
    68  // LimitsResult is the result of the limits in GetOutput.
    69  var LimitsResult = limits.Limits{
    70  	Rate: []limits.Rate{
    71  		{
    72  			Regex: ".*",
    73  			URI:   "*",
    74  			Limit: []limits.Limit{
    75  				{
    76  					Verb:          "GET",
    77  					NextAvailable: "1970-01-01T00:00:00",
    78  					Unit:          "MINUTE",
    79  					Value:         10,
    80  					Remaining:     10,
    81  				},
    82  				{
    83  					Verb:          "POST",
    84  					NextAvailable: "1970-01-01T00:00:00",
    85  					Unit:          "HOUR",
    86  					Value:         5,
    87  					Remaining:     5,
    88  				},
    89  			},
    90  		},
    91  		{
    92  			Regex: "changes-since",
    93  			URI:   "changes-since*",
    94  			Limit: []limits.Limit{
    95  				{
    96  					Verb:          "GET",
    97  					NextAvailable: "1970-01-01T00:00:00",
    98  					Unit:          "MINUTE",
    99  					Value:         5,
   100  					Remaining:     5,
   101  				},
   102  			},
   103  		},
   104  	},
   105  	Absolute: limits.Absolute{
   106  		MaxTotalVolumes:          40,
   107  		MaxTotalSnapshots:        40,
   108  		MaxTotalVolumeGigabytes:  1000,
   109  		MaxTotalBackups:          10,
   110  		MaxTotalBackupGigabytes:  1000,
   111  		TotalVolumesUsed:         1,
   112  		TotalGigabytesUsed:       100,
   113  		TotalSnapshotsUsed:       1,
   114  		TotalBackupsUsed:         1,
   115  		TotalBackupGigabytesUsed: 50,
   116  	},
   117  }
   118  
   119  // HandleGetSuccessfully configures the test server to respond to a Get request
   120  // for a limit.
   121  func HandleGetSuccessfully(t *testing.T) {
   122  	th.Mux.HandleFunc("/limits", func(w http.ResponseWriter, r *http.Request) {
   123  		th.TestMethod(t, r, "GET")
   124  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   125  
   126  		w.Header().Add("Content-Type", "application/json")
   127  		fmt.Fprintf(w, GetOutput)
   128  	})
   129  }