chore: build
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
package projects
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/omnex/control-plane/api/internal/demos"
|
||||
)
|
||||
|
||||
func newTestRouter(t *testing.T) (*gin.Engine, *fakeProv) {
|
||||
@@ -20,6 +24,7 @@ func newTestRouter(t *testing.T) (*gin.Engine, *fakeProv) {
|
||||
r.GET("/projects/:id", h.Get)
|
||||
r.DELETE("/projects/:id", h.Delete)
|
||||
r.POST("/projects/:id/extend", h.Extend)
|
||||
r.GET("/projects/:id/details", h.Details)
|
||||
return r, prov
|
||||
}
|
||||
|
||||
@@ -91,3 +96,42 @@ func TestHandlerExtend_BoundsAndNotFound(t *testing.T) {
|
||||
t.Errorf("sans durée : HTTP %d, attendu 400", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerDetails(t *testing.T) {
|
||||
r, prov := newTestRouter(t)
|
||||
prov.state = demos.ResourceState{API: demos.ComponentState{Phase: "Running"}}
|
||||
|
||||
if w := do(r, "GET", "/projects/inconnu/details", ""); w.Code != http.StatusNotFound {
|
||||
t.Errorf("projet inconnu : %d, attendu 404", w.Code)
|
||||
}
|
||||
|
||||
w := do(r, "POST", "/projects", body("1"))
|
||||
if w.Code != http.StatusAccepted {
|
||||
t.Fatalf("Create: %d %s", w.Code, w.Body)
|
||||
}
|
||||
var created Project
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &created); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
<-prov.provisioned
|
||||
|
||||
w = do(r, "GET", "/projects/"+created.ID+"/details", "")
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("Details: %d %s", w.Code, w.Body)
|
||||
}
|
||||
var got struct {
|
||||
Namespace string `json:"namespace"`
|
||||
State demos.ResourceState `json:"state"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Namespace != created.Namespace || got.State.API.Phase != "Running" {
|
||||
t.Errorf("réponse inattendue : %+v", got)
|
||||
}
|
||||
|
||||
prov.stateErr = errors.New("api k8s indisponible")
|
||||
if w := do(r, "GET", "/projects/"+created.ID+"/details", ""); w.Code != http.StatusInternalServerError || strings.Contains(w.Body.String(), "k8s") {
|
||||
t.Errorf("erreur cluster : %d %s (500 sans détail interne attendu)", w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user