feat: complete remaining Go backend modules
This commit is contained in:
1 parent
cea2751dc5
commit
aef5a97165
145 files changed
+18376
-199
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGoRouteSurfaceExactlyMatchesCheckedInNextManifest(t *testing.T) {
|
||||
_, source, _, _ := runtime.Caller(0)
|
||||
raw, err := os.ReadFile(filepath.Join(filepath.Dir(source), "../../../contracts/http/route-surface.v1.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var fixture struct {
|
||||
Version int `json:"version"`
|
||||
Routes []RouteSurface `json:"routes"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &fixture); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if fixture.Version != 1 {
|
||||
t.Fatalf("version=%d", fixture.Version)
|
||||
}
|
||||
got := GoRouteSurface()
|
||||
less := func(items []RouteSurface) {
|
||||
sort.Slice(items, func(i, j int) bool {
|
||||
if items[i].Method != items[j].Method {
|
||||
return items[i].Method < items[j].Method
|
||||
}
|
||||
return items[i].Path < items[j].Path
|
||||
})
|
||||
}
|
||||
less(got)
|
||||
less(fixture.Routes)
|
||||
if !reflect.DeepEqual(got, fixture.Routes) {
|
||||
t.Fatalf("Go route surface drift\ngot=%#v\nwant=%#v", got, fixture.Routes)
|
||||
}
|
||||
}
|
||||
func TestMatchSurfacePath(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
pattern, path string
|
||||
want bool
|
||||
}{{"/api/x/{id}", "/api/x/a", true}, {"/api/x/{id}", "/api/x/a/b", false}, {"/uploads/{path...}", "/uploads/a/b", true}, {"/uploads/{path...}", "/uploads/", false}, {"/generated-results/{path...}", "/generated-results/", false}, {"/api/health", "/api/health", true}} {
|
||||
if got := MatchSurfacePath(test.pattern, test.path); got != test.want {
|
||||
t.Fatalf("%q %q=%v", test.pattern, test.path, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user