diff --git a/cmd/adsysd/main_test.go b/cmd/adsysd/main_test.go index 030f76491..bd3ba5d5a 100644 --- a/cmd/adsysd/main_test.go +++ b/cmd/adsysd/main_test.go @@ -2,6 +2,8 @@ package main import ( "errors" + "os" + "os/exec" "syscall" "testing" "time" @@ -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") +}