tests: add cram based unit tests
[project/uci.git] / tests / cram / lua / basic.lua
1 local A = assert
2 local c = uci.cursor(os.getenv("CONFIG_DIR"))
3
4 c:foreach("network", "interface", function(s)
5 print("---------------")
6 for k, v in pairs(s) do
7 print(k .. ': ' .. tostring(v))
8 end
9 end)
10
11 local t = c:get_all("network")
12
13 A(t.wan.ifname == 'eth1')
14 A(t.wan.proto == 'dhcp')
15 A(c:get("network", "wan", "ifname") == "eth1")
16 A(c:get("network", "wan", "proto") == "dhcp")
17
18 A(t.lan.ifname == 'eth0')
19 A(t.lan.enabled == 'off')
20 A(c:get("network", "lan", "ifname") == "eth0")
21 A(c:get("network", "lan", "enabled") == "off")
22
23 A(c:set("network", "lan", "ifname", "eth5"))
24 A(c:get("network", "lan", "ifname") == "eth5")
25 A(c:revert("network"))
26 A(c:get("network", "lan", "ifname") == "eth0")
27
28 A(c:set("network", "lan", "ifname", "eth5"))
29 A(c:get("network", "lan", "ifname") == "eth5")
30 A(c:commit("network"))
31 A(c:set("network", "lan", "ifname", "eth0"))
32 A(c:revert("network"))
33 A(c:commit("network"))
34 A(c:get("network", "lan", "ifname") == "eth5")
35
36 A(c:set("network", "lan", "dns", {
37 "ns1.king.banik.cz",
38 "ns2.openwrt.org",
39 }))
40
41 local t = c:get("network", "lan", "dns")
42 A(#t == 2)
43 A(t[1] == "ns1.king.banik.cz")
44 A(t[2] == "ns2.openwrt.org")