Skip to content

Commit

Permalink
testing none mode (#67)
Browse files Browse the repository at this point in the history
* Use the new interfaced methods for testing
* Run convertmode tests in pull requests
---------
Signed-off-by: Malte Muench <[email protected]>
  • Loading branch information
mxmxchere authored Nov 1, 2024
1 parent 29645bd commit efc09aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 0 additions & 13 deletions src/convertmode/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
20 changes: 10 additions & 10 deletions src/convertmode/none_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
}
Expand All @@ -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 {
Expand All @@ -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())
}
Expand All @@ -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)
}
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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)
}
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand Down

0 comments on commit efc09aa

Please sign in to comment.