Repository navigation
Expand file tree
/
Copy pathfolderissue_test.go
More file actions
87 lines (81 loc) · 3.38 KB
/
Copy pathfolderissue_test.go
File metadata and controls
87 lines (81 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/ApolloF/syncer/internal/syncthing"
)
func TestFolderErrorsInPlainWords(t *testing.T) {
for msg, want := range map[string]string{
"folder marker missing (this indicates potential data loss, search docs/forum to get information about how to proceed)": "The folder was emptied or replaced outside Syncer, so syncing stopped to protect the other PCs' copies.",
"folder path missing": "The folder is gone.",
"folder path not a directory": "There's a file where the folder should be.",
"insufficient space on disk for database (C:)": "The disk is almost full, so syncing stopped.",
"something new from Syncthing": "Something new from Syncthing.",
} {
if got := plainFolderError(msg); got != want {
t.Errorf("%q: %q, want %q", msg, got, want)
}
}
for msg, want := range map[string]string{
"opening temp file: The process cannot access the file because it is being used by another process.": "it's open in another program; is the game running?",
"no connected device has the required version of this file": "no PC that has it is online",
"pull: Access is denied.": "Syncthing isn't allowed to change it",
"something else": "something else",
} {
if got := plainFileError(msg); got != want {
t.Errorf("%q: %q, want %q", msg, got, want)
}
}
}
// fakeSyncthing answers /rest/folder/errors with one file that couldn't be
// synced.
func fakeSyncthing(t *testing.T) *syncthing.Client {
t.Helper()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/rest/folder/errors" {
http.NotFound(w, r)
return
}
_, _ = w.Write([]byte(`{"folder":"f","errors":[{"path":"Saves/slot1.sav","error":"The process cannot access the file because it is being used by another process."}],"page":1,"perpage":1}`))
}))
t.Cleanup(srv.Close)
c, err := syncthing.NewAt(strings.TrimPrefix(srv.URL, "http://"), "key")
if err != nil {
t.Fatal(err)
}
return c
}
func TestEveryFolderIssueCountedIsExplained(t *testing.T) {
c := fakeSyncthing(t)
ctx := context.Background()
for _, c2 := range []struct {
st syncthing.FolderStatus
want string
}{
{syncthing.FolderStatus{State: "idle"}, ""},
{syncthing.FolderStatus{State: "error", Error: "folder path missing"}, "The folder is gone."},
{syncthing.FolderStatus{State: "error"}, "Syncthing stopped syncing this folder."},
{syncthing.FolderStatus{State: "idle", Errors: 2, PullErrors: 2}, "2 files can't be synced: Saves/slot1.sav (it's open in another program; is the game running?)."},
{syncthing.FolderStatus{State: "idle", PullErrors: 1}, "1 file can't be synced: Saves/slot1.sav (it's open in another program; is the game running?)."},
} {
got := folderIssue(ctx, c, "f", c2.st)
if got != c2.want {
t.Errorf("%+v: %q, want %q", c2.st, got, c2.want)
}
if hasIssue(c2.st) != (got != "") {
t.Errorf("%+v: counted %v but explained as %q", c2.st, hasIssue(c2.st), got)
}
}
}
func TestFileIssueWithoutDetailsStillSaysWhat(t *testing.T) {
c, err := syncthing.NewAt("127.0.0.1:1", "key") // nothing answers
if err != nil {
t.Fatal(err)
}
if got := folderIssue(context.Background(), c, "f", syncthing.FolderStatus{Errors: 3}); got != "3 files can't be synced." {
t.Errorf("got %q", got)
}
}