diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 7143547..a199b52 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -405,14 +405,20 @@ jobs: integration-test-osx: runs-on: macos-latest - needs: [pkg-osx] + needs: [get-version,pkg-osx] + env: + BIN: "snclient-${{needs.get-version.outputs.version}}-osx-${{ matrix.go-arch }}" steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: ${{ env.GOVERSION }} + - uses: actions/download-artifact@v4 + with: + name: "${{ env.BIN }}.pkg" - name: "OSX Integration Tests" run: | + mv ${{ env.BIN }}.pkg t/snclient.pkg cd t go test -v diff --git a/t/40_build_msi_windows_test.go b/t/40_build_msi_windows_test.go index 3ef0788..2f41df1 100644 --- a/t/40_build_msi_windows_test.go +++ b/t/40_build_msi_windows_test.go @@ -84,24 +84,7 @@ func TestMSIinstaller(t *testing.T) { runCmd(t, &cmd{Cmd: "net", Args: []string{"start", "snclient"}}) // wait a couple of seconds till daemon answers - waitUntilResponse := func() { - waitStart := time.Now() - waitUntil := time.Now().Add(10 * time.Second) - for time.Now().Before(waitUntil) { - res := runCmd(t, &cmd{ - Cmd: bin, - Args: []string{"run", "check_nsc_web", "-k", "-p", "test", "-u", "https://localhost:8443", "check_snclient_version"}, - Exit: -1, - }) - if res.ExitCode == 0 { - t.Logf("daemon responded after %s", time.Since(waitStart)) - - break - } - time.Sleep(100 * time.Millisecond) - } - } - waitUntilResponse() + waitUntilResponse(t, bin) // verify response runCmd(t, &cmd{ @@ -136,7 +119,7 @@ func TestMSIinstaller(t *testing.T) { require.FileExistsf(t, `C:\Program Files\snclient\`+file, file+" still exists") } - waitUntilResponse() + waitUntilResponse(t, bin) // verify response runCmd(t, &cmd{ diff --git a/t/50_pkg_osx_darwin_test.go b/t/50_pkg_osx_darwin_test.go new file mode 100644 index 0000000..00a5f2e --- /dev/null +++ b/t/50_pkg_osx_darwin_test.go @@ -0,0 +1,90 @@ +package main + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +const ( + localOSXINIPath = `/etc/snclient/snclient_local.ini` +) + +var localOSXINI = ` +[/modules] +CheckBuiltinPlugins = enabled +CheckExternalScripts = enabled + +[/settings/default] +password = test +` + +// this test requires: +// - snclient.pkg +// it tries a installation and removes it afterwards +func TestOSXinstaller(t *testing.T) { + bin := getBinary() + require.FileExistsf(t, "snclient.pkg", "snclient.pkg binary must exist") + + // install pkg file + runCmd(t, &cmd{ + Cmd: "installer", + Args: []string{"-pkg", "snclient.pkg", "-target", "/"}, + }) + + requiredFiles := []string{ + "/usr/local/bin/snclient", + "/usr/local/bin/snclient_uninstall.sh", + "/usr/local/bin/node_exporter", + "/etc/snclient/snclient.ini", + "/etc/snclient/cacert.pem", + "/etc/snclient/server.key", + "/etc/snclient/server.crt", + "/Library/LaunchDaemons/com.snclient.snclient.plist", + } + for _, file := range requiredFiles { + require.FileExistsf(t, file, file+" has been installed") + } + + // add custom .ini + writeFile(t, localOSXINIPath, localOSXINI) + + waitUntilResponse(t, bin) + + // verify response + runCmd(t, &cmd{ + Cmd: bin, + Args: []string{"run", "check_nsc_web", "-k", "-p", "test", "-u", "https://localhost:8443", "check_snclient_version"}, + Like: []string{`^SNClient\+ v`}, + }) + + runCmd(t, &cmd{ + Cmd: bin, + Args: []string{"run", "check_nsc_web", "-k", "-p", "test", "-u", "https://localhost:8443", "check_uptime", "crit=uptime<2s", "warn=uptime<1s"}, + Like: []string{"OK - uptime"}, + }) + + runCmd(t, &cmd{ + Cmd: bin, + Args: []string{"run", "check_nsc_web", "-k", "-p", "test", "-u", "https://localhost:8443", "check_cpu", "crit=load>101", "warn=load>101"}, + Like: []string{"OK - CPU load is ok."}, + }) + + // cleanup + os.Remove(localOSXINIPath) + + // uninstall pkg file + runCmd(t, &cmd{ + Cmd: `/usr/local/bin/snclient_uninstall.sh`, + Args: []string{}, + }) + + for _, file := range requiredFiles { + assert.NoFileExistsf(t, file, file+" has been removed") + } + + // remove remaining files + os.Remove("snclient.ini") +} diff --git a/t/utils.go b/t/utils.go index 089dbea..0f9a8b8 100644 --- a/t/utils.go +++ b/t/utils.go @@ -8,13 +8,12 @@ import ( "os" "os/exec" "path/filepath" + "pkg/utils" "runtime" "syscall" "testing" "time" - "pkg/utils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -199,6 +198,27 @@ func writeFile(t *testing.T, path, content string) { require.NoErrorf(t, err, fmt.Sprintf("writing file %s succeeded", path)) } +// wait a couple of seconds till daemon answers +func waitUntilResponse(t *testing.T, bin string) { + t.Helper() + + waitStart := time.Now() + waitUntil := time.Now().Add(10 * time.Second) + for time.Now().Before(waitUntil) { + res := runCmd(t, &cmd{ + Cmd: bin, + Args: []string{"run", "check_nsc_web", "-k", "-p", "test", "-u", "https://localhost:8443", "check_snclient_version"}, + Exit: -1, + }) + if res.ExitCode == 0 { + t.Logf("daemon responded after %s", time.Since(waitStart)) + + break + } + time.Sleep(100 * time.Millisecond) + } +} + var ( daemonPid = 0 daemonPidFile = "snclient.lock"