-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathredis_test.go
199 lines (179 loc) · 5.29 KB
/
redis_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// SPDX-License-Identifier: Apache-2.0
package redis
import (
"fmt"
"testing"
"time"
"github.com/alicebob/miniredis/v2"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"
)
// The following functions were taken from
// https://github.com/go-vela/sdk-go/blob/main/vela/go
// which is the only reason go-vela/sdk-go is
// a dependency for go-vela/server
// TODO: consider moving to go-vela/types?
// Bool is a helper routine that allocates a new boolean
// value to store v and returns a pointer to it.
func Bool(v bool) *bool { return &v }
// Bytes is a helper routine that allocates a new byte
// array value to store v and returns a pointer to it.
func Bytes(v []byte) *[]byte { return &v }
// Int is a helper routine that allocates a new integer
// value to store v and returns a pointer to it.
func Int(v int) *int { return &v }
// Int64 is a helper routine that allocates a new 64 bit
// integer value to store v and returns a pointer to it.
func Int64(v int64) *int64 { return &v }
// String is a helper routine that allocates a new string
// value to store v and returns a pointer to it.
func String(v string) *string { return &v }
// Strings is a helper routine that allocates a new string
// array value to store v and returns a pointer to it.
func Strings(v []string) *[]string { return &v }
// setup global variables used for testing.
var (
_signingPrivateKey = "tCIevHOBq6DdN5SSBtteXUusjjd0fOqzk2eyi0DMq04NewmShNKQeUbbp3vkvIckb4pCxc+vxUo+mYf/vzOaSg=="
_signingPublicKey = "DXsJkoTSkHlG26d75LyHJG+KQsXPr8VKPpmH/78zmko="
_build = &library.Build{
ID: Int64(1),
Number: Int(1),
Parent: Int(1),
Event: String("push"),
Status: String("success"),
Error: String(""),
Enqueued: Int64(1563474077),
Created: Int64(1563474076),
Started: Int64(1563474077),
Finished: Int64(0),
Deploy: String(""),
Clone: String("https://github.com/github/octocat.git"),
Source: String("https://github.com/github/octocat/abcdefghi123456789"),
Title: String("push received from https://github.com/github/octocat"),
Message: String("First commit..."),
Commit: String("48afb5bdc41ad69bf22588491333f7cf71135163"),
Sender: String("OctoKitty"),
Author: String("OctoKitty"),
Branch: String("main"),
Ref: String("refs/heads/main"),
BaseRef: String(""),
Host: String("example.company.com"),
Runtime: String("docker"),
Distribution: String("linux"),
}
_repo = &library.Repo{
ID: Int64(1),
Org: String("github"),
Name: String("octocat"),
FullName: String("github/octocat"),
Link: String("https://github.com/github/octocat"),
Clone: String("https://github.com/github/octocat.git"),
Branch: String("main"),
Timeout: Int64(60),
Visibility: String("public"),
Private: Bool(false),
Trusted: Bool(false),
Active: Bool(true),
AllowPull: Bool(false),
AllowPush: Bool(true),
AllowDeploy: Bool(false),
AllowTag: Bool(false),
}
_steps = &pipeline.Build{
Version: "1",
ID: "github_octocat_1",
Services: pipeline.ContainerSlice{
{
ID: "service_github_octocat_1_postgres",
Directory: "/home/github/octocat",
Environment: map[string]string{"FOO": "bar"},
Image: "postgres:12-alpine",
Name: "postgres",
Number: 1,
Ports: []string{"5432:5432"},
Pull: "not_present",
},
},
Steps: pipeline.ContainerSlice{
{
ID: "step_github_octocat_1_init",
Directory: "/home/github/octocat",
Environment: map[string]string{"FOO": "bar"},
Image: "#init",
Name: "init",
Number: 1,
Pull: "always",
},
{
ID: "step_github_octocat_1_clone",
Directory: "/home/github/octocat",
Environment: map[string]string{"FOO": "bar"},
Image: "target/vela-git:v0.5.1",
Name: "clone",
Number: 2,
Pull: "always",
},
{
ID: "step_github_octocat_1_echo",
Commands: []string{"echo hello"},
Directory: "/home/github/octocat",
Environment: map[string]string{"FOO": "bar"},
Image: "alpine:latest",
Name: "echo",
Number: 3,
Pull: "always",
},
},
}
_user = &library.User{
ID: Int64(1),
Name: String("octocat"),
Token: nil,
Hash: nil,
Active: Bool(true),
Admin: Bool(false),
}
)
func TestRedis_New(t *testing.T) {
// setup types
// create a local fake redis instance
//
// https://pkg.go.dev/github.com/alicebob/miniredis/v2#Run
_redis, err := miniredis.Run()
if err != nil {
t.Errorf("unable to create miniredis instance: %v", err)
}
defer _redis.Close()
// setup tests
tests := []struct {
failure bool
address string
}{
{
failure: false,
address: fmt.Sprintf("redis://%s", _redis.Addr()),
},
{
failure: true,
address: "",
},
}
// run tests
for _, test := range tests {
_, err := New(
WithAddress(test.address),
WithChannels("foo"),
WithCluster(false),
WithTimeout(5*time.Second),
)
if test.failure {
if err == nil {
t.Errorf("New should have returned err")
}
continue
}
if err != nil {
t.Errorf("New returned err: %v", err)
}
}
}