Skip to content

Commit 8b64a52

Browse files
authoredFeb 8, 2019
Merge pull request aptible#43 from krallin/add-test-mode
Add a -test flag
2 parents 0ce2c75 + b5b2a27 commit 8b64a52

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed
 

‎README.md

+7
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ WARN[2017-07-11T12:24:32+02:00] job took too long to run: it should have started
204204
```
205205

206206

207+
## Testing your crontab
208+
209+
Use the `-test` flag to prompt Supercronic to verify your crontab, but not
210+
execute it. This is useful as part of e.g. a build process to verify the syntax
211+
of your crontab.
212+
213+
207214
## Questions and Support ###
208215

209216
Please feel free to open an issue in this repository if you have any question

‎integration/invalid.crontab

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oops

‎integration/test.bats

+13
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,16 @@ wait_for() {
7777

7878
wait_for grep "$canary" "$out"
7979
}
80+
81+
@test "it tests a valid crontab" {
82+
timeout 1s "${BATS_TEST_DIRNAME}/../supercronic" -test "${BATS_TEST_DIRNAME}/noop.crontab"
83+
}
84+
85+
@test "it tests an invalid crontab" {
86+
run timeout 1s "${BATS_TEST_DIRNAME}/../supercronic" -test "${BATS_TEST_DIRNAME}/invalid.crontab"
87+
[[ "$status" -eq 1 ]]
88+
}
89+
90+
@test "it errors on an invalid crontab" {
91+
! run_supercronic -test "${BATS_TEST_DIRNAME}/invalid.crontab"
92+
}

‎main.go

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var Usage = func() {
2121
func main() {
2222
debug := flag.Bool("debug", false, "enable debug logging")
2323
json := flag.Bool("json", false, "enable JSON logging")
24+
test := flag.Bool("test", false, "test crontab (does not run jobs)")
2425
flag.Parse()
2526

2627
if *debug {
@@ -49,6 +50,12 @@ func main() {
4950
return
5051
}
5152

53+
if *test {
54+
logrus.Info("crontab is valid")
55+
os.Exit(0)
56+
return
57+
}
58+
5259
var wg sync.WaitGroup
5360
exitCtx, notifyExit := context.WithCancel(context.Background())
5461

0 commit comments

Comments
 (0)
Please sign in to comment.