-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add pkg/deb installation/uninstall to integration tests
- Loading branch information
Showing
6 changed files
with
276 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
localDEBINIPath = `/etc/snclient/snclient_local.ini` | ||
) | ||
|
||
var localDEBINI = ` | ||
[/modules] | ||
CheckBuiltinPlugins = enabled | ||
CheckExternalScripts = enabled | ||
[/settings/default] | ||
password = test | ||
` | ||
|
||
// this test requires: | ||
// - snclient.deb | ||
// it tries a installation and removes it afterwards | ||
func TestDEBinstaller(t *testing.T) { | ||
// skip test unless requested, it will uninstall existing installations | ||
if os.Getenv("SNCLIENT_INSTALL_TEST") != "1" { | ||
t.Skipf("SKIPPED: pkg installer test requires env SNCLIENT_INSTALL_TEST=1") | ||
|
||
return | ||
} | ||
|
||
bin := getBinary() | ||
require.FileExistsf(t, "snclient.deb", "snclient.deb binary must exist") | ||
|
||
// install deb file | ||
runCmd(t, &cmd{ | ||
Cmd: "sudo", | ||
Args: []string{"apt-get", "install", "-y", "./snclient.deb"}, | ||
}) | ||
|
||
requiredFiles := []string{ | ||
"/usr/bin/snclient", | ||
"/usr/lib/snclient/node_exporter", | ||
"/etc/snclient/snclient.ini", | ||
"/etc/snclient/cacert.pem", | ||
"/etc/snclient/server.key", | ||
"/etc/snclient/server.crt", | ||
"/lib/systemd/system/snclient.service", | ||
"/etc/logrotate.d/snclient", | ||
} | ||
for _, file := range requiredFiles { | ||
require.FileExistsf(t, file, file+" has been installed") | ||
} | ||
|
||
// add custom .ini | ||
runCmd(t, &cmd{ | ||
Cmd: "sudo", | ||
Args: []string{"touch", localDEBINIPath}, | ||
}) | ||
runCmd(t, &cmd{ | ||
Cmd: "sudo", | ||
Args: []string{"chmod", "666", localDEBINIPath}, | ||
}) | ||
writeFile(t, localDEBINIPath, localDEBINI) | ||
|
||
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(localDEBINIPath) | ||
|
||
// uninstall pkg file | ||
runCmd(t, &cmd{ | ||
Cmd: "sudo", | ||
Args: []string{"apt-get", "remove", "-y", "--purge", "snclient"}, | ||
}) | ||
|
||
for _, file := range requiredFiles { | ||
assert.NoFileExistsf(t, file, file+" has been removed") | ||
} | ||
|
||
// remove remaining files | ||
os.Remove("snclient.ini") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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) { | ||
// skip test unless requested, it will uninstall existing installations | ||
if os.Getenv("SNCLIENT_INSTALL_TEST") != "1" { | ||
t.Skipf("SKIPPED: pkg installer test requires env SNCLIENT_INSTALL_TEST=1") | ||
|
||
return | ||
} | ||
|
||
bin := getBinary() | ||
require.FileExistsf(t, "snclient.pkg", "snclient.pkg binary must exist") | ||
|
||
// install pkg file | ||
runCmd(t, &cmd{ | ||
Cmd: "/usr/sbin/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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestFreeBSD(t *testing.T) { | ||
// skip test unless requested, it will uninstall existing installations | ||
if os.Getenv("SNCLIENT_INSTALL_TEST") != "1" { | ||
t.Skipf("SKIPPED: pkg installer test requires env SNCLIENT_INSTALL_TEST=1") | ||
|
||
return | ||
} | ||
|
||
t.Logf("not yet implemented...") | ||
bin := getBinary() | ||
waitUntilResponse(t, bin) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters