File: account_test.go

package info (click to toggle)
golang-github-ncw-go-acd 0.0~git20161119.0.7954f1f-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 104 kB
  • ctags: 94
  • sloc: makefile: 40
file content (115 lines) | stat: -rw-r--r-- 2,717 bytes parent folder | download | duplicates (3)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (c) 2015 Serge Gebhardt. All rights reserved.
//
// Use of this source code is governed by the ISC
// license that can be found in the LICENSE file.

package acd

import (
	"testing"

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

func TestAccount_getInfo(t *testing.T) {
	r := *NewMockResponseOkString(`{ "termsOfUse": "1.0.0", "status": "ACTIVE" }`)
	c := NewMockClient(r)

	info, _, err := c.Account.GetInfo()

	assert.NoError(t, err)
	assert.Equal(t, "ACTIVE", *info.Status)
	assert.Equal(t, "1.0.0", *info.TermsOfUse)
}

func TestAccount_getQuota(t *testing.T) {
	r := *NewMockResponseOkString(`
{
	"quota": 5368709120,
	"lastCalculated": "2014-08-13T23:01:47.479Z",
	"available": 4069088896
}
	`)
	c := NewMockClient(r)

	quota, _, err := c.Account.GetQuota()

	assert.NoError(t, err)
	assert.Equal(t, "2014-08-13 23:01:47.479 +0000 UTC", quota.LastCalculated.String())
	assert.Equal(t, uint64(5368709120), *quota.Quota)
	assert.Equal(t, uint64(4069088896), *quota.Available)
}

func TestAccount_getUsage(t *testing.T) {
	r := *NewMockResponseOkString(`
{
	"lastCalculated":"2014-08-13T23:17:41.365Z",
	"other":{
		"total":{
			"bytes":29999771,
			"count":871
		},
		"billable":{
			"bytes":29999771,
			"count":871
		}
	},
	"doc":{
		"total":{
			"bytes":807170,
			"count":10
		},
		"billable":{
			"bytes":807170,
			"count":10
		}
	},
	"photo":{
		"total":{
			"bytes":9477988,
			"count":25
		},
		"billable":{
			"bytes":9477988,
			"count":25
		}
	},
	"video":{
		"total":{
			"bytes":23524252,
			"count":22
		},
		"billable":{
			"bytes":23524252,
			"count":22
		}
	}
}
	`)
	c := NewMockClient(r)

	usage, _, err := c.Account.GetUsage()

	assert.NoError(t, err)
	assert.Equal(t, "2014-08-13 23:17:41.365 +0000 UTC", usage.LastCalculated.String())

	assert.Equal(t, uint64(29999771), *usage.Other.Total.Bytes)
	assert.Equal(t, uint64(871), *usage.Other.Total.Count)
	assert.Equal(t, uint64(29999771), *usage.Other.Billable.Bytes)
	assert.Equal(t, uint64(871), *usage.Other.Billable.Count)

	assert.Equal(t, uint64(807170), *usage.Doc.Total.Bytes)
	assert.Equal(t, uint64(10), *usage.Doc.Total.Count)
	assert.Equal(t, uint64(807170), *usage.Doc.Billable.Bytes)
	assert.Equal(t, uint64(10), *usage.Doc.Billable.Count)

	assert.Equal(t, uint64(9477988), *usage.Photo.Total.Bytes)
	assert.Equal(t, uint64(25), *usage.Photo.Total.Count)
	assert.Equal(t, uint64(9477988), *usage.Photo.Billable.Bytes)
	assert.Equal(t, uint64(25), *usage.Photo.Billable.Count)

	assert.Equal(t, uint64(23524252), *usage.Video.Total.Bytes)
	assert.Equal(t, uint64(22), *usage.Video.Total.Count)
	assert.Equal(t, uint64(23524252), *usage.Video.Billable.Bytes)
	assert.Equal(t, uint64(22), *usage.Video.Billable.Count)
}