-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathuseConfig.test.ts
More file actions
47 lines (38 loc) · 1.74 KB
/
useConfig.test.ts
File metadata and controls
47 lines (38 loc) · 1.74 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
import { assert, assertEquals, assertFalse, assertThrows, assertMatch } from "deno/assert/mod.ts"
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, [])
})