-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchunker_test.go
75 lines (71 loc) · 1.73 KB
/
chunker_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
package policy_client_test
import (
"code.cloudfoundry.org/policy_client"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("SimpleChunker", func() {
var (
chunker policy_client.SimpleChunker
policies []policy_client.PolicyV0
)
BeforeEach(func() {
policies = []policy_client.PolicyV0{
{
Source: policy_client.SourceV0{
ID: "some-app-guid",
},
Destination: policy_client.DestinationV0{
ID: "some-other-app-guid",
Port: 8090,
Protocol: "tcp",
},
},
{
Source: policy_client.SourceV0{
ID: "some-app-guid-2",
},
Destination: policy_client.DestinationV0{
ID: "some-other-app-guid-2",
Port: 8091,
Protocol: "tcp",
},
},
{
Source: policy_client.SourceV0{
ID: "some-app-guid-3",
},
Destination: policy_client.DestinationV0{
ID: "some-other-app-guid-3",
Port: 8092,
Protocol: "tcp",
},
},
}
})
Context("when the policies do not chunk evenly", func() {
BeforeEach(func() {
chunker = policy_client.SimpleChunker{
ChunkSize: 2,
}
})
It("returns the last chunk as smaller than ChunkSize", func() {
chunkedPolicies := chunker.Chunk(policies)
Expect(len(chunkedPolicies)).To(Equal(2))
Expect(chunkedPolicies[0]).To(Equal(policies[0:2]))
Expect(chunkedPolicies[1]).To(Equal(policies[2:]))
})
})
Context("when the ChunkSize is zero", func() {
BeforeEach(func() {
chunker = policy_client.SimpleChunker{
ChunkSize: 0,
}
})
It("chunks with a chunk size of DefaultMaxPolicies", func() {
chunkedPolicies := chunker.Chunk(policies)
Expect(len(chunkedPolicies)).To(Equal(1))
Expect(chunkedPolicies[0]).To(Equal(policies))
})
})
})