From 5d5dff6729d764d8dc76ae68b32221bcc4557d40 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 6 Mar 2024 00:32:38 +0000 Subject: [PATCH] WIP add failing test that service starts --- pkgs/ifwait/ifwait.fnl | 3 ++- pkgs/ifwait/test-ifwait.fnl | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/pkgs/ifwait/ifwait.fnl b/pkgs/ifwait/ifwait.fnl index 64d3825..d3b9c54 100644 --- a/pkgs/ifwait/ifwait.fnl +++ b/pkgs/ifwait/ifwait.fnl @@ -2,12 +2,13 @@ ; (local { : view} (require :fennel)) -(local { : assoc } (require :anoia)) +(local { : assoc : system } (require :anoia)) (fn parse-args [args] (match args ["-v" & rest] (assoc (parse-args rest) :verbose true) ["-t" timeout & rest] (assoc (parse-args rest) :timeout (tonumber timeout)) + ["-s" service & rest] (assoc (parse-args rest) :service service) [linkname "up"] {:link linkname :expecting "up"} [linkname "running"] {:link linkname :expecting "running"} [linkname "present"] {:link linkname :expecting "present"} diff --git a/pkgs/ifwait/test-ifwait.fnl b/pkgs/ifwait/test-ifwait.fnl index 3c8bdd7..eef6acd 100644 --- a/pkgs/ifwait/test-ifwait.fnl +++ b/pkgs/ifwait/test-ifwait.fnl @@ -1,4 +1,8 @@ -(local fennel (require :fennel)) +(local { : view &as fennel } (require :fennel)) +(local anoia (require :anoia)) + +(var fake-system (fn [s] (print "executing " s))) +(tset anoia :system #(fake-system $1)) (fn event-generator [events] (coroutine.wrap @@ -19,3 +23,30 @@ (match (pcall gen) (true _) true (false msg) (error "didn't detect dummy0 up event"))) + +(var succeeded? false) +(set fake-system + (fn [s] + (print "exec" s) + (if (s:match "addmember") (set succeeded? true)))) + +(let [events + [{:event "newlink" + :hwaddr "b6:7d:5c:38:89:1d" + :index 21 + :mtu 1500 + :name "dummy0" + :running "no" + :stamp 857161382 + :up "no"} + {:event "newlink" + :hwaddr "52:f0:46:da:0c:0c" + :index 22 + :mtu 1500 + :name "dummy0" + :running "no" + :stamp 857161383 + :up "yes"}] + gen (event-generator events)] + (ifwait.run ["-v" "-s" "addmember" "dummy0" "up"] #gen) + (assert succeeded?))