tested real proxmox connection
--> passed
This commit is contained in:
@@ -125,6 +125,9 @@ func (h Handler) ListTenantAudit(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusInternalServerError, "audit_list_failed")
|
||||
return
|
||||
}
|
||||
if entries == nil {
|
||||
entries = []Entry{}
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"data": entries,
|
||||
@@ -141,4 +144,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})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,31 @@ func TestListTenantAuditReturnsEntries(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestListTenantAuditReturnsEmptyArray(t *testing.T) {
|
||||
handler := NewHandler(&stubRepository{})
|
||||
req := requestWithPrincipalAndMembership(http.MethodGet, "/tenants/tenant-1/audit", "tenant-1", "owner")
|
||||
req.SetPathValue("tenantID", "tenant-1")
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
handler.ListTenantAudit(rec, req)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)
|
||||
}
|
||||
var response struct {
|
||||
Data []Entry `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &response); err != nil {
|
||||
t.Fatalf("unmarshal response: %v", err)
|
||||
}
|
||||
if response.Data == nil {
|
||||
t.Fatalf("data = nil, want empty array")
|
||||
}
|
||||
if len(response.Data) != 0 {
|
||||
t.Fatalf("len(data) = %d, want 0", len(response.Data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestListTenantAuditReturnsForbiddenForViewer(t *testing.T) {
|
||||
handler := NewHandler(&stubRepository{})
|
||||
req := requestWithPrincipalAndMembership(http.MethodGet, "/tenants/tenant-1/audit", "tenant-1", "viewer")
|
||||
@@ -84,4 +109,4 @@ type stubRepository struct {
|
||||
|
||||
func (s *stubRepository) ListTenantAudit(_ context.Context, _ string, _ int, _ int) ([]Entry, error) {
|
||||
return s.entries, s.err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user