-
Notifications
You must be signed in to change notification settings - Fork 8
/
job_test.go
76 lines (64 loc) · 1.8 KB
/
job_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
package curlyq
import (
"github.com/gofrs/uuid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Job", func() {
var job *Job
Describe("message", func() {
BeforeEach(func() {
job = &Job{
ID: "TestID",
Attempt: 1,
Data: []byte("TestData"),
}
})
It("Encodes the job data correctly", func() {
msg, err := job.message()
Expect(err).NotTo(HaveOccurred())
Expect(msg).To(Equal([]byte{131, 162, 73, 68, 166, 84, 101, 115, 116, 73, 68, 164, 68, 97, 116, 97, 196, 8, 84, 101, 115, 116, 68, 97, 116, 97, 167, 65, 116, 116, 101, 109, 112, 116, 211, 0, 0, 0, 0, 0, 0, 0, 1}))
})
Context("When an ID is not provided", func() {
BeforeEach(func() {
job = &Job{
Data: []byte("Test"),
}
})
It("Sets it to a random UUID", func() {
job.message()
Expect(job.ID).NotTo(Equal(""))
_, err := uuid.FromString(job.ID)
Expect(err).NotTo(HaveOccurred())
})
})
Context("When an ID is provided", func() {
BeforeEach(func() {
job = &Job{
Data: []byte("Test"),
ID: "TestID",
}
})
It("Does not change it", func() {
job.message()
Expect(job.ID).To(Equal("TestID"))
})
})
})
Describe("FromMessage", func() {
BeforeEach(func() {
job = &Job{}
Expect(job.ID).To(Equal(""))
Expect(job.Data).To(BeNil())
Expect(job.Attempt).To(Equal(0))
})
It("Decodes the job data correctly", func() {
bytes := []byte{131, 162, 73, 68, 166, 84, 101, 115, 116, 73, 68, 164, 68, 97, 116, 97, 168, 84, 101, 115, 116, 68, 97, 116, 97, 167, 65, 116, 116, 101, 109, 112, 116, 207, 0, 0, 0, 0, 0, 0, 0, 1}
err := job.fromMessage(bytes)
Expect(err).NotTo(HaveOccurred())
Expect(job.ID).To(Equal("TestID"))
Expect(job.Attempt).To(Equal(1))
Expect(string(job.Data)).To(Equal("TestData"))
})
})
})