- Lecture des dist-tags npm (latest, next) en une requête ; /api/update
expose tags{latest,next} (latest conservé pour compatibilité).
- Paramètre channel (latest par défaut) dans DATA_DIR/.settings.json,
modifiable par PUT /api/settings {"channel":...} ; titre et canal sont
mis à jour indépendamment, sous verrou.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019EuvvuTv7AUc8ksDHv8VKx
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package update
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCheck(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/-/package/@excalidraw/excalidraw/dist-tags" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
_, _ = w.Write([]byte(`{"latest":"0.19.0","next":"0.19.0-abc1234","rc":"0.19.0-rc.1"}`))
|
|
}))
|
|
defer srv.Close()
|
|
|
|
c := &Checker{Registry: srv.URL, Interval: time.Hour, Client: srv.Client()}
|
|
if s := c.Status(); !s.Enabled || s.Latest != "" {
|
|
t.Fatalf("avant vérification : %+v", s)
|
|
}
|
|
c.check(context.Background())
|
|
s := c.Status()
|
|
if s.Latest != "0.19.0" || s.Tags["next"] != "0.19.0-abc1234" || s.CheckedAt == nil {
|
|
t.Fatalf("après vérification : %+v", s)
|
|
}
|
|
if _, ok := s.Tags["rc"]; ok {
|
|
t.Fatalf("canal non proposé exposé : %+v", s.Tags)
|
|
}
|
|
}
|
|
|
|
func TestCheckKeepsLastValueOnError(t *testing.T) {
|
|
ok := true
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if !ok {
|
|
http.Error(w, "panne", http.StatusBadGateway)
|
|
return
|
|
}
|
|
_, _ = w.Write([]byte(`{"latest":"0.18.2"}`))
|
|
}))
|
|
defer srv.Close()
|
|
|
|
c := &Checker{Registry: srv.URL, Interval: time.Hour, Client: srv.Client()}
|
|
c.check(context.Background())
|
|
ok = false
|
|
c.check(context.Background())
|
|
if s := c.Status(); s.Latest != "0.18.2" {
|
|
t.Fatalf("valeur perdue après une erreur : %+v", s)
|
|
}
|
|
}
|
|
|
|
func TestNilCheckerIsDisabled(t *testing.T) {
|
|
var c *Checker
|
|
if s := c.Status(); s.Enabled {
|
|
t.Fatalf("checker nil : %+v", s)
|
|
}
|
|
}
|