tested real proxmox connection
--> passed
This commit is contained in:
@@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user