chore: build
ci-api / test (push) Successful in 23m32s
ci-web / test (push) Successful in 14m7s

This commit is contained in:
Xor290
2026-09-20 18:52:09 +02:00
parent 9e11f01c2c
commit 8d857faa45
66 changed files with 3673 additions and 1564 deletions
@@ -1,6 +1,7 @@
package projects
import (
"context"
"errors"
"sync"
"testing"
@@ -16,6 +17,9 @@ type fakeProv struct {
specs []demos.ProjectSpec
tornDown []string
provErr error
state demos.ResourceState
stateErr error
stateCalls []string
provisioned chan struct{}
}
@@ -35,6 +39,13 @@ func (f *fakeProv) TeardownProject(ns string) error {
return nil
}
func (f *fakeProv) ProjectState(_ context.Context, ns string) (demos.ResourceState, error) {
f.mu.Lock()
defer f.mu.Unlock()
f.stateCalls = append(f.stateCalls, ns)
return f.state, f.stateErr
}
var t0 = time.Date(2026, time.September, 20, 12, 0, 0, 0, time.UTC)
func newTestService(t *testing.T) (*Service, *fakeProv, *time.Time) {
@@ -277,3 +288,48 @@ func TestDelete_IsIdempotentAndImmediate(t *testing.T) {
t.Errorf("erreur %v, attendu ErrNotFound", err)
}
}
func TestState_ReadyProjectQueriesItsOwnNamespace(t *testing.T) {
svc, prov, _ := newTestService(t)
prov.state = demos.ResourceState{API: demos.ComponentState{Phase: "Running", CPUMilli: 12}}
p := createReady(t, svc, prov, validInput())
got, state, err := svc.State(context.Background(), p.ID)
if err != nil {
t.Fatal(err)
}
if got.Namespace != p.Namespace || state.API.Phase != "Running" || state.API.CPUMilli != 12 {
t.Errorf("namespace=%q state=%+v", got.Namespace, state)
}
if len(prov.stateCalls) != 1 || prov.stateCalls[0] != p.Namespace {
t.Errorf("namespace interrogé=%v, attendu [%s]", prov.stateCalls, p.Namespace)
}
}
func TestState_NoClusterCallWithoutPods(t *testing.T) {
svc, prov, _ := newTestService(t)
p := createReady(t, svc, prov, validInput())
if _, err := svc.Delete(p.ID); err != nil {
t.Fatal(err)
}
_, state, err := svc.State(context.Background(), p.ID)
if err != nil || state != (demos.ResourceState{}) {
t.Errorf("err=%v state=%+v, attendu un état vide", err, state)
}
if len(prov.stateCalls) != 0 {
t.Errorf("cluster interrogé pour un projet supprimé : %v", prov.stateCalls)
}
}
func TestState_UnknownProjectAndClusterError(t *testing.T) {
svc, prov, _ := newTestService(t)
if _, _, err := svc.State(context.Background(), "inconnu"); !errors.Is(err, ErrNotFound) {
t.Errorf("erreur %v, attendu ErrNotFound", err)
}
p := createReady(t, svc, prov, validInput())
prov.stateErr = errors.New("api k8s indisponible")
if _, _, err := svc.State(context.Background(), p.ID); err == nil {
t.Error("erreur du cluster avalée")
}
}