Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions t/41_e2e_build_msi_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"fmt"
"os"
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -58,6 +60,26 @@ func TestMSIinstaller(t *testing.T) {
require.FileExistsf(t, `C:\Program Files\snclient\`+file, file+" has been installed")
}

// Verify the packaged binary recognizes a volume mounted at a directory.
volumeMountPath := setupDirectoryMountedVolume(t)
runCmd(t, &cmd{
Cmd: `C:\Program Files\snclient\snclient.exe`,
Args: []string{
"test",
"check_drivesize",
"warn=used>=95%",
"crit=used>=97%",
"drive=" + volumeMountPath,
"perf-config=*(unit:Gb)",
"perf-syntax=%(key:lc)",
"show-all",
},
Like: []string{
`Exit Code: OK \(0\)`,
`OK.*disk3`,
},
})

iniContent, err := os.ReadFile(`C:\Program Files\snclient\snclient.ini`)
require.NoErrorf(t, err, "snclient.ini can be read")
assert.Containsf(t, string(iniContent), "allowed hosts = 127.0.0.1,::1,192.168.0.1", "snclient.ini contains allowed hosts")
Expand Down Expand Up @@ -206,3 +228,37 @@ func TestMSIinstaller(t *testing.T) {
os.Remove("snclient_update.msi")
os.Remove("snclient.ini")
}

func setupDirectoryMountedVolume(t *testing.T) string {
t.Helper()

root := t.TempDir()

vhdDir := filepath.Join(root, "vhds")
mountPath := filepath.Join(root, "testmount", "disk3")
require.NoError(t, os.MkdirAll(vhdDir, 0o700), "creating VHD directory")
require.NoError(t, os.MkdirAll(mountPath, 0o700), "creating volume mount directory")

vhdPath := filepath.Join(vhdDir, "snclient-drivesize-test.vhdx")
scriptDir := t.TempDir()
createScript := filepath.Join(scriptDir, "create-volume.txt")
writeFile(t, createScript, fmt.Sprintf(`create vdisk file="%s" maximum=100 type=expandable
select vdisk file="%s"
attach vdisk
convert gpt
create partition primary
format fs=ntfs quick label="SNClientTest"
assign mount="%s"
`, vhdPath, vhdPath, mountPath))

runCmd(t, &cmd{Cmd: "diskpart", Args: []string{"/s", createScript}})
t.Cleanup(func() {
detachScript := filepath.Join(scriptDir, "detach-volume.txt")
writeFile(t, detachScript, fmt.Sprintf(`select vdisk file="%s"
detach vdisk
`, vhdPath))
runCmd(t, &cmd{Cmd: "diskpart", Args: []string{"/s", detachScript}})
})

return mountPath
}
Loading