-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnix_test.ts
65 lines (51 loc) · 1.85 KB
/
nix_test.ts
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
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { Obj, Str, Let, Fun, Arr, Import, With, Call, SvcMod } from "./nix.ts";
Deno.test("nix obj", () => {
const result = Obj({ a: Str("b") });
assertEquals(result, '{a="b";}');
});
Deno.test("nix fun let", () => {
const result = Fun("arg", Let({ a: "arg + " + Str("hello") }, "a"));
assertEquals(result, 'arg: let a=arg + "hello"; in a');
});
Deno.test("nix fun array", () => {
const result = Arr("hello", "you");
assertEquals(result, "[hello you]");
});
Deno.test("nix with", () => {
const result = With("hello", "you");
assertEquals(result, "with hello; you");
});
Deno.test("nix function call", () => {
const result = Call("hi", Str("you"));
assertEquals(result, 'hi "you"');
});
Deno.test("nix flake outputs", () => {
const result = Fun(
["nixpkgs"],
Let(
{
pkgs: Import("nixpkgs", Obj({ sys: Str("x86") })),
},
Obj({ "pkg.x86.hello": "pkgs.hello" })
)
);
assertEquals(
result,
'{nixpkgs}: let pkgs=import nixpkgs {sys="x86";}; in {pkg.x86.hello=pkgs.hello;}'
);
});
Deno.test("nix service module", () => {
const result = SvcMod({
name: "dns-heaven",
package: "dns-heaven",
options: {
address: "127.0.0.1:53",
},
args: [Str("-address"), "cfg.address"],
});
assertEquals(
result,
'{config,lib,pkgs,...}: with lib; let cfg=config.services.dns-heaven; in {options={services.dns-heaven={enable=mkOption {type=types.bool;default=false;};package=mkOption {type=types.package;default=pkgs.dns-heaven;};address=mkOption {type=types.str;default="127.0.0.1:53";};};};config=mkIf cfg.enable {environment.systemPackages=[cfg.package];launchd.daemons.dns-heaven.serviceConfig={ProgramArguments=["${cfg.package}/bin/dns-heaven" "-address" cfg.address];RunAtLoad=true;KeepAlive=true;};};}'
);
});