diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4d204d7..e46b5dc 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -24,6 +24,10 @@ jobs: run: go build -v working-directory: ./src - - name: Test + - name: Test can2mqtt run: go test -v working-directory: ./src + + - name: Test convertmodes + run: go test -v + working-directory: ./src/convertmode \ No newline at end of file diff --git a/src/convertmode/none.go b/src/convertmode/none.go index a5ca032..d9516b1 100644 --- a/src/convertmode/none.go +++ b/src/convertmode/none.go @@ -19,17 +19,4 @@ func (_ None) ToCan(input []byte) (can.Frame, error) { func (_ None) ToMqtt(input can.Frame) ([]byte, error) { return input.Data[:input.Length], nil -} - -func NoneToCan(input []byte) (can.Frame, error) { - var returner [8]byte - var i uint8 = 0 - for ; int(i) < len(input) && i < 8; i++ { - returner[i] = input[i] - } - return can.Frame{Length: i, Data: returner}, nil -} - -func NoneToMqtt(input can.Frame) ([]byte, error) { - return input.Data[:input.Length], nil } \ No newline at end of file diff --git a/src/convertmode/none_test.go b/src/convertmode/none_test.go index c6d91a3..2d593a4 100644 --- a/src/convertmode/none_test.go +++ b/src/convertmode/none_test.go @@ -7,7 +7,7 @@ import ( func TestNoneToCan(t *testing.T) { input := []byte("Gladys") - output, err := NoneToCan(input) + output, err := None{}.ToCan(input) // Check whether err is nil if err != nil { @@ -27,7 +27,7 @@ func TestNoneToCan(t *testing.T) { } // Check if back and forth conversion leads to original input - back, err := NoneToMqtt(output) + back, err := None{}.ToMqtt(output) if err != nil { t.Fatalf(`NoneToMqtt failed, err not nil: %s`, err.Error()) } @@ -46,7 +46,7 @@ func TestNoneToMqtt(t *testing.T) { Res1: 0, Data: [8]uint8{'G', 'l', 'a', 'd', 'y', 's'}, } - output, err := NoneToMqtt(input) + output, err := None{}.ToMqtt(input) // Check whether err is nil if err != nil { @@ -66,7 +66,7 @@ func TestNoneToMqtt(t *testing.T) { } // Check if back and forth conversion leads to original input - back, err := NoneToCan(output) + back, err := None{}.ToCan(output) if err != nil { t.Fatalf(`NoneToCan failed, err not nil: %s`, err.Error()) } @@ -78,7 +78,7 @@ func TestNoneToMqtt(t *testing.T) { func FuzzNoneToCan(f *testing.F) { f.Fuzz(func(t *testing.T, input []byte) { - output, err := NoneToCan(input) + output, err := None{}.ToCan(input) if err != nil { t.Fatalf("%v: decode: %v", input, err) } @@ -96,7 +96,7 @@ func FuzzNoneToCan(f *testing.F) { } } // Check if back and forth conversion leads to original input - back, err := NoneToMqtt(output) + back, err := None{}.ToMqtt(output) if err != nil { t.Fatalf(`NoneToMqtt failed, err not nil: %s`, err.Error()) } @@ -118,7 +118,7 @@ func FuzzNoneToCan(f *testing.F) { } // Check if back and forth conversion leads to original input - back, err := NoneToMqtt(output) + back, err := None{}.ToMqtt(output) if err != nil { t.Fatalf(`NoneToMqtt failed, err not nil: %s`, err.Error()) } @@ -142,7 +142,7 @@ func FuzzNoneToMqtt(f *testing.F) { for i := uint8(0); i < input.Length; i++ { input.Data[i] = inputString[i] } - output, err := NoneToMqtt(input) + output, err := None{}.ToMqtt(input) if err != nil { t.Fatalf("%v: decode: %v", input, err) } @@ -160,7 +160,7 @@ func FuzzNoneToMqtt(f *testing.F) { } } // Check if back and forth conversion leads to original input - back, err := NoneToCan(output) + back, err := None{}.ToCan(output) if err != nil { t.Fatalf(`NoneToMqtt failed, err not nil: %s`, err.Error()) } @@ -184,7 +184,7 @@ func FuzzNoneToMqtt(f *testing.F) { } // Check if back and forth conversion leads to original input - back, err := NoneToCan(output) + back, err := None{}.ToCan(output) if err != nil { t.Fatalf(`NoneToMqtt failed, err not nil: %s`, err.Error()) }