-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
95 lines (85 loc) · 1.98 KB
/
utils_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"testing"
)
// CreditToFileUploadSize()
var creditToBytes = []struct {
credit float64
bytes int
}{
{0.0, freeFileUploadBytes},
{5.0, MegabytesToBytes(2750)},
{7.5, MegabytesToBytes(4000)},
}
func TestCreditToFileUploadSize(t *testing.T) {
for _, tt := range creditToBytes {
t.Run(fmt.Sprintf("%f", tt.credit), func(t *testing.T) {
v := CreditToFileUploadSize(float64(tt.credit))
if v != tt.bytes {
t.Errorf("got %v, wanted %v", v, tt.bytes)
}
})
}
}
// CreditToBandwidth()
var creditToBandwidth = []struct {
credit float64
bandwidth int
}{
{0.0, freeBandwidthBytes},
{5.0, MegabytesToBytes(27500)},
{7.5, MegabytesToBytes(40000)},
}
func TestCreditToBandwidth(t *testing.T) {
for _, tt := range creditToBandwidth {
t.Run(fmt.Sprintf("%f", tt.credit), func(t *testing.T) {
v := CreditToBandwidth(float64(tt.credit))
if v != tt.bandwidth {
t.Errorf("got %v, wanted %v", v, tt.bandwidth)
}
})
}
}
// BytesToReadable()
var bytesToReadable = []struct {
bytes int
readable string
}{
{0, "0 bytes"},
{1, "1 bytes"},
{MegabytesToBytes(8000), "8 GB"},
{MegabytesToBytes(1), "1 MB"},
}
func TestBytesToReadable(t *testing.T) {
for _, tt := range bytesToReadable {
t.Run(fmt.Sprintf("%d", tt.bytes), func(t *testing.T) {
v := BytesToReadable(tt.bytes)
if v != tt.readable {
t.Errorf("got %v, wanted %v", v, tt.readable)
}
})
}
}
func TestBytesToMegabytes(t *testing.T) {
MB := BytesToMegabytes(10000)
if MB != 0.01 {
t.Errorf("got %f, wanted %f", MB, 0.01)
}
}
func TestUpdateErr(t *testing.T) {
// invalid UUID so shouldn't update any rows
err := UpdateErr(s.db.Exec(`
UPDATE user
SET UUID_key=''
WHERE UUID = ?
`, "notauuid"))
if err == nil {
t.Errorf("Should have failed because there will never be a uuid value of 'notauuid'")
}
// should fail because invalid SQL is passed
err = UpdateErr(s.db.Exec(`NOT valid SQL`))
if err == nil {
t.Errorf("Should have failed because of invalid SQL")
}
}