mirror of
https://github.com/bokysan/docker-postfix.git
synced 2025-09-03 13:04:35 +08:00
Summary ^^^^^^^ This commit refactors the code base to be more manageble and prepares the groundwork for tests. Refactoring ^^^^^^^^^^^ Files are now moved to subdirectories, all for the sole purpose of easier management. Tests live in their own folders, as well as configs and other files. Test framework ^^^^^^^^^^^^^^ Two new important scripts/directories are available: - `unit-tests.sh` / `/unit-test` which executes unit tests across shell scripts, and - `integration-test.sh` / `integration-tests`, which spins up the container and tries to send the email. Both tests use the [BATS](https://github.com/sstephenson/bats) framework for testing. To create a new test, simply drop a `.bats` file into a corresponding directory. Functions have been extracted into `common-run.sh`, to be able to test them independently. DKIM_SELECTOR ^^^^^^^^^^^^^ It is now possible to specify a DKIM selector to use (instead of the default "mail"). See `README.md` for more details. JSON logging ^^^^^^^^^^^^ WIP: rsyslog will now output JSON logs. This is especially important if you plan on deploying the image into Kubernetes, as [Prometheus](https://prometheus.io/) can handle logs in JSON much easier. TODO: Make this an optional feature, to not confuse existing users.
40 lines
755 B
Bash
Executable file
40 lines
755 B
Bash
Executable file
#!/usr/bin/env bats
|
|
|
|
FROM=$1
|
|
TO=$2
|
|
|
|
if [ -z "$FROM" ]; then
|
|
FROM="demo@example.org"
|
|
fi
|
|
|
|
if [ -z "$TO" ]; then
|
|
TO="test@gmail.com"
|
|
fi
|
|
|
|
# Wait for postfix to startup
|
|
echo "Waiting for startup..."
|
|
wait-for-service -q tcp://postfix_test_587:587
|
|
|
|
SMTP_DATA="-smtp postfix_test_587 -port 587"
|
|
|
|
@test "Get server info" {
|
|
mailsend -info $SMTP_DATA
|
|
}
|
|
|
|
@test "Send a simple mail" {
|
|
mailsend \
|
|
-sub "Test email 1" $SMTP_DATA \
|
|
-from "$FROM" -to "$TO" \
|
|
body \
|
|
-msg "Hello world!\nThis is a simple test message!"
|
|
}
|
|
|
|
@test "Send mail with attachment" {
|
|
mailsend \
|
|
-sub "Test with attachment" $SMTP_DATA \
|
|
-from "$FROM" -to "$TO" \
|
|
body \
|
|
-msg "Hi!\nThis is an example of an attachment." \
|
|
attach \
|
|
-file "/usr/local/bin/mailsend"
|
|
}
|