puerta/internal/door/mock.go

52 lines
835 B
Go
Raw Permalink Normal View History

2022-12-30 06:51:51 +00:00
// SPDX-License-Identifier: Apache-2.0
// Copyright © 2022 Roberto Hidalgo <nidito@un.rob.mx>
package door
import (
"time"
"github.com/sirupsen/logrus"
)
func init() {
_register("dry-run", NewMock)
}
type mockDoor struct {
Status bool
FailedToOpen error
FailedToClose error
}
func NewMock(config map[string]any) (Door, error) {
2022-12-30 06:51:51 +00:00
logrus.Info("Initializing mock client")
return &mockDoor{
Status: false,
}, nil
2022-12-30 06:51:51 +00:00
}
func (md *mockDoor) IsOpen() (bool, error) {
return md.Status, nil
}
func (md *mockDoor) Open(errors chan<- error, done chan<- bool) {
defer close(errors)
if md.FailedToOpen != nil {
errors <- md.FailedToOpen
return
}
md.Status = true
errors <- nil
time.Sleep(4 * time.Second)
md.Status = false
if md.FailedToClose != nil {
errors <- md.FailedToClose
return
}
done <- true
}