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.
This commit is contained in:
Winni Neessen 2024-10-26 16:25:42 +02:00
parent 9072aef355
commit 4b8bf0507d
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 7 additions and 8 deletions

View file

@ -31,6 +31,7 @@ jobs:
go: ['1.23'] go: ['1.23']
env: env:
PERFORM_ONLINE_TEST: ${{ vars.PERFORM_ONLINE_TEST }} PERFORM_ONLINE_TEST: ${{ vars.PERFORM_ONLINE_TEST }}
TEST_SENDMAIL: ${{ vars.TEST_SENDMAIL }}
TEST_HOST: ${{ secrets.TEST_HOST }} TEST_HOST: ${{ secrets.TEST_HOST }}
TEST_USER: ${{ secrets.TEST_USER }} TEST_USER: ${{ secrets.TEST_USER }}
TEST_PASS: ${{ secrets.TEST_PASS }} TEST_PASS: ${{ secrets.TEST_PASS }}
@ -48,8 +49,9 @@ jobs:
check-latest: true check-latest: true
- name: Install sendmail - name: Install sendmail
run: | 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 - name: Run go test
if: success()
run: | run: |
go test -race -shuffle=on --coverprofile=coverage.coverprofile --covermode=atomic ./... go test -race -shuffle=on --coverprofile=coverage.coverprofile --covermode=atomic ./...
- name: Upload coverage to Codecov - name: Upload coverage to Codecov
@ -176,9 +178,6 @@ jobs:
with: with:
go-version: ${{ matrix.go }} go-version: ${{ matrix.go }}
check-latest: true check-latest: true
- name: Install sendmail
run: |
sudo apt-get -y install sendmail; which sendmail
- name: Run go test - name: Run go test
run: | run: |
go test -shuffle=on -race --coverprofile=./cov.out ./... go test -shuffle=on -race --coverprofile=./cov.out ./...

View file

@ -16,8 +16,8 @@ import (
// TestMsg_WriteToSendmailWithContext tests the WriteToSendmailWithContext() method of the Msg // TestMsg_WriteToSendmailWithContext tests the WriteToSendmailWithContext() method of the Msg
func TestMsg_WriteToSendmailWithContext(t *testing.T) { func TestMsg_WriteToSendmailWithContext(t *testing.T) {
if os.Getenv("TEST_SKIP_SENDMAIL") != "" { if os.Getenv("TEST_SENDMAIL") != "true" {
t.Skipf("TEST_SKIP_SENDMAIL variable is set. Skipping sendmail test") t.Skipf("TEST_SENDMAIL variable is not set. Skipping sendmail test")
} }
tests := []struct { tests := []struct {
name string name string
@ -45,8 +45,8 @@ func TestMsg_WriteToSendmailWithContext(t *testing.T) {
// TestMsg_WriteToSendmail will test the output to the local sendmail command // TestMsg_WriteToSendmail will test the output to the local sendmail command
func TestMsg_WriteToSendmail(t *testing.T) { func TestMsg_WriteToSendmail(t *testing.T) {
if os.Getenv("TEST_SKIP_SENDMAIL") != "" { if os.Getenv("TEST_SENDMAIL") != "true" {
t.Skipf("TEST_SKIP_SENDMAIL variable is set. Skipping sendmail test") t.Skipf("TEST_SENDMAIL variable is not set. Skipping sendmail test")
} }
_, err := os.Stat(SendmailPath) _, err := os.Stat(SendmailPath)
if err != nil { if err != nil {