-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_limit_test.go
More file actions
38 lines (34 loc) · 828 Bytes
/
parse_limit_test.go
File metadata and controls
38 lines (34 loc) · 828 Bytes
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
package main
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseLimit(t *testing.T) {
happyCases := map[string]int64{
"1500": 1500,
"1M": 1024 * 1024,
"250M": 250 * 1024 * 1024,
"1K": 1024,
"0K": 0,
"1500K": 1500 * 1024,
"1G": 1024 * 1024 * 1024,
"23G": 1024 * 1024 * 1024 * 23,
}
assert := assert.New(t)
for in, out := range happyCases {
got, err := parseLimit(in)
assert.Nil(err)
assert.Equal(out, got, "parseLimit("+in+")")
}
}
func TestParseLimitErrors(t *testing.T) {
invalidFormat := []string{"70T", "600KK", "6001L", "K", "M", "G"}
for _, in := range invalidFormat {
_, err := parseLimit(in)
if !errors.Is(err, errLimitFormat) {
t.Errorf("Expected errLimitFormat (%s), but got %s",
errLimitFormat.Error(), err.Error())
}
}
}