Skip to content

Commit

Permalink
ci: run mail tests in workflow
Browse files Browse the repository at this point in the history
Resolves #658
  • Loading branch information
YC committed Jul 11, 2024
1 parent fe672bb commit 7a50826
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
npm -g install newman
./testing/run_api_tests.sh
- name: Mail Tests
run: ./testing/run_mail_tests.sh

migration:
name: Migration tests
runs-on: ubuntu-latest
Expand Down
30 changes: 22 additions & 8 deletions services/mail/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ import (
"bytes"
"encoding/json"
"fmt"
"net"
"net/http"
"testing"
"time"

"github.com/emvi/logbuch"
"github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
"github.com/muety/wakapi/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"net/http"
"testing"
"time"
)

const (
Expand All @@ -46,10 +48,22 @@ func (suite *SmtpTestSuite) BeforeTest(suiteName, testName string) {
}

func TestSmtpTestSuite(t *testing.T) {
if smtp4dev := newSmtp4DevClient(); smtp4dev.Check() != nil {
t.Skip(fmt.Sprintf("WARNING: smtp4Dev not available at %s - skipping smtp tests", smtp4dev.ApiBaseUrl))
address := net.JoinHostPort(Smtp4DevHost, fmt.Sprintf("%d", Smtp4DevPort))
_, err := net.DialTimeout("tcp", address, time.Second)
if err != nil {
t.Skipf("WARNING: smtp4Dev not available at %s - skipping smtp tests", address)
return
}

smtp4dev := newSmtp4DevClient()
for i := 0; i < 5; i++ {
if smtp4dev.Check() == nil {
break
}
t.Logf("smtp4Dev not ready at %s, retrying...", smtp4dev.ApiBaseUrl)
time.Sleep(1 * time.Second)
}

suite.Run(t, new(SmtpTestSuite))
}

Expand Down Expand Up @@ -201,21 +215,21 @@ func (c *Smtp4DevClient) CountMessages() (int, error) {
func (c *Smtp4DevClient) SetNoTls() error {
logbuch.Info("[smtp4Dev] disabling tls encryption")
err := c.SetConfigValue("tlsMode", "None")
time.Sleep(1 * time.Second)
time.Sleep(2 * time.Second)
return err
}

func (c *Smtp4DevClient) SetForcedTls() error {
logbuch.Info("[smtp4Dev] enabling forced tls encryption")
err := c.SetConfigValue("tlsMode", "ImplicitTls")
time.Sleep(1 * time.Second)
time.Sleep(2 * time.Second)
return err
}

func (c *Smtp4DevClient) SetStartTls() error {
logbuch.Info("[smtp4Dev] enabling tls encryption via starttls")
err := c.SetConfigValue("tlsMode", "StartTls")
time.Sleep(1 * time.Second)
time.Sleep(2 * time.Second)
return err
}

Expand Down
10 changes: 4 additions & 6 deletions testing/run_api_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o nounset -o pipefail -o errexit
DB_TYPE=${1-sqlite}

if ! command -v newman &> /dev/null; then
echo "Newman could not be found. Run 'npm install -g newman' first."
echo "newman could not be found. Run 'npm install -g newman' first."
exit 1
fi

Expand Down Expand Up @@ -135,7 +135,6 @@ start_wakapi_background "../wakapi" "$config"
kill_wakapi

# Only sqlite has data

if [ "$DB_TYPE" == "sqlite" ]; then
echo "Creating database and schema ..."
sqlite3 wakapi_testing.db < schema.sql
Expand All @@ -145,10 +144,9 @@ if [ "$DB_TYPE" == "sqlite" ]; then
start_wakapi_background "../wakapi" "$config"
echo "Running test collection ..."
if ! newman run "wakapi_api_tests.postman_collection.json"; then
exit_code=$?
echo "newman failed with exit code $exit_code"
exit "$exit_code"
echo "newman failed"
exit 1
fi

kill_wakapi
fi

16 changes: 12 additions & 4 deletions testing/run_mail_tests.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#!/bin/bash
set -o nounset -o errexit -o pipefail

cleanup() {
echo "Stopping and removing smtpdev ..."
docker stop smtp4dev_wakapi &> /dev/null || true
docker rm -f smtp4dev_wakapi &> /dev/null
}
trap cleanup EXIT

cleanup

echo "Starting smtp4dev in Docker ..."
docker run -d --rm -p 2525:25 -p 8080:80 --name smtp4dev_wakapi rnwood/smtp4dev

echo "Running tests ..."
go test -run TestSmtpTestSuite ../services/mail

echo "Killing container again ..."
docker stop smtp4dev_wakapi
script_dir=$(dirname "${BASH_SOURCE[0]}")
go test -count=1 -run TestSmtpTestSuite "$script_dir/../services/mail"

0 comments on commit 7a50826

Please sign in to comment.