Files
cloud-services/pkg/common/ecu_dtc_test.go

63 lines
1.2 KiB
Go

package common
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDTCStatusByte(t *testing.T){
fakeDTC := DTC_ECU{}
fakeDTC.StatusByte = 0x09
dtcArrayCheck(t, fakeDTC, []DTCStatusByteMeaning{Bit4, Bit7})
fakeDTC.StatusByte = 0x00
dtcArrayCheck(t, fakeDTC, []DTCStatusByteMeaning{})
fakeDTC.StatusByte = 0x2F
dtcArrayCheck(t, fakeDTC, []DTCStatusByteMeaning{Bit7, Bit6, Bit5, Bit4, Bit2})
}
func dtcArrayCheck(t *testing.T, fakeDTC DTC_ECU, expected []DTCStatusByteMeaning){
statuses := fakeDTC.DTCStatusByteMeaning()
for _, exp := range expected{
found := false
for _, rec := range statuses{
if rec == exp{
found = true
break
}
}
if !found{
t.Logf("Expected %s but did not find", exp)
t.Fail()
}
}
for _, rec := range statuses{
found := false
for _, exp := range expected{
if rec == exp{
found = true
break
}
}
if !found{
t.Logf("Extra Result %s", rec)
t.Fail()
}
}
}
func TestCacheKey(t *testing.T) {
fakeDTC := DTC_ECU{
VIN: "3FAFP13P71R199432",
ECU: "ACU",
TroubleCode: 8388881,
}
actual := fakeDTC.CacheKey()
expected := "3FAFP13P71R199432:ACU:8388881"
assert.Equal(t, actual, expected)
}