-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathuseConfig.test.ts
More file actions
69 lines (58 loc) · 2.79 KB
/
useConfig.test.ts
File metadata and controls
69 lines (58 loc) · 2.79 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
import { assert, assertEquals, assertFalse, assertThrows, assertMatch } from "@std/assert"
import { _internals, ConfigDefault } from "./useConfig.ts"
import { useTestConfig } from "./useTestConfig.ts"
import Path from "../utils/Path.ts"
Deno.test("useConfig", () => {
let config = useTestConfig()
if (Deno === undefined) {
assertMatch(config.UserAgent!, /libpkgx\/\d+\.\d+.\d+/)
} else {
assertEquals(config.UserAgent, "libpkgx")
}
const PKGX_PANTRY_PATH = Deno.build.os == 'windows' ? "C:\\foo;D:\\bar" : "/foo:/bar"
config = ConfigDefault({ PKGX_PANTRY_PATH, CI: "true" })
if (Deno.build.os == 'windows') {
assertEquals(config.pantries.map(x => x.string), ["C:\\foo", "D:\\bar"])
} else {
assertEquals(config.pantries.map(x => x.string), ["/foo", "/bar"])
}
assertEquals(config.options.compression, "gz")
assertFalse(_internals.boolize("false"))
assertFalse(_internals.boolize("0"))
assertFalse(_internals.boolize("no"))
assert(_internals.boolize("1"))
assert(_internals.boolize("yes"))
assert(_internals.initialized())
})
Deno.test("useConfig empty PKGX_DIR is ignored", () => {
assertEquals(ConfigDefault({ PKGX_DIR: "" }).prefix, Path.home().join(".pkgx"))
assertEquals(ConfigDefault({ PKGX_DIR: " " }).prefix, Path.home().join(".pkgx"))
assertEquals(ConfigDefault({ PKGX_DIR: " / " }).prefix, Path.root)
assertThrows(() => ConfigDefault({ PKGX_DIR: " foo " }))
assertThrows(() => ConfigDefault({ PKGX_DIR: "foo" }))
})
Deno.test("useConfig empty PKGX_PANTRY_PATH is ignored", () => {
const SEP = Deno.build.os == 'windows' ? ';' : ':'
assertEquals(ConfigDefault({ PKGX_PANTRY_PATH: "" }).pantries, [])
assertEquals(ConfigDefault({ PKGX_PANTRY_PATH: ` ${SEP} ${SEP}` }).pantries, [])
})
Deno.test("pkgx^2 rules", () => {
switch (Deno.build.os) {
case 'windows':
assertEquals(ConfigDefault({ XDG_DATA_HOME: "C:\\foo" }).data, Path.home().join("AppData/Local"));
assertEquals(ConfigDefault().data, Path.home().join("AppData/Local"));
assertEquals(ConfigDefault({ XDG_CACHE_HOME: "C:\\foo" }).cache, Path.home().join("AppData/Local"));
assertEquals(ConfigDefault().cache, Path.home().join("AppData/Local"));
break;
case 'darwin':
assertEquals(ConfigDefault({ XDG_DATA_HOME: "/foo" }).data, Path.home().join("Library/Application Support/pkgx"));
assertEquals(ConfigDefault().data, Path.home().join("Library/Application Support/pkgx"));
assertEquals(ConfigDefault({ XDG_CACHE_HOME: "/foo" }).cache, Path.home().join("Library/Caches/pkgx"));
assertEquals(ConfigDefault().cache, Path.home().join("Library/Caches/pkgx"));
break;
case 'linux':
assertEquals(ConfigDefault({ XDG_DATA_HOME: "/foo" }).data, new Path("/foo/pkgx"));
assertEquals(ConfigDefault().data, Path.home().join(".local/share/pkgx"));
break;
}
})