-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(alist_v3): set child paths so nested directories resolve #3019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Elity
wants to merge
2
commits into
OpenListTeam:main
Choose a base branch
from
Elity:fix/alist-v3-child-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package alist_v3 | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/OpenListTeam/OpenList/v4/drivers/base" | ||
| "github.com/OpenListTeam/OpenList/v4/internal/driver" | ||
| "github.com/OpenListTeam/OpenList/v4/internal/model" | ||
| "github.com/go-resty/resty/v2" | ||
| ) | ||
|
|
||
| // TestListSetsChildPaths descends two levels the way op.Get does, feeding an | ||
| // object from one listing back into List as dir. Without a Path on that object | ||
| // the driver asks upstream for "", which a real server answers with its own | ||
| // root -- hence the fake upstream's fallback, and the endless self-similar tree. | ||
| func TestListSetsChildPaths(t *testing.T) { | ||
| tree := map[string][]ObjResp{ | ||
| "/": {{Name: "root-marker", IsDir: true}}, | ||
| "/drive": {{Name: "concerts", IsDir: true}}, | ||
| "/drive/concerts": {{Name: "show.mkv"}}, | ||
| } | ||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| var req ListReq | ||
| _ = json.NewDecoder(r.Body).Decode(&req) | ||
| content, ok := tree[req.Path] | ||
| if !ok { | ||
| content = tree["/"] | ||
| } | ||
| w.Header().Set("Content-Type", "application/json") // resty only unmarshals JSON | ||
| _ = json.NewEncoder(w).Encode(map[string]any{ | ||
| "code": 200, "message": "success", | ||
| "data": map[string]any{"content": content, "total": len(content)}, | ||
| }) | ||
| })) | ||
| t.Cleanup(srv.Close) | ||
|
|
||
| // conf.Conf is nil outside a booted server, so base.InitClient() is unusable. | ||
| prev := base.RestyClient | ||
| base.RestyClient = resty.New().SetTimeout(5 * time.Second) | ||
| t.Cleanup(func() { base.RestyClient = prev }) | ||
|
|
||
| d := &AListV3{Addition: Addition{ | ||
| RootPath: driver.RootPath{RootFolderPath: "/drive"}, | ||
| Address: srv.URL, | ||
| }} | ||
| dir := model.Obj(&model.Object{Path: "/drive", IsFolder: true}) | ||
| for _, want := range []string{"/drive/concerts", "/drive/concerts/show.mkv"} { | ||
| objs, err := d.List(context.Background(), dir, model.ListArgs{}) | ||
| if err != nil { | ||
| t.Fatalf("List(%q): %v", dir.GetPath(), err) | ||
| } | ||
| if len(objs) != 1 { | ||
| t.Fatalf("List(%q) returned %d objects, want 1", dir.GetPath(), len(objs)) | ||
| } | ||
| if got := objs[0].GetPath(); got != want { | ||
| t.Fatalf("child of %q has path %q, want %q", dir.GetPath(), got, want) | ||
| } | ||
| dir = objs[0] | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest reducing the test code from 173 lines to around 20–50 lines, or just remove it. There’s no need to introduce an entire fake server just to cover a single line of production code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cut to a single test: 65 lines, 46 of them code. Dropped the second test, the
recordertype and the helper funcs, and inlined the driver setup.I kept the
httptestserver rather than removing the file.Listdoes its work over HTTP, so there is no seam to exercise it without a server — the alternative here is no test at all. The fake upstream falls back to its own root for unknown paths, which is what makes the loop reproduce; without the one-line fix it fails with:Happy to drop the file entirely if you would rather this package stay test-free.