Skip to content

Commit

Permalink
test: add basic integ tests for mail logic
Browse files Browse the repository at this point in the history
  • Loading branch information
exbotanical committed Nov 12, 2023
1 parent 3cbff2b commit a66aa56
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM ubuntu:20.04
# TODO: shared
RUN apt-get update && apt-get install -y git gcc make uuid-dev vim bash curl libpcre3-dev
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install bsd-mailx
RUN service postfix start

RUN sh -c "`curl -L https://raw.githubusercontent.com/rylnd/shpec/master/install.sh`"

Expand Down
2 changes: 0 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ FROM ubuntu:20.04
RUN apt-get update && apt-get install -y git gcc make uuid-dev vim bash curl libpcre3-dev
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install bsd-mailx

RUN service postfix start

RUN sh -c "`curl -L https://raw.githubusercontent.com/rylnd/shpec/master/install.sh`"

WORKDIR /usr/app
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
- [ ] special crontab config support (toml or yaml?)
- [x] log to syslog
- [ ] syslog levels?
- [ ] Allow log feature flags (fs logs, job logs, time logs, etc)
- [x] integ testing
- [x] unit tests
- [ ] Ensure tests don't log to syslog or whatever (maybe a test sink?)
- [ ] handle signals and log getting closed or deleted
- [ ] daemon lock
- [ ] Allow log feature flags (fs logs, job logs, time logs, etc)
18 changes: 15 additions & 3 deletions clib.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"name": "cron",
"version": "0.1.0",
"name": "chronic",
"version": "0.0.1",
"author": "Matthew Zito",
"repo": "exbotanical/chronic",
"license": "MIT",
"description": "A cron daemon for modern UNIX systems",
"keywords": [
"cron",
"daemon",
"scheduler",
"job",
"task runner"
],
"dependencies": {
"exbotanical/libutil": "*",
"exbotanical/libhash": "*",
Expand All @@ -9,5 +20,6 @@
"development": {
"thlorenz/tap.c": "*"
},
// TODO: setup installer
"src": []
}
}
13 changes: 13 additions & 0 deletions t/integ/main_shpec.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ SETUP_PATH="$ROOT_DIR/utils/setup.bash"
ONE_MIN_IN_SECS=60

describe 'chronic cron daemon'
# Required - Docker doesn't save running processes so we need to start the mail server here
service postfix start

# shellcheck source=utils/setup.bash
. "$SETUP_PATH"

Expand Down Expand Up @@ -102,4 +105,14 @@ describe 'chronic cron daemon'
assert equal $(validate_timestamps "/tmp/$uname_1.5min" 5) 0
}
ti

it 'sends user mail'
uname_1_mail_count="$(cat $MAIL_DIR/$uname_1 | grep 'Subject:' | wc -l 2>/dev/null)"
uname_2_mail_count="$(cat $MAIL_DIR/$uname_2 | grep 'Subject:' | wc -l 2>/dev/null)"

assert gt $uname_1_mail_count 1
assert gt $uname_2_mail_count 1

# TODO: Assert on actual mail contents once we finalize the logic there
ti
end_describe
4 changes: 3 additions & 1 deletion t/integ/utils/setup.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

USER_CRONDIR='/var/spool/cron/crontabs'
MAIL_DIR='/var/spool/mail'

mk_basic_cron_cmd () {
local uname="$1"
Expand Down Expand Up @@ -37,7 +38,8 @@ teardown_user () {
teardown_user_crontab $uname

userdel -r $uname && \
rm /tmp/$uname*
rm /tmp/$uname* && \
rm $MAIL_DIR/$uname
}

setup_user_crondir () {
Expand Down

0 comments on commit a66aa56

Please sign in to comment.