still working

This commit is contained in:
Dev
2025-12-13 15:31:52 +00:00
parent dda7abedb7
commit d69e01bbaf
18 changed files with 795 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import (
"database/sql"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/example/storage-appliance/internal/service/mock"
@@ -23,3 +24,22 @@ func TestPoolsHandler(t *testing.T) {
t.Fatalf("expected non-empty body")
}
}
func TestCreatePoolHandler(t *testing.T) {
m := &mock.MockZFSService{}
j := &mock.MockJobRunner{}
app := &App{DB: &sql.DB{}, ZFSSvc: m, JobRunner: j}
body := `{"name":"tank","vdevs":["/dev/sda"]}`
req := httptest.NewRequest(http.MethodPost, "/api/pools", strings.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Auth-User", "admin")
req.Header.Set("X-Auth-Role", "admin")
w := httptest.NewRecorder()
app.CreatePoolHandler(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected 200, got %d", w.Code)
}
if !strings.Contains(w.Body.String(), "job_id") {
t.Fatalf("expected job_id in response")
}
}