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

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/usage"
    10  	th "github.com/huaweicloud/golangsdk/testhelper"
    11  	"github.com/huaweicloud/golangsdk/testhelper/client"
    12  )
    13  
    14  const FirstTenantID = "aabbccddeeff112233445566"
    15  const SecondTenantID = "665544332211ffeeddccbbaa"
    16  
    17  // GetSingleTenant holds the fixtures for the content of the request for a
    18  // single tenant.
    19  const GetSingleTenant = `{
    20      "tenant_usage": {
    21          "server_usages": [
    22              {
    23                  "ended_at": null,
    24                  "flavor": "m1.tiny",
    25                  "hours": 0.021675453333333334,
    26                  "instance_id": "a70096fd-8196-406b-86c4-045840f53ad7",
    27                  "local_gb": 1,
    28                  "memory_mb": 512,
    29                  "name": "jttest",
    30                  "started_at": "2017-11-30T03:23:43.000000",
    31                  "state": "active",
    32                  "tenant_id": "aabbccddeeff112233445566",
    33                  "uptime": 78,
    34                  "vcpus": 1
    35              },
    36              {
    37                  "ended_at": "2017-11-21T04:10:11.000000",
    38                  "flavor": "m1.acctest",
    39                  "hours": 0.33444444444444443,
    40                  "instance_id": "c04e38f2-dcee-4ca8-9466-7708d0a9b6dd",
    41                  "local_gb": 15,
    42                  "memory_mb": 512,
    43                  "name": "basic",
    44                  "started_at": "2017-11-21T03:50:07.000000",
    45                  "state": "terminated",
    46                  "tenant_id": "aabbccddeeff112233445566",
    47                  "uptime": 1204,
    48                  "vcpus": 1
    49              },
    50              {
    51                  "ended_at": "2017-11-30T03:21:21.000000",
    52                  "flavor": "m1.acctest",
    53                  "hours": 0.004166666666666667,
    54                  "instance_id": "ceb654fa-e0e8-44fb-8942-e4d0bfad3941",
    55                  "local_gb": 15,
    56                  "memory_mb": 512,
    57                  "name": "ACPTTESTJSxbPQAC34lTnBE1",
    58                  "started_at": "2017-11-30T03:21:06.000000",
    59                  "state": "terminated",
    60                  "tenant_id": "aabbccddeeff112233445566",
    61                  "uptime": 15,
    62                  "vcpus": 1
    63              }
    64          ],
    65          "start": "2017-11-02T03:25:01.000000",
    66          "stop": "2017-11-30T03:25:01.000000",
    67          "tenant_id": "aabbccddeeff112233445566",
    68          "total_hours": 1.25834212,
    69          "total_local_gb_usage": 18.571675453333334,
    70          "total_memory_mb_usage": 644.27116544,
    71          "total_vcpus_usage": 1.25834212
    72      }
    73  }`
    74  
    75  // HandleGetSingleTenantSuccessfully configures the test server to respond to a
    76  // Get request for a single tenant
    77  func HandleGetSingleTenantSuccessfully(t *testing.T) {
    78  	th.Mux.HandleFunc("/os-simple-tenant-usage/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
    79  		th.TestMethod(t, r, "GET")
    80  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    81  		w.Header().Add("Content-Type", "application/json")
    82  		fmt.Fprint(w, GetSingleTenant)
    83  	})
    84  }
    85  
    86  // SingleTenantUsageResults is the code fixture for GetSingleTenant.
    87  var SingleTenantUsageResults = usage.TenantUsage{
    88  	ServerUsages: []usage.ServerUsage{
    89  		{
    90  			Flavor:     "m1.tiny",
    91  			Hours:      0.021675453333333334,
    92  			InstanceID: "a70096fd-8196-406b-86c4-045840f53ad7",
    93  			LocalGB:    1,
    94  			MemoryMB:   512,
    95  			Name:       "jttest",
    96  			StartedAt:  time.Date(2017, 11, 30, 3, 23, 43, 0, time.UTC),
    97  			State:      "active",
    98  			TenantID:   "aabbccddeeff112233445566",
    99  			Uptime:     78,
   100  			VCPUs:      1,
   101  		},
   102  		{
   103  			Flavor:     "m1.acctest",
   104  			Hours:      0.33444444444444443,
   105  			InstanceID: "c04e38f2-dcee-4ca8-9466-7708d0a9b6dd",
   106  			LocalGB:    15,
   107  			MemoryMB:   512,
   108  			Name:       "basic",
   109  			StartedAt:  time.Date(2017, 11, 21, 3, 50, 7, 0, time.UTC),
   110  			EndedAt:    time.Date(2017, 11, 21, 4, 10, 11, 0, time.UTC),
   111  			State:      "terminated",
   112  			TenantID:   "aabbccddeeff112233445566",
   113  			Uptime:     1204,
   114  			VCPUs:      1,
   115  		},
   116  		{
   117  			Flavor:     "m1.acctest",
   118  			Hours:      0.004166666666666667,
   119  			InstanceID: "ceb654fa-e0e8-44fb-8942-e4d0bfad3941",
   120  			LocalGB:    15,
   121  			MemoryMB:   512,
   122  			Name:       "ACPTTESTJSxbPQAC34lTnBE1",
   123  			StartedAt:  time.Date(2017, 11, 30, 3, 21, 6, 0, time.UTC),
   124  			EndedAt:    time.Date(2017, 11, 30, 3, 21, 21, 0, time.UTC),
   125  			State:      "terminated",
   126  			TenantID:   "aabbccddeeff112233445566",
   127  			Uptime:     15,
   128  			VCPUs:      1,
   129  		},
   130  	},
   131  	Start:              time.Date(2017, 11, 2, 3, 25, 1, 0, time.UTC),
   132  	Stop:               time.Date(2017, 11, 30, 3, 25, 1, 0, time.UTC),
   133  	TenantID:           "aabbccddeeff112233445566",
   134  	TotalHours:         1.25834212,
   135  	TotalLocalGBUsage:  18.571675453333334,
   136  	TotalMemoryMBUsage: 644.27116544,
   137  	TotalVCPUsUsage:    1.25834212,
   138  }
   139  
   140  // GetAllTenants holds the fixtures for the content of the request for
   141  // all tenants.
   142  const GetAllTenants = `{
   143      "tenant_usages": [
   144  				{
   145  					"server_usages": [
   146  							{
   147  									"ended_at": null,
   148  									"flavor": "m1.tiny",
   149  									"hours": 0.021675453333333334,
   150  									"instance_id": "a70096fd-8196-406b-86c4-045840f53ad7",
   151  									"local_gb": 1,
   152  									"memory_mb": 512,
   153  									"name": "jttest",
   154  									"started_at": "2017-11-30T03:23:43.000000",
   155  									"state": "active",
   156  									"tenant_id": "aabbccddeeff112233445566",
   157  									"uptime": 78,
   158  									"vcpus": 1
   159  							},
   160  							{
   161  									"ended_at": "2017-11-21T04:10:11.000000",
   162  									"flavor": "m1.acctest",
   163  									"hours": 0.33444444444444443,
   164  									"instance_id": "c04e38f2-dcee-4ca8-9466-7708d0a9b6dd",
   165  									"local_gb": 15,
   166  									"memory_mb": 512,
   167  									"name": "basic",
   168  									"started_at": "2017-11-21T03:50:07.000000",
   169  									"state": "terminated",
   170  									"tenant_id": "aabbccddeeff112233445566",
   171  									"uptime": 1204,
   172  									"vcpus": 1
   173  							},
   174  							{
   175  									"ended_at": "2017-11-30T03:21:21.000000",
   176  									"flavor": "m1.acctest",
   177  									"hours": 0.004166666666666667,
   178  									"instance_id": "ceb654fa-e0e8-44fb-8942-e4d0bfad3941",
   179  									"local_gb": 15,
   180  									"memory_mb": 512,
   181  									"name": "ACPTTESTJSxbPQAC34lTnBE1",
   182  									"started_at": "2017-11-30T03:21:06.000000",
   183  									"state": "terminated",
   184  									"tenant_id": "aabbccddeeff112233445566",
   185  									"uptime": 15,
   186  									"vcpus": 1
   187  							}
   188  					],
   189  					"start": "2017-11-02T03:25:01.000000",
   190  					"stop": "2017-11-30T03:25:01.000000",
   191  					"tenant_id": "aabbccddeeff112233445566",
   192  					"total_hours": 1.25834212,
   193  					"total_local_gb_usage": 18.571675453333334,
   194  					"total_memory_mb_usage": 644.27116544,
   195  					"total_vcpus_usage": 1.25834212
   196  				},
   197  				{
   198  					"server_usages": [
   199  							{
   200  									"ended_at": null,
   201  									"flavor": "m1.tiny",
   202  									"hours": 0.021675453333333334,
   203  									"instance_id": "a70096fd-8196-406b-86c4-045840f53ad7",
   204  									"local_gb": 1,
   205  									"memory_mb": 512,
   206  									"name": "test",
   207  									"started_at": "2017-11-30T03:23:43.000000",
   208  									"state": "active",
   209  									"tenant_id": "665544332211ffeeddccbbaa",
   210  									"uptime": 78,
   211  									"vcpus": 1
   212  							}
   213  					],
   214  					"start": "2017-11-02T03:25:01.000000",
   215  					"stop": "2017-11-30T03:25:01.000000",
   216  					"tenant_id": "665544332211ffeeddccbbaa",
   217  					"total_hours": 0.021675453333333334,
   218  					"total_local_gb_usage": 18.571675453333334,
   219  					"total_memory_mb_usage": 644.27116544,
   220  					"total_vcpus_usage": 1.25834212
   221  				}
   222  		]
   223  }`
   224  
   225  // HandleGetAllTenantsSuccessfully configures the test server to respond to a
   226  // Get request for all tenants.
   227  func HandleGetAllTenantsSuccessfully(t *testing.T) {
   228  	th.Mux.HandleFunc("/os-simple-tenant-usage", func(w http.ResponseWriter, r *http.Request) {
   229  		th.TestMethod(t, r, "GET")
   230  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   231  		w.Header().Add("Content-Type", "application/json")
   232  		fmt.Fprint(w, GetAllTenants)
   233  	})
   234  }
   235  
   236  // AllTenantsUsageResult is the code fixture for GetAllTenants.
   237  var AllTenantsUsageResult = []usage.TenantUsage{
   238  	{
   239  		ServerUsages: []usage.ServerUsage{
   240  			{
   241  				Flavor:     "m1.tiny",
   242  				Hours:      0.021675453333333334,
   243  				InstanceID: "a70096fd-8196-406b-86c4-045840f53ad7",
   244  				LocalGB:    1,
   245  				MemoryMB:   512,
   246  				Name:       "jttest",
   247  				StartedAt:  time.Date(2017, 11, 30, 3, 23, 43, 0, time.UTC),
   248  				State:      "active",
   249  				TenantID:   "aabbccddeeff112233445566",
   250  				Uptime:     78,
   251  				VCPUs:      1,
   252  			},
   253  			{
   254  				Flavor:     "m1.acctest",
   255  				Hours:      0.33444444444444443,
   256  				InstanceID: "c04e38f2-dcee-4ca8-9466-7708d0a9b6dd",
   257  				LocalGB:    15,
   258  				MemoryMB:   512,
   259  				Name:       "basic",
   260  				StartedAt:  time.Date(2017, 11, 21, 3, 50, 7, 0, time.UTC),
   261  				EndedAt:    time.Date(2017, 11, 21, 4, 10, 11, 0, time.UTC),
   262  				State:      "terminated",
   263  				TenantID:   "aabbccddeeff112233445566",
   264  				Uptime:     1204,
   265  				VCPUs:      1,
   266  			},
   267  			{
   268  				Flavor:     "m1.acctest",
   269  				Hours:      0.004166666666666667,
   270  				InstanceID: "ceb654fa-e0e8-44fb-8942-e4d0bfad3941",
   271  				LocalGB:    15,
   272  				MemoryMB:   512,
   273  				Name:       "ACPTTESTJSxbPQAC34lTnBE1",
   274  				StartedAt:  time.Date(2017, 11, 30, 3, 21, 6, 0, time.UTC),
   275  				EndedAt:    time.Date(2017, 11, 30, 3, 21, 21, 0, time.UTC),
   276  				State:      "terminated",
   277  				TenantID:   "aabbccddeeff112233445566",
   278  				Uptime:     15,
   279  				VCPUs:      1,
   280  			},
   281  		},
   282  		Start:              time.Date(2017, 11, 2, 3, 25, 1, 0, time.UTC),
   283  		Stop:               time.Date(2017, 11, 30, 3, 25, 1, 0, time.UTC),
   284  		TenantID:           "aabbccddeeff112233445566",
   285  		TotalHours:         1.25834212,
   286  		TotalLocalGBUsage:  18.571675453333334,
   287  		TotalMemoryMBUsage: 644.27116544,
   288  		TotalVCPUsUsage:    1.25834212,
   289  	},
   290  	{
   291  		ServerUsages: []usage.ServerUsage{
   292  			{
   293  				Flavor:     "m1.tiny",
   294  				Hours:      0.021675453333333334,
   295  				InstanceID: "a70096fd-8196-406b-86c4-045840f53ad7",
   296  				LocalGB:    1,
   297  				MemoryMB:   512,
   298  				Name:       "test",
   299  				StartedAt:  time.Date(2017, 11, 30, 3, 23, 43, 0, time.UTC),
   300  				State:      "active",
   301  				TenantID:   "665544332211ffeeddccbbaa",
   302  				Uptime:     78,
   303  				VCPUs:      1,
   304  			},
   305  		},
   306  		Start:              time.Date(2017, 11, 2, 3, 25, 1, 0, time.UTC),
   307  		Stop:               time.Date(2017, 11, 30, 3, 25, 1, 0, time.UTC),
   308  		TenantID:           "665544332211ffeeddccbbaa",
   309  		TotalHours:         0.021675453333333334,
   310  		TotalLocalGBUsage:  18.571675453333334,
   311  		TotalMemoryMBUsage: 644.27116544,
   312  		TotalVCPUsUsage:    1.25834212,
   313  	},
   314  }