Add a -test flag

This allows verifying the syntax of a crontab, without running it.
This commit is contained in:
Thomas Orozco
2019-01-07 19:23:44 +01:00
parent 0ce2c75096
commit b5b2a274d8
4 changed files with 28 additions and 0 deletions

View File

@@ -204,6 +204,13 @@ WARN[2017-07-11T12:24:32+02:00] job took too long to run: it should have started
```
## Testing your crontab
Use the `-test` flag to prompt Supercronic to verify your crontab, but not
execute it. This is useful as part of e.g. a build process to verify the syntax
of your crontab.
## Questions and Support ###
Please feel free to open an issue in this repository if you have any question

View File

@@ -0,0 +1 @@
oops

View File

@@ -77,3 +77,16 @@ wait_for() {
wait_for grep "$canary" "$out"
}
@test "it tests a valid crontab" {
timeout 1s "${BATS_TEST_DIRNAME}/../supercronic" -test "${BATS_TEST_DIRNAME}/noop.crontab"
}
@test "it tests an invalid crontab" {
run timeout 1s "${BATS_TEST_DIRNAME}/../supercronic" -test "${BATS_TEST_DIRNAME}/invalid.crontab"
[[ "$status" -eq 1 ]]
}
@test "it errors on an invalid crontab" {
! run_supercronic -test "${BATS_TEST_DIRNAME}/invalid.crontab"
}

View File

@@ -21,6 +21,7 @@ var Usage = func() {
func main() {
debug := flag.Bool("debug", false, "enable debug logging")
json := flag.Bool("json", false, "enable JSON logging")
test := flag.Bool("test", false, "test crontab (does not run jobs)")
flag.Parse()
if *debug {
@@ -49,6 +50,12 @@ func main() {
return
}
if *test {
logrus.Info("crontab is valid")
os.Exit(0)
return
}
var wg sync.WaitGroup
exitCtx, notifyExit := context.WithCancel(context.Background())