Skip to content

Commit

Permalink
Fixes for previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jan 1, 2024
1 parent 2617704 commit ae83233
Showing 1 changed file with 2 additions and 44 deletions.
46 changes: 2 additions & 44 deletions integration_tests/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ import (

"github.com/enbility/eebus-go/spine"
"github.com/enbility/eebus-go/spine/model"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/assert"
)

const (
wallbox_detaileddiscoverydata_recv_reply_file_path = "./testdata/wallbox_detaileddiscoverydata_recv_reply.json"
wallbox_detaileddiscoverydata_recv_notify_file_path = "./testdata/wallbox_detaileddiscoverydata_recv_notify.json"
wallbox_detaileddiscoverydata_recv_reply_file_path = "../spine/testdata/wallbox_detaileddiscoverydata_recv_reply.json"
wallbox_detaileddiscoverydata_recv_notify_file_path = "../spine/testdata/wallbox_detaileddiscoverydata_recv_notify.json"
)

type WriteMessageHandler struct {
Expand Down Expand Up @@ -133,45 +130,6 @@ func loadFileData(t *testing.T, fileName string) []byte {
return fileData
}

func checkSentData(t *testing.T, sendBytes []byte, msgSendFilePrefix string) {
msgSendExpectedBytes, err := os.ReadFile(msgSendFilePrefix + "_expected.json")
if err != nil {
t.Fatal(err)
}

msgSendActualFileName := msgSendFilePrefix + "_actual.json"
equal := jsonDatagramEqual(t, msgSendExpectedBytes, sendBytes)
if !equal {
saveJsonToFile(t, sendBytes, msgSendActualFileName)
}
assert.Truef(t, equal, "Assert equal failed! Check '%s' ", msgSendActualFileName)
}

func jsonDatagramEqual(t *testing.T, expectedJson, actualJson []byte) bool {
var actualDatagram model.Datagram
if err := json.Unmarshal(actualJson, &actualDatagram); err != nil {
t.Fatal(err)
}
var expectedDatagram model.Datagram
if err := json.Unmarshal(expectedJson, &expectedDatagram); err != nil {
t.Fatal(err)
}

less := func(a, b model.FunctionPropertyType) bool { return string(*a.Function) < string(*b.Function) }
return cmp.Equal(expectedDatagram, actualDatagram, cmpopts.SortSlices(less))
}

func saveJsonToFile(t *testing.T, data json.RawMessage, fileName string) {
jsonIndent, err := json.MarshalIndent(data, "", " ")
if err != nil {
t.Fatal(err)
}
err = os.WriteFile(fileName, jsonIndent, os.ModePerm)
if err != nil {
t.Fatal(err)
}
}

func waitForAck(t *testing.T, msgCounterReference *model.MsgCounterType, writeHandler *WriteMessageHandler) {
var datagram model.Datagram

Expand Down

0 comments on commit ae83233

Please sign in to comment.