mirror of
https://github.com/aptible/supercronic.git
synced 2025-09-26 20:31:17 +08:00
Add a -test flag
This allows verifying the syntax of a crontab, without running it.
This commit is contained in:
@@ -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
|
||||
|
1
integration/invalid.crontab
Normal file
1
integration/invalid.crontab
Normal file
@@ -0,0 +1 @@
|
||||
oops
|
@@ -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"
|
||||
}
|
||||
|
7
main.go
7
main.go
@@ -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())
|
||||
|
||||
|
Reference in New Issue
Block a user