-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.js
226 lines (190 loc) · 6.97 KB
/
main_test.js
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import { test } from "node:test";
import { assert, assertEquals } from "./dev_deps.js";
import { config } from "./mod.js";
test("fetch", async (t) => {
await t.test("global", async () => {
const controller = new AbortController();
Deno.serve({
port: 0,
signal: controller.signal,
async onListen({ port, hostname }) {
const url = `http://${hostname}:${port}/`;
let response = await fetch(url, {
method: "HEAD",
});
assert(response.ok);
const request = new Request(url, {
method: "HEAD",
});
response = await fetch(request);
assert(response.ok);
controller.abort();
},
}, (_request) => {
return new Response();
});
});
await t.test("TRACE", async (t) => {
await t.test("/path/to/dir/", async () => {
const cwd = Deno.cwd();
const response = await fetch(cwd, {
method: "TRACE",
});
const { status, headers } = response;
assertEquals(status, 200);
assertEquals(headers.get("Content-Type"), "message/http");
assertEquals(headers.get("Via"), "local/1.1");
const body = await response.text();
const [, _method, url] = body.match(/^(TRACE) (.*) HTTP\/1.1$/m) || [];
const { pathname } = new URL(url, "file:");
assertEquals(pathname, cwd);
});
// Sets up
await Deno.writeFile("rclone.conf", new Uint8Array());
await config("create", "source", {
type: "local",
});
await config("create", "target", {
type: "alias",
remote: "source:",
});
await t.test(":type:", async () => {
const { status, headers } = await fetch(":local:", {
method: "TRACE",
});
assertEquals(status, 200);
assertEquals(headers.get("Content-Type"), "message/http");
assertEquals(headers.get("Via"), "local/1.1");
});
await t.test("name:", async () => {
const { status, headers } = await fetch("source:", {
method: "TRACE",
});
assertEquals(status, 200);
assertEquals(headers.get("Content-Type"), "message/http");
assertEquals(headers.get("Via"), "local/1.1 source");
});
/** Connection string */
await t.test("name,param1=value1,param2=value2:", async (t) => {
const cwd = Deno.cwd();
await t.test("params from config", async () => {
const response = await fetch("target:", {
method: "TRACE",
});
const { status, headers } = response;
assertEquals(status, 200);
assertEquals(headers.get("Content-Type"), "message/http");
assertEquals(headers.get("Via"), "alias/1.1 target");
const body = await response.text();
const [, _method, url] = body.match(/^(TRACE) (.*) HTTP\/1.1$/m) || [];
const { pathname, searchParams } = new URL(url, "file:");
assertEquals(pathname, "/");
assertEquals(searchParams.get("remote"), `source:`);
});
await t.test(
"overriden by backend generic environment vars",
async () => {
Deno.env.set("RCLONE_SKIP_LINKS", "true");
const response = await fetch("target:", {
method: "TRACE",
});
const body = await response.text();
const [, _method, url] = body.match(/^(TRACE) (.*) HTTP\/1.1$/m) ||
[];
const { searchParams } = new URL(url, "file:");
assertEquals(searchParams.get("remote"), `source:`);
assertEquals(searchParams.get("skip_links"), `true`);
},
);
await t.test(
"overriden by backend-specific environment vars",
async () => {
Deno.env.set("RCLONE_ALIAS_REMOTE", "/tmp/1");
const response = await fetch("target:", {
method: "TRACE",
});
const body = await response.text();
const [, _method, url] = body.match(/^(TRACE) (.*) HTTP\/1.1$/m) ||
[];
const { searchParams } = new URL(url, "file:");
assertEquals(searchParams.get("remote"), `/tmp/1`);
assert(
!searchParams.has("alias_remote"),
"should not have param prefixed with backend type",
);
},
);
await t.test(
"overriden by remote specific environment vars",
async () => {
Deno.env.set("RCLONE_CONFIG_TARGET_REMOTE", "/tmp/2");
const response = await fetch("target:", {
method: "TRACE",
});
const body = await response.text();
const [, _method, url] = body.match(/^(TRACE) (.*) HTTP\/1.1$/m) ||
[];
const { searchParams } = new URL(url, "file:");
assertEquals(searchParams.get("remote"), `/tmp/2`);
assert(
!searchParams.has("config_target_remote"),
"should not have param prefixed with remote name",
);
},
);
await t.test(
"overriden by flags prefixed with backend type",
async () => {
const response = await fetch("target:?alias_remote='/tmp/3'", {
method: "TRACE",
});
const { status, headers } = response;
assertEquals(status, 200);
assertEquals(headers.get("Content-Type"), "message/http");
assertEquals(headers.get("Via"), "alias/1.1 target");
const body = await response.text();
const [, _method, url] = body.match(/^(TRACE) (.*) HTTP\/1.1$/m) ||
[];
const { pathname, searchParams } = new URL(url, "file:");
assertEquals(pathname, "/");
assertEquals(searchParams.get("remote"), `'/tmp/3'`);
},
);
await t.test("overriden by params in connection string", async () => {
const response = await fetch(
`target,remote='${cwd}':?alias_remote='/tmp/3'`,
{
method: "TRACE",
},
);
const body = await response.text();
const [, _method, url] = body.match(/^(TRACE) (.*) HTTP\/1.1$/m) || [];
const { pathname, searchParams } = new URL(url, "file:");
assertEquals(pathname, "/");
assertEquals(searchParams.get("remote"), `'${cwd}'`);
});
await t.test(
"overriden by params in connection string that is also a connection string",
async () => {
const response = await fetch(
`target,remote=':local,case_sensitive=true:${cwd}':?alias_remote='/tmp/3'`,
{
method: "TRACE",
},
);
const body = await response.text();
const [, _method, url] = body.match(/^(TRACE) (.*) HTTP\/1.1$/m) ||
[];
const { pathname, searchParams } = new URL(url, "file:");
assertEquals(pathname, "/");
assertEquals(searchParams.get("remote"), `':local:${cwd}'`);
},
);
});
// Tears down
await Deno.remove("rclone.conf");
Deno.env.delete("RCLONE_SKIP_LINKS");
Deno.env.delete("RCLONE_ALIAS_REMOTE");
Deno.env.delete("RCLONE_CONFIG_TARGET_REMOTE");
});
});