This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
generated from vshn/go-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accumulate_test.go
71 lines (59 loc) · 2.12 KB
/
accumulate_test.go
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
package main
import (
"fmt"
"testing"
"time"
"github.com/cloudscale-ch/cloudscale-go-sdk/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// assertEqualfUint64 implements the functionality of assert.Equalf for uint64, because assert.Equalf cannot print uint64 correctly.
// See https://github.com/stretchr/testify/issues/400
func assertEqualfUint64(t *testing.T, expected uint64, actual uint64, msg string, args ...interface{}) bool {
if expected != actual {
return assert.Fail(t, fmt.Sprintf("Not equal: \n"+
"expected: %d\n"+
"actual : %d", expected, actual))
}
return true
}
func TestAccumulateBucketMetricsForObjectsUser(t *testing.T) {
zone := "cloudscale"
organization := "inity"
namespace := "testnamespace"
// get the correct date for a data set that was created yesterday
location, err := time.LoadLocation("Europe/Zurich")
require.NoError(t, err, "could not load location Europe/Zurich")
now := time.Now().In(location)
date := time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, now.Location())
// build input data structure
bucketMetricsInterval := []cloudscale.BucketMetricsInterval{
{
Start: date,
End: date,
Usage: cloudscale.BucketMetricsIntervalUsage{
Requests: 5,
StorageBytes: 1000000,
SentBytes: 2000000,
},
},
}
bucketMetricsData := cloudscale.BucketMetricsData{
TimeSeries: bucketMetricsInterval,
}
accumulated := make(map[AccumulateKey]uint64)
assert.NoError(t, accumulateBucketMetricsForObjectsUser(accumulated, bucketMetricsData, organization, namespace))
require.Len(t, accumulated, 3, "incorrect amount of values 'accumulated'")
key := AccumulateKey{
Zone: zone,
Tenant: organization,
Namespace: namespace,
Start: date,
}
key.Query = "object-storage-requests"
assertEqualfUint64(t, uint64(5), accumulated[key], "incorrect value in %s", key)
key.Query = "object-storage-storage"
assertEqualfUint64(t, uint64(1000000), accumulated[key], "incorrect value in %s", key)
key.Query = "object-storage-traffic-out"
assertEqualfUint64(t, uint64(2000000), accumulated[key], "incorrect value in %s", key)
}