still working
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user