forked from dan/liminix
1
0
Fork 0

test for acquire-wan-address

This commit is contained in:
Daniel Barlow 2023-09-11 00:07:49 +01:00
parent 7683ed69de
commit d49cbbb8ed
2 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,68 @@
(local subject (require :acquire-wan-address))
(local { : view } (require :fennel))
(local { : merge : dup } (require :anoia))
(local a1
{
"2001-ab-cd-ef_hjgKHGhKJH" {
:address "2001:ab:cd:ef"
:len "64"
:preferred "200"
:valid "200"
}
}
)
(local a2
{
"2001-0-1-2-3_aNteBnb" {
:address "2001:0:1:2:3"
:len "64"
:preferred "200"
:valid "200"
}
}
)
(macro expect [assertion]
(let [msg (.. "expectation failed: " (view assertion))]
`(when (not ,assertion)
(assert false ,msg))))
(fn first-address []
(let [(add del)
(subject.changes
{ }
a1
)]
(expect (= (# del) 0))
(expect (= (# add) 1))
(let [[first] add]
(expect (= first.address "2001:ab:cd:ef")))))
(fn second-address []
(let [(add del)
(subject.changes
a1
(merge (dup a1) a2)
)]
(expect (= (# del) 0))
(expect (= (# add) 1))
(let [[first] add] (expect (= first.address "2001:0:1:2:3")))))
(fn less-address []1
(let [(add del)
(subject.changes
(merge (dup a1) a2)
a1
)]
(expect (= (# add) 0))
(expect (= (# del) 1))
(let [[first] del] (expect (= first.address "2001:0:1:2:3")))))
(first-address)
(second-address)
(less-address)

View File

@ -2,6 +2,9 @@
(collect [k v (pairs table2) &into table1]
k v))
(fn dup [table]
(collect [k v (pairs table)] k v))
(fn split [sep string]
(icollect [v (string.gmatch string (.. "([^" sep "]+)"))]
v))
@ -56,4 +59,4 @@
(s:sub 1 (- (# s) pad))))
{ : merge : split : file-exists? : system : hash : base64url }
{ : merge : split : file-exists? : system : hash : base64url : dup }