-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_test.go
127 lines (111 loc) · 2.38 KB
/
env_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
// SPDX-FileCopyrightText: 2021 M. Shulhan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
package karajo
import (
"encoding/json"
"testing"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
func TestLoadEnv(t *testing.T) {
var (
tdata *test.Data
env *Env
got []byte
exp []byte
err error
)
tdata, err = test.LoadData(`testdata/environment_test.txt`)
if err != nil {
t.Fatal(err)
}
env, err = LoadEnv(`testdata/karajo.conf`)
if err != nil {
t.Fatal(err)
}
err = env.initDirs()
if err != nil {
t.Fatal(err)
}
err = env.loadJobd()
if err != nil {
t.Fatal(err)
}
err = env.loadJobHTTPd()
if err != nil {
t.Fatal(err)
}
got, err = json.MarshalIndent(env, ``, ` `)
if err != nil {
t.Fatal(err)
}
exp = tdata.Output[`environment.json`]
test.Assert(t, `LoadEnv`, string(exp), string(got))
}
func TestEnv_loadJobs(t *testing.T) {
var (
env = &Env{
dirConfigJobd: `testdata/etc/karajo/job.d`,
}
expJobs = map[string]*JobExec{
`Scheduler hourly 5m`: &JobExec{
JobBase: JobBase{
Schedule: `hourly@0,5,10,15,20,25,30,35,40,45,50,55`,
},
Path: `/scheduler-hourly-5m`,
Secret: `s3cret`,
Commands: []string{
`echo Test job scheduler hourly per 5m`,
},
},
`Scheduler minutely`: &JobExec{
JobBase: JobBase{
Schedule: `minutely`,
},
Secret: `s3cret`,
Path: `/scheduler-minutely`,
Commands: []string{
`echo Test job scheduler per minute`,
},
},
`Test auth_kind github`: &JobExec{
AuthKind: `github`,
Path: `/github`,
Secret: `s3cret`,
Commands: []string{
`echo auth_kind is github`,
},
},
`test success`: &JobExec{
Path: `/test-success`,
Secret: `s3cret`,
Commands: []string{
`echo Test job success`,
`echo Counter is $KARAJO_JOB_COUNTER`,
`x=$(($RANDOM%10)) && echo sleep in ${x}s && sleep $x`,
},
},
`notif-email-success`: &JobExec{
JobBase: JobBase{
Description: `Send notification when job success.`,
NotifOnSuccess: []string{
`email-to-shulhan`,
`email-to-ops`,
},
NotifOnFailed: []string{
`email-to-shulhan`,
},
},
Path: `/notif-email-success`,
Commands: []string{
`echo Test email notification`,
},
},
}
err error
)
err = env.loadJobd()
if err != nil {
t.Fatal(err)
}
test.Assert(t, `loadJobs`, expJobs, env.ExecJobs)
}