Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
//go:build vmembed && linux && (amd64 || arm64)
|
|
|
|
package vmsup
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/v10networks/nmon/internal/config"
|
|
)
|
|
|
|
func TestEmbeddedPins(t *testing.T) {
|
|
if got := sum(embeddedGz); got != embeddedGzSHA256 {
|
|
t.Fatalf("embedded .gz sha256 %s, pinned %s (re-run scripts/fetch-vm.sh)", got, embeddedGzSHA256)
|
|
}
|
|
}
|
|
|
|
func TestPrepareBinaryExtractsEmbedded(t *testing.T) {
|
|
t.Setenv(envBinary, "")
|
|
dir := t.TempDir()
|
|
spec, err := prepareBinary(dir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := filepath.Join(config.BinDir(dir), "victoria-metrics-prod")
|
|
if spec.path != want || spec.want != embeddedBinSHA256 {
|
|
t.Fatalf("spec %+v", spec)
|
|
}
|
|
fi, err := os.Stat(spec.path)
|
|
if err != nil || fi.Mode().Perm() != 0o755 {
|
|
t.Fatalf("%v %v", fi, err)
|
|
}
|
|
if err := spec.verify(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// second call skips the work
|
|
fi1, _ := os.Stat(spec.path)
|
|
if _, err := prepareBinary(dir); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fi2, _ := os.Stat(spec.path)
|
|
if !os.SameFile(fi1, fi2) {
|
|
t.Fatal("binary was re-extracted")
|
|
}
|
|
}
|