Skip to content

Commit

Permalink
Test main function for adsysd
Browse files Browse the repository at this point in the history
We can do a smoke test of the main function by telling it to print the
version and asserting on the output.
  • Loading branch information
GabrielNagy committed May 29, 2024
1 parent 5b4a8bc commit 3f82a88
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/adsysd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"errors"
"os"
"os/exec"
"syscall"
"testing"
"time"
Expand Down Expand Up @@ -114,3 +116,18 @@ func TestRun(t *testing.T) {
})
}
}

func TestMainApp(t *testing.T) {
if os.Getenv("ADSYS_CALL_MAIN") != "" {
main()
return
}

// #nosec G204: this is only for tests, under controlled args
cmd := exec.Command(os.Args[0], "version", "-test.run=TestMainApp")
cmd.Env = append(os.Environ(), "ADSYS_CALL_MAIN=1")
out, err := cmd.CombinedOutput()

require.Contains(t, string(out), "adsysd\tdev", "Main function should print the version")
require.NoError(t, err, "Main should not return an error")
}

0 comments on commit 3f82a88

Please sign in to comment.