feat: LedEngine for controlling LED patterns (e.g. burst blinks)

Signed-off-by: Matthias Riegler <matthias.riegler@ankorstore.com>
This commit is contained in:
Matthias Riegler
2023-07-17 07:01:54 +02:00
parent dd49079918
commit 752d39697e
6 changed files with 530 additions and 4 deletions

24
pkg/util/clock.go Normal file
View File

@@ -0,0 +1,24 @@
package util
import (
"time"
)
// Clock is an interface for the time package
type Clock interface {
// Now returns the current time.
Now() time.Time
// After waits for the duration to elapse and then sends the current time
After(d time.Duration) <-chan time.Time
}
// RealClock implements the Clock interface using the real time package.
type RealClock struct{}
func (RealClock) Now() time.Time {
return time.Now()
}
func (RealClock) After(d time.Duration) <-chan time.Time {
return time.After(d)
}

24
pkg/util/clock_mock.go Normal file
View File

@@ -0,0 +1,24 @@
package util
import (
"time"
"github.com/stretchr/testify/mock"
)
// MockClock implements the Clock interface using the testify mock package.
type MockClock struct {
mock.Mock
}
// Now returns the current time.
func (mc *MockClock) Now() time.Time {
args := mc.Called()
return args.Get(0).(time.Time)
}
// After waits for the duration to elapse and then sends the current time
func (mc *MockClock) After(d time.Duration) <-chan time.Time {
args := mc.Called(d)
return args.Get(0).(chan time.Time)
}