File: object_storage_quota_test.go

package info (click to toggle)
golang-github-linode-linodego 1.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,112 kB
  • sloc: makefile: 96; sh: 52; python: 24
file content (84 lines) | stat: -rw-r--r-- 2,994 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package integration

import (
	"context"
	"testing"

	"github.com/linode/linodego"
	"github.com/stretchr/testify/assert"
)

func TestObjectStorageQuotas_Get(t *testing.T) {
	client, teardown := createTestClient(t, "fixtures/TestObjectStorageQuotas_Get")
	defer teardown()

	quota, err := client.GetObjectStorageQuota(context.Background(), "obj-objects-us-ord-1.linodeobjects.com")
	assert.NoError(t, err)

	expected := linodego.ObjectStorageQuota{
		QuotaID:        "obj-objects-us-ord-1.linodeobjects.com",
		QuotaName:      "max_objects",
		EndpointType:   "E1",
		S3Endpoint:     "us-ord-1.linodeobjects.com",
		Description:    "Maximum number of objects this customer is allowed to have on this endpoint",
		QuotaLimit:     100000000,
		ResourceMetric: "object",
	}

	assert.Equal(t, expected.QuotaID, quota.QuotaID)
	assert.Equal(t, expected.QuotaName, quota.QuotaName)
	assert.Equal(t, expected.EndpointType, quota.EndpointType)
	assert.Equal(t, expected.S3Endpoint, quota.S3Endpoint)
	assert.Equal(t, expected.Description, quota.Description)
	assert.Equal(t, expected.QuotaLimit, quota.QuotaLimit)
	assert.Equal(t, expected.ResourceMetric, quota.ResourceMetric)
}

func TestObjectStorageQuotas_List(t *testing.T) {
	client, teardown := createTestClient(t, "fixtures/TestObjectStorageQuotas_List")
	defer teardown()

	quotas, err := client.ListObjectStorageQuotas(context.Background(), &linodego.ListOptions{})
	assert.NoError(t, err, "Error listing ObjectStorageQuotas")

	targetQuotaID := "obj-buckets-us-mia-1.linodeobjects.com"
	var foundQuota *linodego.ObjectStorageQuota

	for _, quota := range quotas {
		if quota.QuotaID == targetQuotaID {
			foundQuota = &quota
			break
		}
	}

	if assert.NotNil(t, foundQuota, "Expected quota_id %q not found", targetQuotaID) {
		expected := linodego.ObjectStorageQuota{
			QuotaID:        "obj-buckets-us-mia-1.linodeobjects.com",
			QuotaName:      "max_buckets",
			EndpointType:   "E1",
			S3Endpoint:     "us-mia-1.linodeobjects.com",
			Description:    "Maximum number of buckets this customer is allowed to have on this endpoint",
			QuotaLimit:     1000,
			ResourceMetric: "bucket",
		}

		assert.Equal(t, expected.QuotaID, foundQuota.QuotaID)
		assert.Equal(t, expected.QuotaName, foundQuota.QuotaName)
		assert.Equal(t, expected.EndpointType, foundQuota.EndpointType)
		assert.Equal(t, expected.S3Endpoint, foundQuota.S3Endpoint)
		assert.Equal(t, expected.Description, foundQuota.Description)
		assert.Equal(t, expected.QuotaLimit, foundQuota.QuotaLimit)
		assert.Equal(t, expected.ResourceMetric, foundQuota.ResourceMetric)
	}
}

func TestObjectStorageQuotaUsage_Get(t *testing.T) {
	client, teardown := createTestClient(t, "fixtures/TestObjectStorageQuotaUsage_Get")
	defer teardown()

	quotaUsage, err := client.GetObjectStorageQuotaUsage(context.Background(), "obj-objects-us-ord-1.linodeobjects.com")
	assert.NoError(t, err)

	assert.Equal(t, 100000000, quotaUsage.QuotaLimit)
	assert.GreaterOrEqual(t, *quotaUsage.Usage, 0)
}