-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresource_test.go
82 lines (57 loc) · 1.66 KB
/
resource_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
package strive
import (
"testing"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vektra/neko"
)
func TestResource(t *testing.T) {
n := neko.Start(t)
n.It("can remove partial resources", func() {
r1 := &Resource{
Type: Resource_CPU.Enum(),
Value: NewIntValue(4),
}
r2 := &Resource{
Type: Resource_CPU.Enum(),
Value: NewIntValue(1),
}
r3, err := r1.Remove(r2)
require.NoError(t, err)
assert.Equal(t, 3, r3.GetValue().GetIntVal())
})
n.Meow()
}
func TestRange(t *testing.T) {
n := neko.Start(t)
full := &Ranges{Ranges: []*Range{{Start: proto.Int64(1000), End: proto.Int64(2000)}}}
n.It("returns a new range by subtracting one from another", func() {
a := &Ranges{Ranges: []*Range{{Start: proto.Int64(1000), End: proto.Int64(1010)}}}
out, err := full.Remove(a)
require.NoError(t, err)
x := out.Ranges[0]
assert.Equal(t, 1011, x.GetStart())
assert.Equal(t, 2000, x.GetEnd())
})
n.It("splits a range in 2", func() {
a := &Ranges{Ranges: []*Range{{Start: proto.Int64(1010), End: proto.Int64(1020)}}}
out, err := full.Remove(a)
require.NoError(t, err)
x := out.Ranges[0]
assert.Equal(t, 1000, x.GetStart())
assert.Equal(t, 1009, x.GetEnd())
x = out.Ranges[1]
assert.Equal(t, 1021, x.GetStart())
assert.Equal(t, 2000, x.GetEnd())
})
n.It("subtracts a range at the end of another", func() {
a := &Ranges{Ranges: []*Range{{Start: proto.Int64(1900), End: proto.Int64(2000)}}}
out, err := full.Remove(a)
require.NoError(t, err)
x := out.Ranges[0]
assert.Equal(t, 1000, x.GetStart())
assert.Equal(t, 1899, x.GetEnd())
})
n.Meow()
}