tested real proxmox connection

--> passed
This commit is contained in:
Philipp
2026-06-12 14:25:34 +02:00
parent 1bfc46f03b
commit 452d1fb8b3
9 changed files with 271 additions and 42 deletions
+4 -1
View File
@@ -28,6 +28,9 @@ func (h Handler) ListTemplates(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusInternalServerError, "templates_list_failed")
return
}
if templates == nil {
templates = []Template{}
}
writeJSON(w, http.StatusOK, map[string][]Template{"data": templates})
}
@@ -186,4 +189,4 @@ func writeJSON(w http.ResponseWriter, status int, body any) {
func writeError(w http.ResponseWriter, status int, message string) {
writeJSON(w, status, map[string]string{"error": message})
}
}
+5 -2
View File
@@ -48,7 +48,7 @@ func TestListTemplatesReturnsTemplates(t *testing.T) {
}
func TestListTemplatesReturnsEmptyList(t *testing.T) {
handler := NewHandler(&stubRepository{templates: []Template{}})
handler := NewHandler(&stubRepository{})
req := httptest.NewRequest(http.MethodGet, "/internal/templates", nil)
rec := httptest.NewRecorder()
@@ -57,6 +57,9 @@ func TestListTemplatesReturnsEmptyList(t *testing.T) {
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)
}
if got := rec.Body.String(); got != "{\"data\":[]}\n" {
t.Fatalf("body = %q, want empty data array", got)
}
}
func TestCreateTemplateReturnsCreated(t *testing.T) {
@@ -205,4 +208,4 @@ func (s *stubRepository) Upsert(_ context.Context, _ Template) (Template, error)
func (s *stubRepository) Delete(_ context.Context, _ string) (bool, error) {
return s.deleteResult, nil
}
}