From 12736fd9d4fc94f82c7e066b9788e8bdaad8ee7c Mon Sep 17 00:00:00 2001 From: Igor Kuznetsov Date: Tue, 13 Jul 2021 13:38:48 +0300 Subject: [PATCH] =?UTF-8?q?refactoring:=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=BD=D0=B0=20testify=20=D0=B2=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=85=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D1=81=D1=82=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/receiver/config_test.go | 50 ++++--- cli/receiver/main_test.go | 20 ++- go.mod | 3 +- libs/egts/crc_test.go | 9 +- libs/egts/egts_pkg_test.go | 127 +++--------------- libs/egts/egts_pt_response_test.go | 20 +-- libs/egts/egts_sr_abs_an_sensors_data_test.go | 48 ++----- libs/egts/egts_sr_abs_cntr_data_test.go | 36 ++--- libs/egts/egts_sr_ad_sensors_data_test.go | 38 ++---- libs/egts/egts_sr_auth_info_test.go | 18 +-- libs/egts/egts_sr_counters_data_test.go | 38 ++---- libs/egts/egts_sr_dispatcher_identity_test.go | 18 +-- libs/egts/egts_sr_egtsplus_data_test.go | 37 ++--- libs/egts/egts_sr_ext_pos_data_test.go | 38 ++---- libs/egts/egts_sr_liquid_level_sensor_test.go | 37 ++--- libs/egts/egts_sr_pos_data_test.go | 19 +-- libs/egts/egts_sr_response_test.go | 20 +-- libs/egts/egts_sr_result_code_test.go | 20 +-- libs/egts/egts_sr_state_data_test.go | 38 ++---- libs/egts/egts_sr_term_identity_test.go | 36 ++--- libs/egts/record_data_test.go | 22 +-- libs/egts/service_data_records_test.go | 21 +-- 22 files changed, 193 insertions(+), 520 deletions(-) diff --git a/cli/receiver/config_test.go b/cli/receiver/config_test.go index cd4beff..b59ed7e 100644 --- a/cli/receiver/config_test.go +++ b/cli/receiver/config_test.go @@ -1,11 +1,10 @@ package main import ( + "github.com/stretchr/testify/assert" "io/ioutil" "os" "testing" - - "github.com/google/go-cmp/cmp" ) func TestConfigLoad(t *testing.T) { @@ -26,37 +25,34 @@ exchange = "receiver" level = "DEBUG"` file, err := ioutil.TempFile("/tmp", "config.toml") - if err != nil { - t.Fatal(err) + if !assert.NoError(t, err) { + return } defer os.Remove(file.Name()) - if _, err = file.WriteString(cfg); err != nil { - t.Fatal(err) + if _, err = file.WriteString(cfg); assert.NoError(t, err) { + return } conf := settings{} - if err = conf.Load(file.Name()); err != nil { - t.Fatal(err) - } - - testCfg := settings{ - Srv: service{ - Host: "127.0.0.1", - Port: "5020", - ConLiveSec: 10, + if assert.NoError(t, conf.Load(file.Name())) { + assert.Equal(t, settings{ + Srv: service{ + Host: "127.0.0.1", + Port: "5020", + ConLiveSec: 10, + }, + Store: map[string]string{ + "exchange": "receiver", + "host": "localhost", + "password": "guest", + "plugin": "rabbitmq.so", + "port": "5672", + "user": "guest", + }, + Log: logSection{Level: "DEBUG"}, }, - Store: map[string]string{ - "exchange": "receiver", - "host": "localhost", - "password": "guest", - "plugin": "rabbitmq.so", - "port": "5672", - "user": "guest", - }, - Log: logSection{Level: "DEBUG"}, - } - if diff := cmp.Diff(testCfg, conf); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + conf, + ) } } diff --git a/cli/receiver/main_test.go b/cli/receiver/main_test.go index 3e5482a..4235f6f 100644 --- a/cli/receiver/main_test.go +++ b/cli/receiver/main_test.go @@ -1,7 +1,7 @@ package main import ( - "bytes" + "github.com/stretchr/testify/assert" "net" "testing" "time" @@ -32,18 +32,14 @@ func TestServer(t *testing.T) { time.Sleep(500 * time.Microsecond) conn, err := net.Dial("tcp", srv) - if err != nil { - t.Fatal(err) - } - defer conn.Close() + if assert.NoError(t, err) { + _ = conn.SetWriteDeadline(time.Now().Add(2 * time.Second)) + _, _ = conn.Write(message) - _ = conn.SetWriteDeadline(time.Now().Add(2 * time.Second)) - _, _ = conn.Write(message) + buf := make([]byte, 29) + _, _ = conn.Read(buf) - buf := make([]byte, 29) - _, _ = conn.Read(buf) - - if !bytes.Equal(buf, response) { - t.Errorf("Ответне совпадает: %X != %X ", buf, response) + assert.Equal(t, buf, response) } + defer conn.Close() } diff --git a/go.mod b/go.mod index b04bfb6..8702b19 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.12 require ( github.com/BurntSushi/toml v0.3.1 github.com/golang/protobuf v1.3.5 - github.com/google/go-cmp v0.3.0 github.com/kr/pretty v0.1.0 // indirect github.com/labstack/gommon v0.2.8 github.com/lib/pq v1.1.1 @@ -15,7 +14,7 @@ require ( github.com/nats-io/nats.go v1.9.2 github.com/satori/go.uuid v1.2.0 github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94 - github.com/stretchr/testify v1.3.0 // indirect + github.com/stretchr/testify v1.3.0 github.com/tarantool/go-tarantool v0.0.0-20190330192518-aaa93c4bdc35 github.com/valyala/fasttemplate v1.0.1 // indirect google.golang.org/appengine v1.6.5 // indirect diff --git a/libs/egts/crc_test.go b/libs/egts/crc_test.go index 8af3529..8407bd9 100644 --- a/libs/egts/crc_test.go +++ b/libs/egts/crc_test.go @@ -1,6 +1,7 @@ package egts import ( + "github.com/stretchr/testify/assert" "testing" ) @@ -8,16 +9,12 @@ func Test_crc8(t *testing.T) { crc := crc8([]byte("123456789")) checkVal := byte(0xF7) - if crc != checkVal { - t.Errorf("Incorrect value: %x != %x\n", crc, checkVal) - } + assert.Equal(t, crc, checkVal) } func Test_crc16(t *testing.T) { crc := crc16([]byte("123456789")) checkVal := uint16(0x29b1) - if crc != checkVal { - t.Errorf("Incorrect value: %x != %x\n", crc, checkVal) - } + assert.Equal(t, crc, checkVal) } diff --git a/libs/egts/egts_pkg_test.go b/libs/egts/egts_pkg_test.go index cb1e9c8..c09335b 100644 --- a/libs/egts/egts_pkg_test.go +++ b/libs/egts/egts_pkg_test.go @@ -1,76 +1,15 @@ package egts import ( - "bytes" + "github.com/stretchr/testify/assert" "testing" "time" - - "github.com/google/go-cmp/cmp" ) var ( egtsPkgPosDataBytes = []byte{0x01, 0x00, 0x03, 0x0B, 0x00, 0x23, 0x00, 0x8A, 0x00, 0x01, 0x49, 0x18, 0x00, 0x61, 0x00, 0x99, 0xB0, 0x09, 0x02, 0x00, 0x02, 0x02, 0x10, 0x15, 0x00, 0xD5, 0x3F, 0x01, 0x10, 0x6F, 0x1C, 0x05, 0x9E, 0x7A, 0xB5, 0x3C, 0x35, 0x01, 0xD0, 0x87, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0xCC, 0x27} - - egtsPkgPosData = Package{ - ProtocolVersion: 1, - SecurityKeyID: 0, - Prefix: "00", - Route: "0", - EncryptionAlg: "00", - Compression: "0", - Priority: "11", - // HeaderLength: 11, - HeaderEncoding: 0, - FrameDataLength: 35, - PacketIdentifier: 138, - PacketType: 1, - HeaderCheckSum: 73, - ServicesFrameData: &ServiceDataSet{ - ServiceDataRecord{ - // RecordLength: 24, - RecordNumber: 97, - SourceServiceOnDevice: "1", - RecipientServiceOnDevice: "0", - Group: "0", - RecordProcessingPriority: "11", - TimeFieldExists: "0", - EventIDFieldExists: "0", - ObjectIDFieldExists: "1", - ObjectIdentifier: 133552, - SourceServiceType: 2, - RecipientServiceType: 2, - RecordDataSet: RecordDataSet{ - RecordData{ - SubrecordType: 16, - // SubrecordLength: 21, - SubrecordData: &SrPosData{ - NavigationTime: time.Date(2018, time.July, 5, 20, 8, 53, 0, time.UTC), - Latitude: 55.55389399769574, - Longitude: 37.43236696287812, - ALTE: "0", - LOHS: "0", - LAHS: "0", - MV: "0", - BB: "0", - CS: "0", - FIX: "0", - VLD: "1", - DirectionHighestBit: 1, - AltitudeSign: 0, - Speed: 200, - Direction: 172, - Odometer: []byte{0x01, 0x00, 0x00}, - DigitalInputs: 0, - Source: 0, - }, - }, - }, - }, - }, - ServicesFrameDataCheckSum: 10188, //52263 - } ) func TestEgtsPackagePosData_Encode(t *testing.T) { @@ -129,12 +68,8 @@ func TestEgtsPackagePosData_Encode(t *testing.T) { } posDataBytes, err := egtsPkgPosData.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(posDataBytes, egtsPkgPosDataBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", posDataBytes, testEgtsPkgBytes) + if assert.NoError(t, err) { + assert.Equal(t, posDataBytes, egtsPkgPosDataBytes) } } @@ -199,12 +134,8 @@ func TestEgtsPackagePosData_Decode(t *testing.T) { ServicesFrameDataCheckSum: 10188, } - if _, err := egtsPkg.Decode(egtsPkgPosDataBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(egtsPkg, egtsPkgPosData); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if _, err := egtsPkg.Decode(egtsPkgPosDataBytes); assert.NoError(t, err) { + assert.Equal(t, egtsPkg, egtsPkgPosData) } } @@ -269,21 +200,14 @@ func TestFullCycleCoding(t *testing.T) { ServicesFrameDataCheckSum: 10188, } - if _, err := egtsPkg.Decode(egtsPkgPosDataBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } + _, err := egtsPkg.Decode(egtsPkgPosDataBytes) + if assert.NoError(t, err) { + assert.Equal(t, egtsPkg, egtsPkgPosData) - if diff := cmp.Diff(egtsPkg, egtsPkgPosData); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) - } - - posDataBytes, err := egtsPkg.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(posDataBytes, egtsPkgPosDataBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", posDataBytes, testEgtsPkgBytes) + posDataBytes, err := egtsPkg.Encode() + if assert.NoError(t, err) { + assert.Equal(t, posDataBytes, egtsPkgPosDataBytes) + } } } @@ -364,18 +288,12 @@ func TestRebuildCycleCoding(t *testing.T) { 0x00, 0x00, 0x1b, 0x07, 0x00, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xe8} encodePkg, err := egtsPkg.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } + if assert.NoError(t, err) { + assert.Equal(t, encodePkg, p) - if !bytes.Equal(encodePkg, p) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", encodePkg, p) - } - - dp := Package{} - _, err = dp.Decode(encodePkg) - if err != nil { - t.Errorf("Ошибка разбора: %v\n", err) + dp := Package{} + _, err = dp.Decode(encodePkg) + assert.NoError(t, err) } } @@ -453,13 +371,10 @@ func TestRebuildOID(t *testing.T) { } encodePkg, err := egtsPkg.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } + if assert.NoError(t, err) { + p := Package{} - p := Package{} - _, err = p.Decode(encodePkg) - if err != nil { - t.Errorf("Ошибка разбора: %v. Пакет: %v\n", err, encodePkg) + _, err = p.Decode(encodePkg) + assert.NoError(t, err) } } diff --git a/libs/egts/egts_pt_response_test.go b/libs/egts/egts_pt_response_test.go index 06369a3..2345b20 100644 --- a/libs/egts/egts_pt_response_test.go +++ b/libs/egts/egts_pt_response_test.go @@ -1,8 +1,7 @@ package egts import ( - "bytes" - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" ) @@ -33,23 +32,16 @@ var ( func TestEgtsPkgResp_Encode(t *testing.T) { posDataBytes, err := egtsPkgResp.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(posDataBytes, testEgtsPkgBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", posDataBytes, testEgtsPkgBytes) + if assert.NoError(t, err) { + assert.Equal(t, posDataBytes, testEgtsPkgBytes) } } func TestEgtsPkgResp_Decode(t *testing.T) { egtsPkg := Package{} - if _, err := egtsPkg.Decode(testEgtsPkgBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(egtsPkg, egtsPkgResp); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + _, err := egtsPkg.Decode(testEgtsPkgBytes) + if assert.NoError(t, err) { + assert.Equal(t, egtsPkg, egtsPkgResp) } } diff --git a/libs/egts/egts_sr_abs_an_sensors_data_test.go b/libs/egts/egts_sr_abs_an_sensors_data_test.go index 9175363..03bf61e 100644 --- a/libs/egts/egts_sr_abs_an_sensors_data_test.go +++ b/libs/egts/egts_sr_abs_an_sensors_data_test.go @@ -1,7 +1,7 @@ package egts import ( - "bytes" + "github.com/stretchr/testify/assert" "testing" ) @@ -11,45 +11,25 @@ func TestEgtsSrAbsAnSensData_Encode(t *testing.T) { Value: 0x123456, } data, err := a.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v", err) - } - - if data[0] != 0x98 || - data[1] != 0x56 || - data[2] != 0x34 || - data[3] != 0x12 { - t.Error("Ошибка кодирования") - } + if assert.NoError(t, err) { + assert.False(t, data[0] != 0x98 || data[1] != 0x56 || data[2] != 0x34 || data[3] != 0x12) - b := SrAbsAnSensData{} + b := SrAbsAnSensData{} - if err := b.Decode(data); err != nil { - t.Error("Ошибка декодирования") + if err := b.Decode(data); assert.NoError(t, err) { + assert.False(t, a.Value != b.Value || a.SensorNumber != b.SensorNumber) + } } - - if a.Value != b.Value || a.SensorNumber != b.SensorNumber { - t.Error("Ошибка кодирования") - } - } func TestEgtsSrAbsAnSensData_Decode(t *testing.T) { data := []byte{0x98, 0x56, 0x34, 0x12} a := SrAbsAnSensData{} - if err := a.Decode(data); err != nil { - t.Errorf("Ошибка декодирования: %v", err) - } - - if a.SensorNumber != 0x98 || a.Value != 0x123456 { - t.Error("Ошибка декодирования") - } - - data2, err := a.Encode() - if err != nil { - t.Error("Ошибка кодирования") - } - - if bytes.Compare(data, data2) != 0 { - t.Error("Ошибка декодирования") + err := a.Decode(data) + if assert.NoError(t, err) { + assert.False(t, a.SensorNumber != 0x98 || a.Value != 0x123456) + data2, err := a.Encode() + if assert.NoError(t, err) { + assert.Equal(t, data, data2) + } } } diff --git a/libs/egts/egts_sr_abs_cntr_data_test.go b/libs/egts/egts_sr_abs_cntr_data_test.go index 948c424..4809140 100644 --- a/libs/egts/egts_sr_abs_cntr_data_test.go +++ b/libs/egts/egts_sr_abs_cntr_data_test.go @@ -1,8 +1,7 @@ package egts import ( - "bytes" - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" ) @@ -16,25 +15,18 @@ var ( func TestEgtsSrAbsCntrData_Encode(t *testing.T) { posDataBytes, err := testEgtsSrAbsCntrData.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(posDataBytes, srAbsCntrDataBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", posDataBytes, srAbsCntrDataBytes) + if assert.NoError(t, err) { + assert.Equal(t, posDataBytes, srAbsCntrDataBytes) } } func TestEgtsSrAbsCntrData_Decode(t *testing.T) { adSensData := SrAbsCntrData{} - if err := adSensData.Decode(srAbsCntrDataBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) + if err := adSensData.Decode(srAbsCntrDataBytes); assert.NoError(t, err) { + assert.Equal(t, adSensData, testEgtsSrAbsCntrData) } - if diff := cmp.Diff(adSensData, testEgtsSrAbsCntrData); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) - } } // проверяем что рекордсет работает правильно с данным типом подзаписи @@ -50,19 +42,11 @@ func TestEgtsSrAbsCntrDataRs(t *testing.T) { testStruct := RecordDataSet{} testBytes, err := egtsSrAbsCntrDataRD.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(testBytes, egtsSrAbsCntrDataRDBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", testBytes, egtsSrAbsCntrDataRDBytes) - } - - if err = testStruct.Decode(egtsSrAbsCntrDataRDBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } + if assert.NoError(t, err) { + assert.Equal(t, testBytes, egtsSrAbsCntrDataRDBytes) - if diff := cmp.Diff(egtsSrAbsCntrDataRD, testStruct); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if err = testStruct.Decode(egtsSrAbsCntrDataRDBytes); assert.NoError(t, err) { + assert.Equal(t, egtsSrAbsCntrDataRD, testStruct) + } } } diff --git a/libs/egts/egts_sr_ad_sensors_data_test.go b/libs/egts/egts_sr_ad_sensors_data_test.go index 904127e..7d48e7a 100644 --- a/libs/egts/egts_sr_ad_sensors_data_test.go +++ b/libs/egts/egts_sr_ad_sensors_data_test.go @@ -1,10 +1,8 @@ package egts import ( - "bytes" + "github.com/stretchr/testify/assert" "testing" - - "github.com/google/go-cmp/cmp" ) var ( @@ -42,24 +40,16 @@ var ( func TestEgtsSrAdSensorsData_Encode(t *testing.T) { sensDataBytes, err := testEgtsSrAdSensorsData.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(sensDataBytes, srAdSensorsDataBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", sensDataBytes, srAdSensorsDataBytes) + if assert.NoError(t, err) { + assert.Equal(t, sensDataBytes, srAdSensorsDataBytes) } } func TestEgtsSrAdSensorsData_Decode(t *testing.T) { adSensData := SrAdSensorsData{} - if err := adSensData.Decode(srAdSensorsDataBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(adSensData, testEgtsSrAdSensorsData); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, adSensData.Decode(srAdSensorsDataBytes)) { + assert.Equal(t, adSensData, testEgtsSrAdSensorsData) } } @@ -76,19 +66,11 @@ func TestEgtsSrAdSensorsDataaRs(t *testing.T) { testStruct := RecordDataSet{} testBytes, err := adSensDataRD.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(testBytes, adSensDataRDBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", testBytes, adSensDataRDBytes) - } - - if err = testStruct.Decode(adSensDataRDBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } + if assert.NoError(t, err) { + assert.Equal(t, testBytes, adSensDataRDBytes) - if diff := cmp.Diff(adSensDataRD, testStruct); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, testStruct.Decode(adSensDataRDBytes)) { + assert.Equal(t, adSensDataRD, testStruct) + } } } diff --git a/libs/egts/egts_sr_auth_info_test.go b/libs/egts/egts_sr_auth_info_test.go index 5dfec5f..0a4f3d3 100644 --- a/libs/egts/egts_sr_auth_info_test.go +++ b/libs/egts/egts_sr_auth_info_test.go @@ -1,7 +1,7 @@ package egts import ( - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" ) @@ -58,23 +58,15 @@ var ( func TestEgtsSrAuthInfo_Encode(t *testing.T) { authInfoPkg, err := testAuthInfoPkg.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if diff := cmp.Diff(authInfoPkg, srAuthInfoPkgBytes); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, err) { + assert.Equal(t, authInfoPkg, srAuthInfoPkgBytes) } } func TestEgtsSrAuthInfo_Decode(t *testing.T) { authPkg := Package{} - if _, err := authPkg.Decode(srAuthInfoPkgBytes); err != nil { - t.Errorf("Ошибка декодирования: %v\n", err) - } - - if diff := cmp.Diff(authPkg, testAuthInfoPkg); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if _, err := authPkg.Decode(srAuthInfoPkgBytes); assert.NoError(t, err) { + assert.Equal(t, authPkg, testAuthInfoPkg) } } diff --git a/libs/egts/egts_sr_counters_data_test.go b/libs/egts/egts_sr_counters_data_test.go index 8c67954..a0513ba 100644 --- a/libs/egts/egts_sr_counters_data_test.go +++ b/libs/egts/egts_sr_counters_data_test.go @@ -1,10 +1,8 @@ package egts import ( - "bytes" + "github.com/stretchr/testify/assert" "testing" - - "github.com/google/go-cmp/cmp" ) var ( @@ -31,24 +29,16 @@ var ( func TestEgtsSrCountersData_Encode(t *testing.T) { countersBytes, err := testEgtsSrCountersData.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(countersBytes, testSrCountersDataBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", countersBytes, testSrCountersDataBytes) + if assert.NoError(t, err) { + assert.Equal(t, countersBytes, testSrCountersDataBytes) } } func TestEgtsSrCountersData_Decode(t *testing.T) { countersData := SrCountersData{} - if err := countersData.Decode(testSrCountersDataBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(countersData, testEgtsSrCountersData); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, countersData.Decode(testSrCountersDataBytes)) { + assert.Equal(t, countersData, testEgtsSrCountersData) } } @@ -65,19 +55,11 @@ func TestEgtsSrCountersDataRs(t *testing.T) { testStruct := RecordDataSet{} testBytes, err := countersDataRD.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(testBytes, countersDataRDBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", testBytes, countersDataRDBytes) - } - - if err = testStruct.Decode(countersDataRDBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } + if assert.NoError(t, err) { + assert.Equal(t, testBytes, countersDataRDBytes) - if diff := cmp.Diff(countersDataRD, testStruct); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, testStruct.Decode(countersDataRDBytes)) { + assert.Equal(t, countersDataRD, testStruct) + } } } diff --git a/libs/egts/egts_sr_dispatcher_identity_test.go b/libs/egts/egts_sr_dispatcher_identity_test.go index dae200d..4de7c11 100644 --- a/libs/egts/egts_sr_dispatcher_identity_test.go +++ b/libs/egts/egts_sr_dispatcher_identity_test.go @@ -1,7 +1,7 @@ package egts import ( - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" ) @@ -54,23 +54,15 @@ var ( func TestEgtsSrDispatcherIdentity_Encode(t *testing.T) { authInfoPkg, err := testAuthInfoPkg.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if diff := cmp.Diff(authInfoPkg, srAuthInfoPkgBytes); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, err) { + assert.Equal(t, authInfoPkg, srAuthInfoPkgBytes) } } func TestEgtsSrDispatcherIdentity_Decode(t *testing.T) { authPkg := Package{} - if _, err := authPkg.Decode(srDispatcherIdentityPkgBytes); err != nil { - t.Errorf("Ошибка декодирования: %v\n", err) - } - - if diff := cmp.Diff(authPkg, testDispatcherIdentityPkg); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if _, err := authPkg.Decode(srDispatcherIdentityPkgBytes); assert.NoError(t, err) { + assert.Equal(t, authPkg, testDispatcherIdentityPkg) } } diff --git a/libs/egts/egts_sr_egtsplus_data_test.go b/libs/egts/egts_sr_egtsplus_data_test.go index 3a17496..cad1af0 100644 --- a/libs/egts/egts_sr_egtsplus_data_test.go +++ b/libs/egts/egts_sr_egtsplus_data_test.go @@ -1,8 +1,7 @@ package egts import ( - "bytes" - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" ) @@ -33,24 +32,16 @@ var ( func TestStorageRecord_Encode(t *testing.T) { egtsPlusBytes, err := testEgtsPlusData.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(egtsPlusBytes, srEgtsPlusBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", egtsPlusBytes, srEgtsPlusBytes) + if assert.NoError(t, err) { + assert.Equal(t, egtsPlusBytes, srEgtsPlusBytes) } } func TestStorageRecord_Decode(t *testing.T) { egtsPlus := StorageRecord{} - if err := egtsPlus.Decode(srEgtsPlusBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(egtsPlus, testEgtsPlusData); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, egtsPlus.Decode(srEgtsPlusBytes)) { + assert.Equal(t, egtsPlus, testEgtsPlusData) } } @@ -67,19 +58,11 @@ func TestStorageRecordRs(t *testing.T) { testStruct := RecordDataSet{} testBytes, err := egtsPlusDataRD.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(testBytes, egtsPlusRDBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", testBytes, egtsPlusRDBytes) - } - - if err = testStruct.Decode(egtsPlusRDBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } + if assert.NoError(t, err) { + assert.Equal(t, testBytes, egtsPlusRDBytes) - if diff := cmp.Diff(egtsPlusDataRD, testStruct); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, testStruct.Decode(egtsPlusRDBytes)) { + assert.Equal(t, egtsPlusDataRD, testStruct) + } } } diff --git a/libs/egts/egts_sr_ext_pos_data_test.go b/libs/egts/egts_sr_ext_pos_data_test.go index ea0cabf..8af7b4d 100644 --- a/libs/egts/egts_sr_ext_pos_data_test.go +++ b/libs/egts/egts_sr_ext_pos_data_test.go @@ -1,8 +1,7 @@ package egts import ( - "bytes" - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" ) @@ -22,24 +21,15 @@ var ( func TestEgtsSrExtPosData_Encode(t *testing.T) { posDataBytes, err := testEgtsSrExtPosData.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(posDataBytes, extPosDataBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", posDataBytes, extPosDataBytes) + if assert.NoError(t, err) { + assert.Equal(t, posDataBytes, extPosDataBytes) } } func TestEgtsSrExtPosData_Decode(t *testing.T) { extPosData := SrExtPosData{} - - if err := extPosData.Decode(extPosDataBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(extPosData, testEgtsSrExtPosData); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, extPosData.Decode(extPosDataBytes)) { + assert.Equal(t, extPosData, testEgtsSrExtPosData) } } @@ -56,19 +46,11 @@ func TestEgtsSrExtPosDataRs(t *testing.T) { testStruct := RecordDataSet{} testBytes, err := extPosDataRD.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(testBytes, extPosDataRDBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", testBytes, extPosDataRDBytes) - } - - if err = testStruct.Decode(extPosDataRDBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } + if assert.NoError(t, err) { + assert.Equal(t, testBytes, extPosDataRDBytes) - if diff := cmp.Diff(extPosDataRD, testStruct); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, testStruct.Decode(extPosDataRDBytes)) { + assert.Equal(t, extPosDataRD, testStruct) + } } } diff --git a/libs/egts/egts_sr_liquid_level_sensor_test.go b/libs/egts/egts_sr_liquid_level_sensor_test.go index 025dbf4..e75b9c0 100644 --- a/libs/egts/egts_sr_liquid_level_sensor_test.go +++ b/libs/egts/egts_sr_liquid_level_sensor_test.go @@ -1,8 +1,7 @@ package egts import ( - "bytes" - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" ) @@ -19,26 +18,18 @@ var ( ) func TestEgtsSrLiquidLevelSensor_Encode(t *testing.T) { - pkgBytes, err := testSrLiquidLevelSensor.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - if !bytes.Equal(pkgBytes, testSrLiquidLevelSensorBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", pkgBytes, testSrLiquidLevelSensorBytes) + if assert.NoError(t, err) { + assert.Equal(t, pkgBytes, testSrLiquidLevelSensorBytes) } } func TestEgtsSrLiquidLevelSensor_Decode(t *testing.T) { liquidLev := SrLiquidLevelSensor{} - if err := liquidLev.Decode(testSrLiquidLevelSensorBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(liquidLev, testSrLiquidLevelSensor); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, liquidLev.Decode(testSrLiquidLevelSensorBytes)) { + assert.Equal(t, liquidLev, testSrLiquidLevelSensor) } } @@ -55,19 +46,11 @@ func TestEgtsSrLiquidLevelSensorRs(t *testing.T) { testStruct := RecordDataSet{} testBytes, err := liquidLevelRD.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(testBytes, liquidLevelRDRDBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", testBytes, liquidLevelRDRDBytes) - } - - if err = testStruct.Decode(liquidLevelRDRDBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } + if assert.NoError(t, err) { + assert.Equal(t, testBytes, liquidLevelRDRDBytes) - if diff := cmp.Diff(liquidLevelRD, testStruct); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, testStruct.Decode(liquidLevelRDRDBytes)) { + assert.Equal(t, liquidLevelRD, testStruct) + } } } diff --git a/libs/egts/egts_sr_pos_data_test.go b/libs/egts/egts_sr_pos_data_test.go index 1cdd5b5..d0244d6 100644 --- a/libs/egts/egts_sr_pos_data_test.go +++ b/libs/egts/egts_sr_pos_data_test.go @@ -1,8 +1,7 @@ package egts import ( - "bytes" - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" "time" ) @@ -34,24 +33,16 @@ var ( func TestEgtsSrPosData_Encode(t *testing.T) { posDataBytes, err := testEgtsSrPosData.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - if !bytes.Equal(posDataBytes, testEgtsSrPosDataBytes) { - t.Errorf("Байтовые строки не совпадают: %#X != %#X ", posDataBytes, testEgtsSrPosDataBytes) + if assert.NoError(t, err) { + assert.Equal(t, posDataBytes, testEgtsSrPosDataBytes) } } func TestEgtsSrPosData_Decode(t *testing.T) { posData := SrPosData{} - if err := posData.Decode(testEgtsSrPosDataBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(posData, testEgtsSrPosData); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, posData.Decode(testEgtsSrPosDataBytes)) { + assert.Equal(t, posData, testEgtsSrPosData) } - } diff --git a/libs/egts/egts_sr_response_test.go b/libs/egts/egts_sr_response_test.go index 93dcdae..54b66fe 100644 --- a/libs/egts/egts_sr_response_test.go +++ b/libs/egts/egts_sr_response_test.go @@ -1,8 +1,7 @@ package egts import ( - "bytes" - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" ) @@ -57,25 +56,18 @@ var ( ) func TestEgtsPkgSrResp_Encode(t *testing.T) { - pkgBytes, err := egtsPkgSrResp.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - if !bytes.Equal(pkgBytes, testEgtsPkgSrRespBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", pkgBytes, testEgtsPkgSrRespBytes) + if assert.NoError(t, err) { + assert.Equal(t, pkgBytes, testEgtsPkgSrRespBytes) } } func TestEgtsPkgSrResp_Decode(t *testing.T) { egtsPkg := Package{} - if _, err := egtsPkg.Decode(testEgtsPkgSrRespBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(egtsPkg, egtsPkgSrResp); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + _, err := egtsPkg.Decode(testEgtsPkgSrRespBytes) + if assert.NoError(t, err) { + assert.Equal(t, egtsPkg, egtsPkgSrResp) } } diff --git a/libs/egts/egts_sr_result_code_test.go b/libs/egts/egts_sr_result_code_test.go index 1f93527..bd5ed73 100644 --- a/libs/egts/egts_sr_result_code_test.go +++ b/libs/egts/egts_sr_result_code_test.go @@ -1,8 +1,7 @@ package egts import ( - "bytes" - "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "testing" ) @@ -53,25 +52,18 @@ var ( ) func TestEgtsPkgSrResCode_Encode(t *testing.T) { - pkgBytes, err := egtsPkgSrResCode.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - if !bytes.Equal(pkgBytes, testEgtsPkgSrResCodeBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", pkgBytes, testEgtsPkgSrResCodeBytes) + if assert.NoError(t, err) { + assert.Equal(t, pkgBytes, testEgtsPkgSrResCodeBytes) } } func TestEgtsPkgSrResCode_Decode(t *testing.T) { egtsPkg := Package{} - if _, err := egtsPkg.Decode(testEgtsPkgSrResCodeBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(egtsPkg, egtsPkgSrResCode); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + _, err := egtsPkg.Decode(testEgtsPkgSrResCodeBytes) + if assert.NoError(t, err) { + assert.Equal(t, egtsPkg, egtsPkgSrResCode) } } diff --git a/libs/egts/egts_sr_state_data_test.go b/libs/egts/egts_sr_state_data_test.go index e11ef3a..7622f72 100644 --- a/libs/egts/egts_sr_state_data_test.go +++ b/libs/egts/egts_sr_state_data_test.go @@ -1,10 +1,8 @@ package egts import ( - "bytes" + "github.com/stretchr/testify/assert" "testing" - - "github.com/google/go-cmp/cmp" ) var ( @@ -23,24 +21,16 @@ var ( func TestEgtsPkgSrStateData_Encode(t *testing.T) { pkgBytes, err := testEgtsSrStateData.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(pkgBytes, testSrStateDataBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", pkgBytes, testSrStateDataBytes) + if assert.NoError(t, err) { + assert.Equal(t, pkgBytes, testSrStateDataBytes) } } func TestEgtsPkgSrStateData_Decode(t *testing.T) { stStateData := SrStateData{} - if err := stStateData.Decode(testSrStateDataBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(stStateData, testEgtsSrStateData); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, stStateData.Decode(testSrStateDataBytes)) { + assert.Equal(t, stStateData, testEgtsSrStateData) } } @@ -57,19 +47,11 @@ func TestEgtsSrStateDataRs(t *testing.T) { testStruct := RecordDataSet{} testBytes, err := stateDataRD.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(testBytes, stateDataRDBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", testBytes, stateDataRDBytes) - } - - if err = testStruct.Decode(stateDataRDBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } + if assert.NoError(t, err) { + assert.Equal(t, testBytes, stateDataRDBytes) - if diff := cmp.Diff(testStruct, stateDataRD); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, testStruct.Decode(stateDataRDBytes)) { + assert.Equal(t, stateDataRD, testStruct) + } } } diff --git a/libs/egts/egts_sr_term_identity_test.go b/libs/egts/egts_sr_term_identity_test.go index ee34ef8..f8f140e 100644 --- a/libs/egts/egts_sr_term_identity_test.go +++ b/libs/egts/egts_sr_term_identity_test.go @@ -1,9 +1,7 @@ package egts import ( - "bytes" - "github.com/google/go-cmp/cmp" - "reflect" + "github.com/stretchr/testify/assert" "testing" ) @@ -65,47 +63,33 @@ var ( func TestEgtsSrTermIdentity_Encode(t *testing.T) { sti, err := testEgtsSrTermIdentity.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - if !bytes.Equal(sti, testEgtsSrTermIdentityBin) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", sti, testEgtsSrTermIdentityBin) + if assert.NoError(t, err) { + assert.Equal(t, sti, testEgtsSrTermIdentityBin) } } func TestEgtsSrTermIdentity_Decode(t *testing.T) { srTermIdent := SrTermIdentity{} - if err := srTermIdent.Decode(testEgtsSrTermIdentityBin); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if !reflect.DeepEqual(srTermIdent, testEgtsSrTermIdentity) { - t.Errorf("Секция не совпадает %v != %v\n", srTermIdent, testEgtsSrTermIdentity) + if assert.NoError(t, srTermIdent.Decode(testEgtsSrTermIdentityBin)) { + assert.Equal(t, srTermIdent, testEgtsSrTermIdentity) } - } func TestEgtsSrTermIdentityPkg_Encode(t *testing.T) { pkg, err := testEgtsSrTermIdentityPkg.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - if !bytes.Equal(pkg, testEgtsSrTermIdentityPkgBin) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", pkg, testEgtsSrTermIdentityPkgBin) + if assert.NoError(t, err) { + assert.Equal(t, pkg, testEgtsSrTermIdentityPkgBin) } } func TestEgtsSrTermIdentityPkg_Decode(t *testing.T) { srTermIdentPkg := Package{} - if _, err := srTermIdentPkg.Decode(testEgtsSrTermIdentityPkgBin); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(srTermIdentPkg, testEgtsSrTermIdentityPkg); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + _, err := srTermIdentPkg.Decode(testEgtsSrTermIdentityPkgBin) + if assert.NoError(t, err) { + assert.Equal(t, srTermIdentPkg, testEgtsSrTermIdentityPkg) } } diff --git a/libs/egts/record_data_test.go b/libs/egts/record_data_test.go index 1022c3c..0937ea5 100644 --- a/libs/egts/record_data_test.go +++ b/libs/egts/record_data_test.go @@ -1,11 +1,9 @@ package egts import ( - "bytes" + "github.com/stretchr/testify/assert" "testing" "time" - - "github.com/google/go-cmp/cmp" ) var ( @@ -40,12 +38,8 @@ func TestRecordDataSet_Encode(t *testing.T) { } rdBytes, err := testRecordDataSet.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(rdBytes, testRecordDataBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", rdBytes, testRecordDataBytes) + if assert.NoError(t, err) { + assert.Equal(t, rdBytes, testRecordDataBytes) } } @@ -77,13 +71,7 @@ func TestRecordDataSet_Decode(t *testing.T) { }, }, } - - if err := rds.Decode(testRecordDataBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) + if assert.NoError(t, rds.Decode(testRecordDataBytes)) { + assert.Equal(t, rds, testRecordDataSet) } - - if diff := cmp.Diff(rds, testRecordDataSet); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) - } - } diff --git a/libs/egts/service_data_records_test.go b/libs/egts/service_data_records_test.go index 618b42c..1b871c3 100644 --- a/libs/egts/service_data_records_test.go +++ b/libs/egts/service_data_records_test.go @@ -1,10 +1,8 @@ package egts import ( - "bytes" + "github.com/stretchr/testify/assert" "testing" - - "github.com/google/go-cmp/cmp" ) func TestServiceDataRecord_Encode(t *testing.T) { @@ -27,12 +25,8 @@ func TestServiceDataRecord_Encode(t *testing.T) { testServiceDataRecordBytes := []byte{0x00, 0x00, 0x61, 0x00, 0x99, 0xB0, 0x09, 0x02, 0x00, 0x02, 0x02} sdr, err := testServiceDataRecord.Encode() - if err != nil { - t.Errorf("Ошибка кодирования: %v\n", err) - } - - if !bytes.Equal(sdr, testServiceDataRecordBytes) { - t.Errorf("Байтовые строки не совпадают: %v != %v ", sdr, testServiceDataRecordBytes) + if assert.NoError(t, err) { + assert.Equal(t, sdr, testServiceDataRecordBytes) } } @@ -55,12 +49,7 @@ func TestServiceDataRecord_Decode(t *testing.T) { }, } testServiceDataRecordBytes := []byte{0x18, 0x00, 0x61, 0x00, 0x99, 0xB0, 0x09, 0x02, 0x00, 0x02, 0x02} - - if err := sdr.Decode(testServiceDataRecordBytes); err != nil { - t.Errorf("Ошибка декадирования: %v\n", err) - } - - if diff := cmp.Diff(sdr, testServiceDataRecord); diff != "" { - t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) + if assert.NoError(t, sdr.Decode(testServiceDataRecordBytes)) { + assert.Equal(t, sdr, testServiceDataRecord) } }