72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
package server
|
|
|
|
import (
|
|
"archive/zip"
|
|
"bytes"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.mchus.pro/mchus/logpile/internal/models"
|
|
)
|
|
|
|
func topologyTestResult() *models.AnalysisResult {
|
|
return &models.AnalysisResult{Filename: "bee.tar.gz", Hardware: &models.HardwareConfig{
|
|
BoardInfo: models.BoardInfo{ProductName: "SYS-TEST", SerialNumber: "SN123"},
|
|
CPUs: []models.CPU{{Socket: 0, Model: "Xeon", Status: "OK"}},
|
|
PCIeDevices: []models.PCIeDevice{{
|
|
Slot: "0000:31:00.0", BDF: "0000:31:00.0", DeviceClass: "VideoController",
|
|
Model: "NVIDIA GPU", NUMANode: intPtr(0), Status: "OK",
|
|
}},
|
|
}}
|
|
}
|
|
|
|
func TestTopologyEndpointsPreserveNUMAZero(t *testing.T) {
|
|
s := New(Config{})
|
|
s.SetResult(topologyTestResult())
|
|
for _, tc := range []struct{ path, want string }{{"/api/topology", `"numa_node": 0`}, {"/topology/current", "SYS-TEST - SN123"}} {
|
|
rec := httptest.NewRecorder()
|
|
s.mux.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, tc.path, nil))
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("%s returned %d: %s", tc.path, rec.Code, rec.Body.String())
|
|
}
|
|
if !strings.Contains(rec.Body.String(), tc.want) {
|
|
t.Fatalf("%s missing %q: %s", tc.path, tc.want, rec.Body.String())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRawExportBundleContainsSeparateTopologyJSON(t *testing.T) {
|
|
result := topologyTestResult()
|
|
pkg := newRawExportFromUploadedFile(result.Filename, "application/gzip", []byte("source"), result)
|
|
body, err := buildRawExportBundle(pkg, result, "test")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
zr, err := zip.NewReader(bytes.NewReader(body), int64(len(body)))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, f := range zr.File {
|
|
if f.Name != rawExportBundleTopologyFile {
|
|
continue
|
|
}
|
|
r, err := f.Open()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
data, err := io.ReadAll(r)
|
|
_ = r.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(data), `"version": "1.0"`) {
|
|
t.Fatalf("unexpected topology.json: %s", data)
|
|
}
|
|
return
|
|
}
|
|
t.Fatal("raw export bundle has no topology.json")
|
|
}
|