Adapt unit test to changed implementation

This commit is contained in:
2026-01-30 16:49:55 +01:00
parent b600eeca5e
commit 5e58c9f376

View File

@@ -7,35 +7,48 @@ package web
import ( import (
"encoding/json" "encoding/json"
"fmt"
"testing" "testing"
ccconf "github.com/ClusterCockpit/cc-lib/v2/ccConfig"
) )
func TestInit(t *testing.T) { func TestInitDefaults(t *testing.T) {
fp := "../../configs/config.json" // Test Init with nil config uses defaults
ccconf.Init(fp) err := Init(nil)
cfg := ccconf.GetPackageConfig("ui") if err != nil {
t.Fatalf("Init failed: %v", err)
}
Init(cfg) // Check default values are set
if UIDefaultsMap["jobList_usePaging"] != false {
if UIDefaultsMap["nodeList_usePaging"] == false { t.Errorf("wrong option\ngot: %v \nwant: false", UIDefaultsMap["jobList_usePaging"])
t.Errorf("wrong option\ngot: %v \nwant: true", UIDefaultsMap["NodeList_UsePaging"]) }
if UIDefaultsMap["nodeList_usePaging"] != false {
t.Errorf("wrong option\ngot: %v \nwant: false", UIDefaultsMap["nodeList_usePaging"])
}
if UIDefaultsMap["jobView_showPolarPlot"] != true {
t.Errorf("wrong option\ngot: %v \nwant: true", UIDefaultsMap["jobView_showPolarPlot"])
} }
} }
func TestSimpleDefaults(t *testing.T) { func TestSimpleDefaults(t *testing.T) {
const s = `{ const s = `{
"job-list": { "job-list": {
"show-footprint": false "show-footprint": true
} }
}` }`
Init(json.RawMessage(s)) err := Init(json.RawMessage(s))
if err != nil {
t.Fatalf("Init failed: %v", err)
}
if UIDefaultsMap["jobList_usePaging"] == true { // Verify show-footprint was set
t.Errorf("wrong option\ngot: %v \nwant: false", UIDefaultsMap["NodeList_UsePaging"]) if UIDefaultsMap["jobList_showFootprint"] != true {
t.Errorf("wrong option\ngot: %v \nwant: true", UIDefaultsMap["jobList_showFootprint"])
}
// Verify other defaults remain unchanged
if UIDefaultsMap["jobList_usePaging"] != false {
t.Errorf("wrong option\ngot: %v \nwant: false", UIDefaultsMap["jobList_usePaging"])
} }
} }
@@ -59,9 +72,11 @@ func TestOverwrite(t *testing.T) {
} }
}` }`
Init(json.RawMessage(s)) err := Init(json.RawMessage(s))
if err != nil {
t.Fatalf("Init failed: %v", err)
}
fmt.Printf("%+v", UIDefaultsMap)
v, ok := UIDefaultsMap["metricConfig_jobListMetrics"].([]string) v, ok := UIDefaultsMap["metricConfig_jobListMetrics"].([]string)
if ok { if ok {
if v[0] != "flops_sp" { if v[0] != "flops_sp" {