cicd: fix unit tests
This commit is contained in:
parent
f746095173
commit
ae533ffdfc
@ -11,27 +11,27 @@ func TestColorLed_Red(t *testing.T) {
|
|||||||
setLedBackup := setLed
|
setLedBackup := setLed
|
||||||
defer func() { setLed = setLedBackup }()
|
defer func() { setLed = setLedBackup }()
|
||||||
|
|
||||||
var colorValue int
|
ledColors := make(map[gpio.PinIO]int)
|
||||||
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
colorValue = v
|
ledColors[led] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
l := New()
|
l := New()
|
||||||
if l.Red() != 0 {
|
if l.Red() != 0 {
|
||||||
t.Errorf("%T.Red(): %v, wants %v", l, l.Red(), 0)
|
t.Errorf("%T.Red(): %v, wants %v", l, l.Red(), 0)
|
||||||
}
|
}
|
||||||
if colorValue != 0 {
|
if ledColors[l.pinRed] != 0 {
|
||||||
t.Errorf("colorValue: %v, wants %v", colorValue, 0)
|
t.Errorf("colorValue: %v, wants %v", ledColors[l.pinRed], 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
l.SetColor(ColorRed)
|
l.SetColor(ColorRed)
|
||||||
if l.Red() != 255 {
|
if l.Red() != 255 {
|
||||||
t.Errorf("%T.Red(): %v, wants %v", l, l.Red(), 255)
|
t.Errorf("%T.Red(): %v, wants %v", l, l.Red(), 255)
|
||||||
}
|
}
|
||||||
if colorValue != 255 {
|
if ledColors[l.pinRed] != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", colorValue, 255)
|
t.Errorf("colorValue: %v, wants %v", ledColors[l.pinRed], 255)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,27 +39,27 @@ func TestColorLed_Green(t *testing.T) {
|
|||||||
setLedBackup := setLed
|
setLedBackup := setLed
|
||||||
defer func() { setLed = setLedBackup }()
|
defer func() { setLed = setLedBackup }()
|
||||||
|
|
||||||
var colorValue int
|
ledColors := make(map[gpio.PinIO]int)
|
||||||
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
colorValue = v
|
ledColors[led] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
l := New()
|
l := New()
|
||||||
if l.Green() != 0 {
|
if l.Green() != 0 {
|
||||||
t.Errorf("%T.Green(): %v, wants %v", l, l.Green(), 0)
|
t.Errorf("%T.Green(): %v, wants %v", l, l.Green(), 0)
|
||||||
}
|
}
|
||||||
if colorValue != 0 {
|
if ledColors[l.pinGreen] != 0 {
|
||||||
t.Errorf("colorValue: %v, wants %v", colorValue, 0)
|
t.Errorf("colorValue: %v, wants %v", ledColors[l.pinGreen], 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
l.SetColor(ColorGreen)
|
l.SetColor(ColorGreen)
|
||||||
if l.Green() != 255 {
|
if l.Green() != 255 {
|
||||||
t.Errorf("%T.Green(): %v, wants %v", l, l.Green(), 255)
|
t.Errorf("%T.Green(): %v, wants %v", l, l.Green(), 255)
|
||||||
}
|
}
|
||||||
if colorValue != 255 {
|
if ledColors[l.pinGreen] != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", colorValue, 255)
|
t.Errorf("colorValue: %v, wants %v", ledColors[l.pinGreen], 255)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,27 +67,27 @@ func TestColorLed_Blue(t *testing.T) {
|
|||||||
setLedBackup := setLed
|
setLedBackup := setLed
|
||||||
defer func() { setLed = setLedBackup }()
|
defer func() { setLed = setLedBackup }()
|
||||||
|
|
||||||
var colorValue int
|
ledColors := make(map[gpio.PinIO]int)
|
||||||
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
colorValue = v
|
ledColors[led] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
l := New()
|
l := New()
|
||||||
if l.Blue() != 0 {
|
if l.Blue() != 0 {
|
||||||
t.Errorf("%T.Blue(): %v, wants %v", l, l.Blue(), 0)
|
t.Errorf("%T.Blue(): %v, wants %v", l, l.Blue(), 0)
|
||||||
}
|
}
|
||||||
if colorValue != 0 {
|
if ledColors[l.pinBlue] != 0 {
|
||||||
t.Errorf("colorValue: %v, wants %v", colorValue, 0)
|
t.Errorf("colorValue: %v, wants %v", ledColors[l.pinBlue], 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
l.SetColor(ColorBlue)
|
l.SetColor(ColorBlue)
|
||||||
if l.Blue() != 255 {
|
if l.Blue() != 255 {
|
||||||
t.Errorf("%T.Blue(): %v, wants %v", l, l.Blue(), 255)
|
t.Errorf("%T.Blue(): %v, wants %v", l, l.Blue(), 255)
|
||||||
}
|
}
|
||||||
if colorValue != 255 {
|
if ledColors[l.pinBlue] != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", colorValue, 255)
|
t.Errorf("colorValue: %v, wants %v", ledColors[l.pinBlue], 255)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,43 +96,43 @@ func TestColorLed_SetBlink(t *testing.T) {
|
|||||||
defer func() { setLed = setLedBackup }()
|
defer func() { setLed = setLedBackup }()
|
||||||
|
|
||||||
var muFakeValue sync.Mutex
|
var muFakeValue sync.Mutex
|
||||||
var colorValue int
|
ledColors := make(map[gpio.PinIO]int)
|
||||||
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
muFakeValue.Lock()
|
muFakeValue.Lock()
|
||||||
defer muFakeValue.Unlock()
|
defer muFakeValue.Unlock()
|
||||||
colorValue = v
|
ledColors[led] = v
|
||||||
}
|
}
|
||||||
readValue := func() int {
|
readValue := func(p gpio.PinIO) int {
|
||||||
muFakeValue.Lock()
|
muFakeValue.Lock()
|
||||||
defer muFakeValue.Unlock()
|
defer muFakeValue.Unlock()
|
||||||
return colorValue
|
return ledColors[p]
|
||||||
}
|
}
|
||||||
|
|
||||||
l := New()
|
l := New()
|
||||||
l.SetColor(ColorBlue)
|
l.SetColor(ColorBlue)
|
||||||
v := readValue()
|
v := ledColors[l.pinBlue]
|
||||||
if v != 255 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 255)
|
t.Errorf("colorValue: %v, wants %v", v, 255)
|
||||||
}
|
}
|
||||||
l.SetBlink(100)
|
l.SetBlink(100)
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 255 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 255)
|
t.Errorf("colorValue: %v, wants %v", v, 255)
|
||||||
}
|
}
|
||||||
time.Sleep(12 * time.Millisecond)
|
time.Sleep(12 * time.Millisecond)
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 0 {
|
if v != 0 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 0)
|
t.Errorf("colorValue: %v, wants %v", v, 0)
|
||||||
}
|
}
|
||||||
time.Sleep(12 * time.Millisecond)
|
time.Sleep(12 * time.Millisecond)
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 255 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 255)
|
t.Errorf("colorValue: %v, wants %v", v, 255)
|
||||||
}
|
}
|
||||||
time.Sleep(12 * time.Millisecond)
|
time.Sleep(12 * time.Millisecond)
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 0 {
|
if v != 0 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 0)
|
t.Errorf("colorValue: %v, wants %v", v, 0)
|
||||||
}
|
}
|
||||||
@ -140,12 +140,12 @@ func TestColorLed_SetBlink(t *testing.T) {
|
|||||||
// Stop blink
|
// Stop blink
|
||||||
l.SetBlink(0)
|
l.SetBlink(0)
|
||||||
time.Sleep(5 * time.Millisecond)
|
time.Sleep(5 * time.Millisecond)
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 255 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 255)
|
t.Errorf("colorValue: %v, wants %v", v, 255)
|
||||||
}
|
}
|
||||||
time.Sleep(12 * time.Millisecond)
|
time.Sleep(12 * time.Millisecond)
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 255 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 255)
|
t.Errorf("colorValue: %v, wants %v", v, 255)
|
||||||
}
|
}
|
||||||
@ -156,45 +156,45 @@ func TestColorLed_SetBlinkAndUpdadeColor(t *testing.T) {
|
|||||||
defer func() { setLed = setLedBackup }()
|
defer func() { setLed = setLedBackup }()
|
||||||
|
|
||||||
var muFakeValue sync.Mutex
|
var muFakeValue sync.Mutex
|
||||||
var colorValue int
|
ledColors := make(map[gpio.PinIO]int)
|
||||||
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
setLed = func(v int, led gpio.PinIO, mutex *sync.Mutex) {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
muFakeValue.Lock()
|
muFakeValue.Lock()
|
||||||
defer muFakeValue.Unlock()
|
defer muFakeValue.Unlock()
|
||||||
colorValue = v
|
ledColors[led] = v
|
||||||
}
|
}
|
||||||
readValue := func() int {
|
readValue := func(p gpio.PinIO) int {
|
||||||
muFakeValue.Lock()
|
muFakeValue.Lock()
|
||||||
defer muFakeValue.Unlock()
|
defer muFakeValue.Unlock()
|
||||||
return colorValue
|
return ledColors[p]
|
||||||
}
|
}
|
||||||
|
|
||||||
l := New()
|
l := New()
|
||||||
l.SetColor(ColorBlue)
|
l.SetColor(ColorBlue)
|
||||||
l.SetBlink(100)
|
l.SetBlink(100)
|
||||||
v := readValue()
|
v := readValue(l.pinBlue)
|
||||||
if v != 255 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 255)
|
t.Errorf("colorValue: %v, wants %v", v, 255)
|
||||||
}
|
}
|
||||||
time.Sleep(6 * time.Millisecond)
|
time.Sleep(6 * time.Millisecond)
|
||||||
l.SetColor(ColorBlue)
|
l.SetColor(ColorBlue)
|
||||||
|
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 128 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 128)
|
t.Errorf("colorValue: %v, wants %v", v, 128)
|
||||||
}
|
}
|
||||||
time.Sleep(6 * time.Millisecond)
|
time.Sleep(6 * time.Millisecond)
|
||||||
|
|
||||||
time.Sleep(12 * time.Millisecond)
|
time.Sleep(12 * time.Millisecond)
|
||||||
|
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 128 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 128)
|
t.Errorf("colorValue: %v, wants %v", v, 128)
|
||||||
}
|
}
|
||||||
time.Sleep(12 * time.Millisecond)
|
time.Sleep(12 * time.Millisecond)
|
||||||
|
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 0 {
|
if v != 0 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 0)
|
t.Errorf("colorValue: %v, wants %v", v, 0)
|
||||||
}
|
}
|
||||||
@ -202,13 +202,13 @@ func TestColorLed_SetBlinkAndUpdadeColor(t *testing.T) {
|
|||||||
// Stop blink
|
// Stop blink
|
||||||
l.SetBlink(0)
|
l.SetBlink(0)
|
||||||
time.Sleep(5 * time.Millisecond)
|
time.Sleep(5 * time.Millisecond)
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 128 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 128)
|
t.Errorf("colorValue: %v, wants %v", v, 128)
|
||||||
}
|
}
|
||||||
time.Sleep(12 * time.Millisecond)
|
time.Sleep(12 * time.Millisecond)
|
||||||
v = readValue()
|
v = readValue(l.pinBlue)
|
||||||
if v != 128 {
|
if v != 255 {
|
||||||
t.Errorf("colorValue: %v, wants %v", v, 128)
|
t.Errorf("colorValue: %v, wants %v", v, 128)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user