Skip to content

Commit

Permalink
Merge pull request #2 from mittwald/feat/inotify-support
Browse files Browse the repository at this point in the history
Add inotify integration test
  • Loading branch information
YannikBramkamp authored Sep 11, 2024
2 parents a849a80 + 752c325 commit 81e6974
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions integration/reload.bats
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,46 @@ grep_test_file() {
kill -s TERM "$PID"
wait
}

@test "if inotify is enabled it reloads on file change when receiving a WRITE event" {
echo '* * * * * * * echo a > "$TEST_FILE"' > "$CRONTAB_FILE"

"${BATS_TEST_DIRNAME}/../supercronic" -inotify "$CRONTAB_FILE" 3>&- &
PID="$!"

wait_for grep_test_file a

echo '* * * * * * * echo b > "$TEST_FILE"' > "$CRONTAB_FILE"

wait_for grep_test_file b

kill -s TERM "$PID"
wait
}

@test "if inotify is enabled it handles kubernetes like atomic writes using updated symlinks and folder deletion" {
CRONTAB_FILE_NAME="$(basename $(mktemp --dry-run --tmpdir))"

WORK_DIR="$(mktemp -d)"
CRONTAB_PRE_DIR="$(mktemp -d)"
CRONTAB_POST_DIR="$(mktemp -d)"

echo '* * * * * * * echo a > "$TEST_FILE"' > "$CRONTAB_PRE_DIR"/"$CRONTAB_FILE_NAME"
echo '* * * * * * * echo b > "$TEST_FILE"' > "$CRONTAB_POST_DIR"/"$CRONTAB_FILE_NAME"

ln -s "$CRONTAB_PRE_DIR"/"$CRONTAB_FILE_NAME" "$WORK_DIR"/"$CRONTAB_FILE_NAME"

"${BATS_TEST_DIRNAME}/../supercronic" -inotify -debug "$WORK_DIR"/"$CRONTAB_FILE_NAME" 3>&- &
PID="$!"

wait_for grep_test_file a

ln -sf "$CRONTAB_POST_DIR"/"$CRONTAB_FILE_NAME" "$WORK_DIR"/"$CRONTAB_FILE_NAME"

rm -r "$CRONTAB_PRE_DIR"

wait_for grep_test_file b

kill -s TERM "$PID"
wait
}
Empty file modified integration/test.bats
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func main() {
// workaround for k8s configmap and secret mounts
case event.Op & fsnotify.Remove:
logrus.Debug("watched file changed")
if err := watcher.Add(event.Name); err != nil {
if err := watcher.Add(crontabFileName); err != nil {
logrus.Fatal(err)
return
}
Expand Down

0 comments on commit 81e6974

Please sign in to comment.