From 4b8bf0507ddbb2b6aedaf84b30ea4a2b2c415d9c Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 26 Oct 2024 16:25:42 +0200 Subject: [PATCH] Update CI workflow and sendmail test condition Add the TEST_SENDMAIL environment variable for better control over sendmail tests. Optimize sendmail installation in CI by updating and installing ssmtp. Modify tests to check if TEST_SENDMAIL is set to "true" before running. --- .github/workflows/ci.yml | 7 +++---- msg_nowin_test.go | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c196ae7..fbd0342 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,7 @@ jobs: go: ['1.23'] env: PERFORM_ONLINE_TEST: ${{ vars.PERFORM_ONLINE_TEST }} + TEST_SENDMAIL: ${{ vars.TEST_SENDMAIL }} TEST_HOST: ${{ secrets.TEST_HOST }} TEST_USER: ${{ secrets.TEST_USER }} TEST_PASS: ${{ secrets.TEST_PASS }} @@ -48,8 +49,9 @@ jobs: check-latest: true - name: Install sendmail run: | - sudo apt-get -y install sendmail; which sendmail + apt-get -y update >/dev/null && apt-get -y upgrade >/dev/null && apt-get -y install ssmtp >/dev/null && which sendmail - name: Run go test + if: success() run: | go test -race -shuffle=on --coverprofile=coverage.coverprofile --covermode=atomic ./... - name: Upload coverage to Codecov @@ -176,9 +178,6 @@ jobs: with: go-version: ${{ matrix.go }} check-latest: true - - name: Install sendmail - run: | - sudo apt-get -y install sendmail; which sendmail - name: Run go test run: | go test -shuffle=on -race --coverprofile=./cov.out ./... diff --git a/msg_nowin_test.go b/msg_nowin_test.go index 6cde71a..b0ef87b 100644 --- a/msg_nowin_test.go +++ b/msg_nowin_test.go @@ -16,8 +16,8 @@ import ( // TestMsg_WriteToSendmailWithContext tests the WriteToSendmailWithContext() method of the Msg func TestMsg_WriteToSendmailWithContext(t *testing.T) { - if os.Getenv("TEST_SKIP_SENDMAIL") != "" { - t.Skipf("TEST_SKIP_SENDMAIL variable is set. Skipping sendmail test") + if os.Getenv("TEST_SENDMAIL") != "true" { + t.Skipf("TEST_SENDMAIL variable is not set. Skipping sendmail test") } tests := []struct { name string @@ -45,8 +45,8 @@ func TestMsg_WriteToSendmailWithContext(t *testing.T) { // TestMsg_WriteToSendmail will test the output to the local sendmail command func TestMsg_WriteToSendmail(t *testing.T) { - if os.Getenv("TEST_SKIP_SENDMAIL") != "" { - t.Skipf("TEST_SKIP_SENDMAIL variable is set. Skipping sendmail test") + if os.Getenv("TEST_SENDMAIL") != "true" { + t.Skipf("TEST_SENDMAIL variable is not set. Skipping sendmail test") } _, err := os.Stat(SendmailPath) if err != nil {