add TestMode to run actions without effect

This commit is contained in:
2023-08-16 01:27:28 +02:00
parent 381cc31d4b
commit 8f6fc72bfb
7 changed files with 56 additions and 20 deletions

View File

@@ -25,7 +25,6 @@ func isEthernetConnected(deviceName string) bool {
}
if string(content[:4]) == "down" {
fmt.Println("Ethernet is disconnected")
return false
}
@@ -33,25 +32,21 @@ func isEthernetConnected(deviceName string) bool {
}
func (t EthernetDisconnect) Listen() {
fmt.Println("EthernetDisconnect listens")
if t.WaitTillConnected {
for !isEthernetConnected("enp0s31f6") {
for !isEthernetConnected(t.InterfaceName) {
time.Sleep(1 * time.Second)
}
}
for {
if !isEthernetConnected("enp0s31f6") {
fmt.Println("Ethernet is disconnected")
if !isEthernetConnected(t.InterfaceName) {
break
}
time.Sleep(1 * time.Second)
}
fmt.Println("EthernetDisconnect fires")
t.action.Execute()
actions.Fire(t.action)
}
// func NewTimeOut(d time.Duration, action actions.Action) EthernetDisconnect {
@@ -60,17 +55,12 @@ func NewEthernetDisconnect(config internal.KillSwitchConfig) (EthernetDisconnect
WaitTillConnected: true,
}
fmt.Println(string(config.Options))
err := json.Unmarshal(config.Options, &result)
fmt.Println(result)
if err != nil {
return EthernetDisconnect{}, err
}
fmt.Println(result.InterfaceName)
if result.InterfaceName == "" {
return EthernetDisconnect{}, internal.OptionMissingError{"interfaceName"}
}

View File

@@ -10,19 +10,20 @@ import (
)
type TimeOut struct {
d time.Duration
action actions.Action
Duration int
action actions.Action
}
func (t TimeOut) Listen() {
fmt.Println("TimeOut listens")
time.Sleep(t.d)
fmt.Println(t.Duration)
time.Sleep(time.Duration(t.Duration) * time.Second)
fmt.Println("TimeOut fires")
t.action.Execute()
actions.Fire(t.action)
}
func NewTimeOut(config internal.KillSwitchConfig) (TimeOut, error) {
result := TimeOut{d: 0 * time.Second}
var result TimeOut
err := json.Unmarshal(config.Options, &result)
if err != nil {