@@ -10,6 +10,7 @@ import (
10
10
"testing"
11
11
12
12
"github.com/github/git-bundle-server/internal/daemon"
13
+ . "github.com/github/git-bundle-server/internal/testhelpers"
13
14
"github.com/stretchr/testify/assert"
14
15
"github.com/stretchr/testify/mock"
15
16
)
@@ -19,14 +20,14 @@ var launchdCreateBehaviorTests = []struct {
19
20
20
21
// Inputs
21
22
config * daemon.DaemonConfig
22
- force boolArg
23
+ force BoolArg
23
24
24
25
// Mocked responses
25
- fileExists []pair [bool , error ]
26
+ fileExists []Pair [bool , error ]
26
27
writeFile []error
27
- launchctlPrint []pair [int , error ]
28
- launchctlBootstrap []pair [int , error ]
29
- launchctlBootout []pair [int , error ]
28
+ launchctlPrint []Pair [int , error ]
29
+ launchctlBootstrap []Pair [int , error ]
30
+ launchctlBootout []Pair [int , error ]
30
31
31
32
// Expected values
32
33
expectErr bool
@@ -35,66 +36,66 @@ var launchdCreateBehaviorTests = []struct {
35
36
"Fresh config created if none exists" ,
36
37
& basicDaemonConfig ,
37
38
Any ,
38
- []pair [bool , error ]{newPair [bool , error ](false , nil )}, // file exists
39
+ []Pair [bool , error ]{NewPair [bool , error ](false , nil )}, // file exists
39
40
[]error {nil }, // write file
40
- []pair [int , error ]{newPair [int , error ](daemon .LaunchdServiceNotFoundErrorCode , nil )}, // launchctl print (isBootstrapped)
41
- []pair [int , error ]{newPair [int , error ](0 , nil )}, // launchctl bootstrap
42
- []pair [int , error ]{}, // launchctl bootout
41
+ []Pair [int , error ]{NewPair [int , error ](daemon .LaunchdServiceNotFoundErrorCode , nil )}, // launchctl print (isBootstrapped)
42
+ []Pair [int , error ]{NewPair [int , error ](0 , nil )}, // launchctl bootstrap
43
+ []Pair [int , error ]{}, // launchctl bootout
43
44
false ,
44
45
},
45
46
{
46
47
"Config exists & is not bootstrapped doesn't write file, bootstraps" ,
47
48
& basicDaemonConfig ,
48
49
False ,
49
- []pair [bool , error ]{newPair [bool , error ](true , nil )}, // file exists
50
+ []Pair [bool , error ]{NewPair [bool , error ](true , nil )}, // file exists
50
51
[]error {}, // write file
51
- []pair [int , error ]{newPair [int , error ](daemon .LaunchdServiceNotFoundErrorCode , nil )}, // launchctl print (isBootstrapped)
52
- []pair [int , error ]{newPair [int , error ](0 , nil )}, // launchctl bootstrap
53
- []pair [int , error ]{}, // launchctl bootout
52
+ []Pair [int , error ]{NewPair [int , error ](daemon .LaunchdServiceNotFoundErrorCode , nil )}, // launchctl print (isBootstrapped)
53
+ []Pair [int , error ]{NewPair [int , error ](0 , nil )}, // launchctl bootstrap
54
+ []Pair [int , error ]{}, // launchctl bootout
54
55
false ,
55
56
},
56
57
{
57
58
"'force' option overwrites file and bootstraps when not already bootstrapped" ,
58
59
& basicDaemonConfig ,
59
60
True ,
60
- []pair [bool , error ]{newPair [bool , error ](true , nil )}, // file exists
61
+ []Pair [bool , error ]{NewPair [bool , error ](true , nil )}, // file exists
61
62
[]error {nil }, // write file
62
- []pair [int , error ]{newPair [int , error ](daemon .LaunchdServiceNotFoundErrorCode , nil )}, // launchctl print (isBootstrapped)
63
- []pair [int , error ]{newPair [int , error ](0 , nil )}, // launchctl bootstrap
64
- []pair [int , error ]{}, // launchctl bootout
63
+ []Pair [int , error ]{NewPair [int , error ](daemon .LaunchdServiceNotFoundErrorCode , nil )}, // launchctl print (isBootstrapped)
64
+ []Pair [int , error ]{NewPair [int , error ](0 , nil )}, // launchctl bootstrap
65
+ []Pair [int , error ]{}, // launchctl bootout
65
66
false ,
66
67
},
67
68
{
68
69
"Config exists & already bootstrapped does nothing" ,
69
70
& basicDaemonConfig ,
70
71
False ,
71
- []pair [bool , error ]{newPair [bool , error ](true , nil )}, // file exists
72
+ []Pair [bool , error ]{NewPair [bool , error ](true , nil )}, // file exists
72
73
[]error {}, // write file
73
- []pair [int , error ]{newPair [int , error ](0 , nil )}, // launchctl print (isBootstrapped)
74
- []pair [int , error ]{}, // launchctl bootstrap
75
- []pair [int , error ]{}, // launchctl bootout
74
+ []Pair [int , error ]{NewPair [int , error ](0 , nil )}, // launchctl print (isBootstrapped)
75
+ []Pair [int , error ]{}, // launchctl bootstrap
76
+ []Pair [int , error ]{}, // launchctl bootout
76
77
false ,
77
78
},
78
79
{
79
80
"'force' option unloads config, overwrites file, and bootstraps" ,
80
81
& basicDaemonConfig ,
81
82
True ,
82
- []pair [bool , error ]{newPair [bool , error ](true , nil )}, // file exists
83
+ []Pair [bool , error ]{NewPair [bool , error ](true , nil )}, // file exists
83
84
[]error {nil }, // write file
84
- []pair [int , error ]{newPair [int , error ](0 , nil )}, // launchctl print (isBootstrapped)
85
- []pair [int , error ]{newPair [int , error ](0 , nil )}, // launchctl bootstrap
86
- []pair [int , error ]{newPair [int , error ](0 , nil )}, // launchctl bootout
85
+ []Pair [int , error ]{NewPair [int , error ](0 , nil )}, // launchctl print (isBootstrapped)
86
+ []Pair [int , error ]{NewPair [int , error ](0 , nil )}, // launchctl bootstrap
87
+ []Pair [int , error ]{NewPair [int , error ](0 , nil )}, // launchctl bootout
87
88
false ,
88
89
},
89
90
{
90
91
"Config missing & already bootstrapped throws error" ,
91
92
& basicDaemonConfig ,
92
93
Any ,
93
- []pair [bool , error ]{newPair [bool , error ](false , nil )}, // file exists
94
+ []Pair [bool , error ]{NewPair [bool , error ](false , nil )}, // file exists
94
95
[]error {}, // write file
95
- []pair [int , error ]{newPair [int , error ](0 , nil )}, // launchctl print (isBootstrapped)
96
- []pair [int , error ]{}, // launchctl bootstrap
97
- []pair [int , error ]{}, // launchctl bootout
96
+ []Pair [int , error ]{NewPair [int , error ](0 , nil )}, // launchctl print (isBootstrapped)
97
+ []Pair [int , error ]{}, // launchctl bootstrap
98
+ []Pair [int , error ]{}, // launchctl bootout
98
99
true ,
99
100
},
100
101
}
@@ -220,43 +221,43 @@ func TestLaunchd_Create(t *testing.T) {
220
221
Username : "testuser" ,
221
222
HomeDir : "/my/test/dir" ,
222
223
}
223
- testUserProvider := & mockUserProvider {}
224
+ testUserProvider := & MockUserProvider {}
224
225
testUserProvider .On ("CurrentUser" ).Return (testUser , nil )
225
226
226
- testCommandExecutor := & mockCommandExecutor {}
227
+ testCommandExecutor := & MockCommandExecutor {}
227
228
228
- testFileSystem := & mockFileSystem {}
229
+ testFileSystem := & MockFileSystem {}
229
230
230
231
launchd := daemon .NewLaunchdProvider (testUserProvider , testCommandExecutor , testFileSystem )
231
232
232
233
// Verify launchd commands called
233
234
for _ , tt := range launchdCreateBehaviorTests {
234
- forceArg := tt .force .toBoolList ()
235
+ forceArg := tt .force .ToBoolList ()
235
236
for _ , force := range forceArg {
236
237
t .Run (fmt .Sprintf ("%s (force='%t')" , tt .title , force ), func (t * testing.T ) {
237
238
// Mock responses
238
239
for _ , retVal := range tt .launchctlPrint {
239
240
testCommandExecutor .On ("Run" ,
240
241
"launchctl" ,
241
242
mock .MatchedBy (func (args []string ) bool { return args [0 ] == "print" }),
242
- ).Return (retVal .first , retVal .second ).Once ()
243
+ ).Return (retVal .First , retVal .Second ).Once ()
243
244
}
244
245
for _ , retVal := range tt .launchctlBootstrap {
245
246
testCommandExecutor .On ("Run" ,
246
247
"launchctl" ,
247
248
mock .MatchedBy (func (args []string ) bool { return args [0 ] == "bootstrap" }),
248
- ).Return (retVal .first , retVal .second ).Once ()
249
+ ).Return (retVal .First , retVal .Second ).Once ()
249
250
}
250
251
for _ , retVal := range tt .launchctlBootout {
251
252
testCommandExecutor .On ("Run" ,
252
253
"launchctl" ,
253
254
mock .MatchedBy (func (args []string ) bool { return args [0 ] == "bootout" }),
254
- ).Return (retVal .first , retVal .second ).Once ()
255
+ ).Return (retVal .First , retVal .Second ).Once ()
255
256
}
256
257
for _ , retVal := range tt .fileExists {
257
258
testFileSystem .On ("FileExists" ,
258
259
mock .AnythingOfType ("string" ),
259
- ).Return (retVal .first , retVal .second ).Once ()
260
+ ).Return (retVal .First , retVal .Second ).Once ()
260
261
}
261
262
for _ , retVal := range tt .writeFile {
262
263
testFileSystem .On ("WriteFile" ,
@@ -347,10 +348,10 @@ func TestLaunchd_Start(t *testing.T) {
347
348
Uid : "123" ,
348
349
Username : "testuser" ,
349
350
}
350
- testUserProvider := & mockUserProvider {}
351
+ testUserProvider := & MockUserProvider {}
351
352
testUserProvider .On ("CurrentUser" ).Return (testUser , nil )
352
353
353
- testCommandExecutor := & mockCommandExecutor {}
354
+ testCommandExecutor := & MockCommandExecutor {}
354
355
355
356
launchd := daemon .NewLaunchdProvider (testUserProvider , testCommandExecutor , nil )
356
357
@@ -388,10 +389,10 @@ func TestLaunchd_Stop(t *testing.T) {
388
389
Uid : "123" ,
389
390
Username : "testuser" ,
390
391
}
391
- testUserProvider := & mockUserProvider {}
392
+ testUserProvider := & MockUserProvider {}
392
393
testUserProvider .On ("CurrentUser" ).Return (testUser , nil )
393
394
394
- testCommandExecutor := & mockCommandExecutor {}
395
+ testCommandExecutor := & MockCommandExecutor {}
395
396
396
397
launchd := daemon .NewLaunchdProvider (testUserProvider , testCommandExecutor , nil )
397
398
0 commit comments