This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcodesigner_service_test.go
76 lines (68 loc) · 1.64 KB
/
codesigner_service_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 codesigner
import (
"fmt"
"os"
"os/exec"
"strconv"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
const (
unsignedPath = "/some/path/to/a/clementine.dmg"
)
func fakeExecCommand(exitCode int) func(string, ...string) *exec.Cmd {
return func(command string, args ...string) *exec.Cmd {
cs := []string{"-test.run=TestHelperProcess", "--", command}
cs = append(cs, args...)
cmd := exec.Command(os.Args[0], cs...)
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1", fmt.Sprintf("GO_WANT_EXIT_CODE=%d", exitCode)}
return cmd
}
}
func TestUnlockKeychain(t *testing.T) {
Convey("Unlock keychain success", t, func() {
execCommand = fakeExecCommand(0)
defer func() { execCommand = exec.Command }()
_, err := unlockKeychain("foo", "bar")
So(err, ShouldBeNil)
})
Convey("Unlock keychain fails", t, func() {
execCommand = fakeExecCommand(1)
defer func() { execCommand = exec.Command }()
_, err := unlockKeychain("foo", "bar")
So(err, ShouldNotBeNil)
})
}
func TestHelperProcess(t *testing.T) {
Convey("Test helper process", t, func() {
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
return
}
exitEnv, ok := os.LookupEnv("GO_WANT_EXIT_CODE")
if !ok {
defer os.Exit(0)
} else {
exitCode, err := strconv.Atoi(exitEnv)
if err != nil {
defer os.Exit(0)
} else {
defer os.Exit(exitCode)
}
}
args := os.Args
for len(args) > 0 {
if args[0] == "--" {
args = args[1:]
break
}
args = args[1:]
}
cmd, args := args[0], args[1:]
switch cmd {
case "codesign":
So(args[1], ShouldEqual, "-fv")
So(args[2], ShouldEqual, "-s")
So(args[3], ShouldEqual, unsignedPath)
}
})
}