+15
-25
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/local/glpi-neural-brain/internal/research"
|
||||
)
|
||||
|
||||
func TestRuntimeSettingsAndCategoriesAPI(t *testing.T) {
|
||||
func TestRuntimeSettingsAndSourcesAPI(t *testing.T) {
|
||||
data := t.TempDir()
|
||||
g, err := graph.Open(data)
|
||||
if err != nil {
|
||||
@@ -34,10 +34,11 @@ func TestRuntimeSettingsAndCategoriesAPI(t *testing.T) {
|
||||
LearningEnabled: true,
|
||||
ThinkingEnabled: true,
|
||||
DefaultView: "neural",
|
||||
GLPIKBSource: "Configured GLPI Source",
|
||||
}, g, broker)
|
||||
h := (&Server{Engine: eng, Graph: g, Broker: broker}).Handler()
|
||||
|
||||
body := `{"learning_enabled":false,"thinking_enabled":false,"learning_categories":["GLPI"],"display_categories":["Ollama"],"thinking_categories":["GLPI"],"learning_sources":["GLPI Knowledge Base"],"display_sources":["internal-kb"],"thinking_sources":["GLPI Knowledge Base"],"view_mode":"constellation","max_display_nodes":1500,"low_power_mode":true}`
|
||||
body := `{"learning_enabled":false,"thinking_enabled":false,"learning_sources":["GLPI Knowledge Base"],"display_sources":["internal-kb"],"thinking_sources":["GLPI Knowledge Base"],"view_mode":"constellation","max_display_nodes":1500,"low_power_mode":true}`
|
||||
req := httptest.NewRequest(http.MethodPut, "/api/runtime-settings", strings.NewReader(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
res := httptest.NewRecorder()
|
||||
@@ -53,27 +54,6 @@ func TestRuntimeSettingsAndCategoriesAPI(t *testing.T) {
|
||||
t.Fatalf("unexpected settings: %+v", settings)
|
||||
}
|
||||
|
||||
res = httptest.NewRecorder()
|
||||
h.ServeHTTP(res, httptest.NewRequest(http.MethodGet, "/api/categories", nil))
|
||||
if res.Code != http.StatusOK {
|
||||
t.Fatalf("GET categories returned %d", res.Code)
|
||||
}
|
||||
var categories struct {
|
||||
Categories []engine.CategoryInfo `json:"categories"`
|
||||
}
|
||||
if err := json.NewDecoder(res.Body).Decode(&categories); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundUncategorized := false
|
||||
for _, category := range categories.Categories {
|
||||
if category.Name == "__uncategorized__" && category.Count == 1 {
|
||||
foundUncategorized = true
|
||||
}
|
||||
}
|
||||
if !foundUncategorized {
|
||||
t.Fatalf("uncategorized virtual category missing: %+v", categories.Categories)
|
||||
}
|
||||
|
||||
res = httptest.NewRecorder()
|
||||
h.ServeHTTP(res, httptest.NewRequest(http.MethodGet, "/api/sources", nil))
|
||||
if res.Code != http.StatusOK {
|
||||
@@ -85,8 +65,18 @@ func TestRuntimeSettingsAndCategoriesAPI(t *testing.T) {
|
||||
if err := json.NewDecoder(res.Body).Decode(&sources); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(sources.Sources) < 2 {
|
||||
t.Fatalf("source options missing: %+v", sources.Sources)
|
||||
foundConfiguredGLPI := false
|
||||
foundInternal := false
|
||||
for _, source := range sources.Sources {
|
||||
if source.Name == "Configured GLPI Source" && source.Count == 0 {
|
||||
foundConfiguredGLPI = true
|
||||
}
|
||||
if source.Name == "internal-kb" && source.Count == 1 {
|
||||
foundInternal = true
|
||||
}
|
||||
}
|
||||
if !foundConfiguredGLPI || !foundInternal {
|
||||
t.Fatalf("exact source options or configured GLPI source missing: %+v", sources.Sources)
|
||||
}
|
||||
|
||||
res = httptest.NewRecorder()
|
||||
|
||||
Reference in New Issue
Block a user