mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
471d237af0
Update route assertions and regenerate swagger so the process no longer documents /api/cap or /api/health.
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"Wavelet/core"
|
|
)
|
|
|
|
func testSource(t *testing.T) core.ConfigSource {
|
|
t.Helper()
|
|
return core.NewMapSource(map[string]any{
|
|
"app": map[string]any{
|
|
"addr": "127.0.0.1:0",
|
|
"env": "testing",
|
|
},
|
|
"redis": map[string]any{
|
|
"enabled": false,
|
|
},
|
|
"database": map[string]any{
|
|
"enabled": false,
|
|
"sqlite_path": filepath.Join(t.TempDir(), "openflare-cmd.db"),
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestNewOpenFlareAppRegistersServerAndWaveletUser(t *testing.T) {
|
|
app := newOpenFlareApp(core.ProfileAPI, core.WithConfigSource(testSource(t)))
|
|
if err := app.Prepare(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
names := map[string]bool{}
|
|
for _, p := range app.Plugins() {
|
|
names[p.Name()] = true
|
|
}
|
|
for _, n := range []string{"user", "auth", "cap", "admin", "server"} {
|
|
if !names[n] {
|
|
t.Errorf("missing plugin %s", n)
|
|
}
|
|
}
|
|
|
|
if err := app.Reconcile(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
got := map[string]bool{}
|
|
for _, rd := range app.Context().Router().Routes() {
|
|
got[rd.Method+" "+rd.Path] = true
|
|
}
|
|
for _, want := range []string{
|
|
"GET /api/healthz",
|
|
"GET /api/v1/user/self",
|
|
"GET /api/v1/d/nodes",
|
|
"POST /api/v1/cap/challenge",
|
|
} {
|
|
if !got[want] {
|
|
t.Errorf("missing route %s", want)
|
|
}
|
|
}
|
|
for _, drop := range []string{
|
|
"GET /api/health",
|
|
"GET /healthz",
|
|
"POST /api/cap/challenge",
|
|
} {
|
|
if got[drop] {
|
|
t.Errorf("removed route still registered: %s", drop)
|
|
}
|
|
}
|
|
}
|