This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package onboarding
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDefaultDashboardIsEmbeddedAndMigrated(t *testing.T) {
|
||||
document, err := defaultDashboard()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if document["id"] == nil || document["slug"] != DefaultSlug {
|
||||
t.Fatalf("unexpected default dashboard: %#v", document)
|
||||
}
|
||||
if document["schemaVersion"] != 2 {
|
||||
t.Fatalf("schema version=%v, want 2", document["schemaVersion"])
|
||||
}
|
||||
encoded, err := json.Marshal(document)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(encoded), `"serverId":"$server"`) || strings.Contains(string(encoded), `"server":"$server"`) {
|
||||
t.Fatalf("default metric scope does not use the query planner alias: %s", encoded)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompleteRejectsUnknownChoicesBeforePersistence(t *testing.T) {
|
||||
service := Service{}
|
||||
if _, err := service.Complete(context.Background(), Choice{Dashboard: "unsafe", Rules: "default"}); err == nil {
|
||||
t.Fatal("expected invalid onboarding choice")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidChoicesAreBounded(t *testing.T) {
|
||||
for _, value := range []string{"default", "skip"} {
|
||||
if !validChoice(value) {
|
||||
t.Fatalf("choice %q should be accepted", value)
|
||||
}
|
||||
}
|
||||
if validChoice("install-everything") {
|
||||
t.Fatal("unexpected unbounded onboarding choice")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeCapabilitiesOverrideConfigurationPlaceholders(t *testing.T) {
|
||||
configured := []Capability{
|
||||
{ID: "database", State: "ready", Detail: "database"},
|
||||
{ID: "prometheus", State: "unknown", Detail: "not configured"},
|
||||
{ID: "unraid", State: "unknown", Detail: "not configured"},
|
||||
}
|
||||
observed := []Capability{
|
||||
{ID: "prometheus", State: "ready", Detail: "runtime sampled"},
|
||||
{ID: "unraid", State: "ready", Detail: "runtime sampled"},
|
||||
{ID: "unexpected", State: "ready", Detail: "must stay closed"},
|
||||
}
|
||||
merged := mergeCapabilities(configured, observed)
|
||||
if len(merged) != 3 {
|
||||
t.Fatalf("merged capabilities = %#v", merged)
|
||||
}
|
||||
for _, capability := range merged {
|
||||
if capability.ID == "prometheus" || capability.ID == "unraid" {
|
||||
if capability.State != "ready" || capability.Detail != "runtime sampled" {
|
||||
t.Fatalf("runtime capability not authoritative: %#v", capability)
|
||||
}
|
||||
}
|
||||
if capability.ID == "unexpected" {
|
||||
t.Fatal("runtime callback expanded the closed capability set")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user