-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrabbit_test.go
90 lines (62 loc) · 2.09 KB
/
rabbit_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
package rabbit
import (
"errors"
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestGeneratePublicProperty(t *testing.T) {
params := []Param{
{Type: "public", Name: "paramName", Value: "paramValue"},
}
c := Config{Job: "testJob"}
generatedParams := c.generateProperty(params...)
expectedParams := "s:9:\"paramName\";s:10:\"paramValue\";"
assert.Equal(t, expectedParams, generatedParams)
}
func TestGenerateInvalidProperty(t *testing.T) {
params := []Param{
{Type: "invalid", Name: "paramName", Value: "paramValue"},
}
c := Config{Job: "testJob"}
generatedParams := c.generateProperty(params...)
expectedParams := "s:9:\"paramName\";s:10:\"paramValue\";"
assert.Equal(t, expectedParams, generatedParams)
}
func TestGenerateProtectedProperty(t *testing.T) {
params := []Param{
{Type: "protected", Name: "paramName", Value: "paramValue"},
}
c := Config{Job: "testJob"}
generatedParams := c.generateProperty(params...)
expectedParams := fmt.Sprintf("s:%d:\"\u0000*\u0000%s\";s:%d:\"%s\";", len("paramName")+3, "paramName", len("paramValue"), "paramValue")
assert.Equal(t, expectedParams, generatedParams)
}
func TestGeneratePrivateProperty(t *testing.T) {
params := []Param{
{Type: "private", Name: "paramName", Value: "paramValue"},
}
c := Config{Job: "testJob"}
generatedParams := c.generateProperty(params...)
expectedParams := fmt.Sprintf("s:%d:\"\u0000%s\u0000%s\";s:%d:\"%s\";", len(c.Job)+2, c.Job, "paramName", len("paramValue"), "paramValue")
assert.Equal(t, expectedParams, generatedParams)
}
func TestDelay(t *testing.T) {
c := Config{Delay: 5}
expected := fmt.Sprintf("i:%d;", c.Delay)
assert.Equal(t, expected, c.generateDelay())
}
func TestNoDelay(t *testing.T) {
c := Config{Delay: 0}
expected := "N;"
assert.Equal(t, expected, c.generateDelay())
}
func TestEmptyAppName(t *testing.T) {
params := []Param{
{Type: "protected", Name: "paramName", Value: "paramValue"},
}
c := Config{}
generatedParams := c.Dispatch(params...)
expectedParams := errors.New("AppName is required in config")
assert.Equal(t, expectedParams, generatedParams)
}