projects/aports·blob master · refs

43 lines · 1.7 KiB

1Restore the server() test helper that the v1.1.7 tag left out.
2
3The tag carries api/api_authentication_test.go, which calls server(), but
4not api/helpers_test.go, where upstream main defines it:
5https://github.com/PlakarKorp/plakar/commit/1402c42194e55d0b8f1ba49513ac30980838d402
6Only server() is taken from main. Drop this patch when the release branch
7carries it.
8
9--- /dev/null
10+++ b/api/helpers_test.go
11@@ -0,0 +1,32 @@
12+package api
13+
14+import (
15+ "bytes"
16+ "net/http"
17+ "testing"
18+
19+ "github.com/PlakarKorp/kloset/repository"
20+ "github.com/PlakarKorp/kloset/snapshot"
21+ "github.com/PlakarKorp/plakar/appcontext"
22+ ptesting "github.com/PlakarKorp/plakar/testing"
23+)
24+
25+// server builds a real repository with a richer snapshot than newAPIServer
26+// (nested dirs, multiple files) and wires SetupRoutes with norefresh=true.
27+// Distinct name to avoid clashing with the team's newAPIServer helper.
28+func server(t *testing.T, token string) (*http.ServeMux, *repository.Repository, *snapshot.Snapshot, *appcontext.AppContext) {
29+ t.Helper()
30+ repo, ctx := ptesting.GenerateRepository(t, bytes.NewBuffer(nil), bytes.NewBuffer(nil), nil)
31+ snap := ptesting.GenerateSnapshot(t, repo, []ptesting.MockFile{
32+ ptesting.NewMockDir("subdir"),
33+ ptesting.NewMockFile("subdir/dummy.txt", 0644, "hello dummy"),
34+ ptesting.NewMockFile("subdir/foo.txt", 0644, "hello foo"),
35+ ptesting.NewMockFile("subdir/noext", 0644, "hello noext"),
36+ ptesting.NewMockDir("subdir/nested"),
37+ ptesting.NewMockFile("subdir/nested/deep.txt", 0644, "deep content"),
38+ ptesting.NewMockFile("top.txt", 0644, "top level"),
39+ })
40+ mux := http.NewServeMux()
41+ SetupRoutes(mux, repo, ctx, token, true /* norefresh */)
42+ return mux, repo, snap, ctx
43+}