From 6ba7dfa5745f6c4e4722aeb6d592bb11ba4dfb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20R=C3=BChl?= Date: Tue, 1 Oct 2024 14:09:00 +0200 Subject: [PATCH] test(plc4go): enable color in tests --- plc4go/internal/cbus/Configuration_test.go | 68 ------- plc4go/internal/cbus/Connection_test.go | 62 ------- plc4go/internal/cbus/MessageCodec_test.go | 70 ------- plc4go/internal/cbus/Tag_test.go | 181 ------------------- plc4go/spi/default/DefaultCodec_test.go | 66 ------- plc4go/spi/default/DefaultConnection_test.go | 45 ----- plc4go/spi/testutils/TestUtils.go | 12 +- 7 files changed, 10 insertions(+), 494 deletions(-) diff --git a/plc4go/internal/cbus/Configuration_test.go b/plc4go/internal/cbus/Configuration_test.go index bc96feb1d73..1a84f095bcd 100644 --- a/plc4go/internal/cbus/Configuration_test.go +++ b/plc4go/internal/cbus/Configuration_test.go @@ -203,71 +203,3 @@ func Test_getFromOptions(t *testing.T) { }) } } - -func TestConfiguration_String(t *testing.T) { - type fields struct { - Srchk bool - Exstat bool - Pun bool - LocalSal bool - Pcn bool - Idmon bool - Monitor bool - Smart bool - XonXoff bool - Connect bool - MonitoredApplication1 byte - MonitoredApplication2 byte - } - tests := []struct { - name string - fields fields - want string - }{ - { - name: "string it", - fields: fields{ - Srchk: true, - Exstat: true, - Pun: true, - LocalSal: true, - Pcn: true, - Idmon: true, - Monitor: true, - Smart: true, - XonXoff: true, - Connect: true, - MonitoredApplication1: 2, - MonitoredApplication2: 3, - }, - want: ` -╔═Configuration═════════════════════════════════════════════════════════════════════════════════╗ -║╔═srchk═╗╔═exstat╗╔═pun═══╗╔═localSal╗╔═pcn═══╗╔═idmon═╗╔═monitor╗╔═smart═╗╔═xonXoff╗╔═connect╗║ -║║b1 true║║b1 true║║b1 true║║ b1 true ║║b1 true║║b1 true║║b1 true ║║b1 true║║b1 true ║║b1 true ║║ -║╚═══════╝╚═══════╝╚═══════╝╚═════════╝╚═══════╝╚═══════╝╚════════╝╚═══════╝╚════════╝╚════════╝║ -║╔═monitoredApplication1╗╔═monitoredApplication2╗ ║ -║║ 0x02 '.' ║║ 0x03 '.' ║ ║ -║╚══════════════════════╝╚══════════════════════╝ ║ -╚═══════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := Configuration{ - Srchk: tt.fields.Srchk, - Exstat: tt.fields.Exstat, - Pun: tt.fields.Pun, - LocalSal: tt.fields.LocalSal, - Pcn: tt.fields.Pcn, - Idmon: tt.fields.Idmon, - Monitor: tt.fields.Monitor, - Smart: tt.fields.Smart, - XonXoff: tt.fields.XonXoff, - Connect: tt.fields.Connect, - MonitoredApplication1: tt.fields.MonitoredApplication1, - MonitoredApplication2: tt.fields.MonitoredApplication2, - } - assert.Equalf(t, tt.want, c.String(), "String()") - }) - } -} diff --git a/plc4go/internal/cbus/Connection_test.go b/plc4go/internal/cbus/Connection_test.go index df4e61ccb5a..8696ba22f24 100644 --- a/plc4go/internal/cbus/Connection_test.go +++ b/plc4go/internal/cbus/Connection_test.go @@ -487,68 +487,6 @@ func TestConnection_ReadRequestBuilder(t *testing.T) { } } -func TestConnection_String(t *testing.T) { - type fields struct { - messageCodec *MessageCodec - subscribers []*Subscriber - tm transactions.RequestTransactionManager - configuration Configuration - connectionId string - tracer tracer.Tracer - } - tests := []struct { - name string - fields fields - want string - }{ - { - name: "a string", - want: ` -╔═Connection══════════════════════════════════════════════════════════════════════════════════════════════╗ -║╔═defaultConnection═══════╗╔═alphaGenerator═══════════════╗ ║ -║║╔═defaultTtl╗╔═connected╗║║╔═AlphaGenerator/currentAlpha╗║ ║ -║║║ 10s ║║ b0 false ║║║║ 0x67 'g' ║║ ║ -║║╚═══════════╝╚══════════╝║║╚════════════════════════════╝║ ║ -║╚═════════════════════════╝╚══════════════════════════════╝ ║ -║╔═configuration═════════════════════════════════════════════════════════════════════════════════════════╗║ -║║╔═Configuration═══════════════════════════════════════════════════════════════════════════════════════╗║║ -║║║╔═srchk══╗╔═exstat═╗╔═pun════╗╔═localSal╗╔═pcn════╗╔═idmon══╗╔═monitor╗╔═smart══╗╔═xonXoff╗╔═connect╗║║║ -║║║║b0 false║║b0 false║║b0 false║║b0 false ║║b0 false║║b0 false║║b0 false║║b0 false║║b0 false║║b0 false║║║║ -║║║╚════════╝╚════════╝╚════════╝╚═════════╝╚════════╝╚════════╝╚════════╝╚════════╝╚════════╝╚════════╝║║║ -║║║╔═monitoredApplication1╗╔═monitoredApplication2╗ ║║║ -║║║║ 0x00 '.' ║║ 0x00 '.' ║ ║║║ -║║║╚══════════════════════╝╚══════════════════════╝ ║║║ -║║╚═════════════════════════════════════════════════════════════════════════════════════════════════════╝║║ -║╚═══════════════════════════════════════════════════════════════════════════════════════════════════════╝║ -║╔═driverContext═══════════════════════════════════╗ ║ -║║╔═DriverContext═════════════════════════════════╗║ ║ -║║║╔═awaitSetupComplete╗╔═awaitDisconnectComplete╗║║ ║ -║║║║ b1 true ║║ b1 true ║║║ ║ -║║║╚═══════════════════╝╚════════════════════════╝║║ ║ -║║╚═══════════════════════════════════════════════╝║ ║ -║╚═════════════════════════════════════════════════╝ ║ -╚═════════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := &Connection{ - alphaGenerator: AlphaGenerator{currentAlpha: 'g'}, - messageCodec: tt.fields.messageCodec, - subscribers: tt.fields.subscribers, - tm: tt.fields.tm, - configuration: tt.fields.configuration, - driverContext: driverContextForTesting(), - connectionId: tt.fields.connectionId, - tracer: tt.fields.tracer, - log: testutils.ProduceTestingLogger(t), - } - c.DefaultConnection = _default.NewDefaultConnection(c, testutils.EnrichOptionsWithOptionsForTesting(t)...) - assert.Equalf(t, tt.want, c.String(), "String()") - }) - } -} - func TestConnection_SubscriptionRequestBuilder(t *testing.T) { type fields struct { messageCodec *MessageCodec diff --git a/plc4go/internal/cbus/MessageCodec_test.go b/plc4go/internal/cbus/MessageCodec_test.go index 54e849be975..699c789484a 100644 --- a/plc4go/internal/cbus/MessageCodec_test.go +++ b/plc4go/internal/cbus/MessageCodec_test.go @@ -826,73 +826,3 @@ func Test_extractMMIAndSAL(t *testing.T) { }) } } - -func TestMessageCodec_String(t *testing.T) { - type fields struct { - DefaultCodec _default.DefaultCodec - requestContext readWriteModel.RequestContext - cbusOptions readWriteModel.CBusOptions - monitoredMMIs chan readWriteModel.CALReply - monitoredSALs chan readWriteModel.MonitoredSAL - } - tests := []struct { - name string - fields fields - manipulator func(t *testing.T, messageCodec *MessageCodec) - want string - }{ - { - name: "string it", - fields: fields{ - DefaultCodec: _default.NewDefaultCodec(nil, test.NewTransportInstance(test.NewTransport())), - requestContext: readWriteModel.NewRequestContext(true), - cbusOptions: readWriteModel.NewCBusOptions(true, true, true, true, true, true, true, true, true), - monitoredMMIs: nil, - monitoredSALs: nil, - }, - manipulator: func(t *testing.T, messageCodec *MessageCodec) { - messageCodec.lastPackageHash.Store(2) - messageCodec.hashEncountered.Store(3) - messageCodec.currentlyReportedServerErrors.Store(4) - }, - want: ` -╔═MessageCodec════════════════════════════════════════════════════════════════════════════════════════════════════════╗ -║╔═defaultCodec══════════════════════════════════════════════════════════════════════════════════════════╗ ║ -║║╔═transportInstance╗╔═defaultIncomingMessageChannel╗╔═customMessageHandling╗╔═running╗╔═receiveTimeout╗║ ║ -║║║ test ║║ 0 element(s) ║║ b0 false ║║b0 false║║ 10s ║║ ║ -║║╚══════════════════╝╚══════════════════════════════╝╚══════════════════════╝╚════════╝╚═══════════════╝║ ║ -║║╔═traceDefaultMessageCodecWorker╗ ║ ║ -║║║ b0 false ║ ║ ║ -║║╚═══════════════════════════════╝ ║ ║ -║╚═══════════════════════════════════════════════════════════════════════════════════════════════════════╝ ║ -║╔═requestContext/RequestContext/sendIdentifyRequestBefore╗ ║ -║║ b1 true ║ ║ -║╚════════════════════════════════════════════════════════╝ ║ -║╔═cbusOptions/CBusOptions═══════════════════════════════════════════════════════════╗╔═monitoredMMIs╗╔═monitoredSALs╗║ -║║╔═connect╗╔═smart═╗╔═idmon═╗╔═exstat╗╔═monitor╗╔═monall╗╔═pun═══╗╔═pcn═══╗╔═srchk═╗║║ 0 element(s) ║║ 0 element(s) ║║ -║║║b1 true ║║b1 true║║b1 true║║b1 true║║b1 true ║║b1 true║║b1 true║║b1 true║║b1 true║║╚══════════════╝╚══════════════╝║ -║║╚════════╝╚═══════╝╚═══════╝╚═══════╝╚════════╝╚═══════╝╚═══════╝╚═══════╝╚═══════╝║ ║ -║╚═══════════════════════════════════════════════════════════════════════════════════╝ ║ -║╔═lastPackageHash╗╔═hashEncountered════╗╔═currentlyReportedServerErrors╗ ║ -║║ 0x00000002 2 ║║0x0000000000000003 3║║ 0x0000000000000004 4 ║ ║ -║╚════════════════╝╚════════════════════╝╚══════════════════════════════╝ ║ -╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - m := &MessageCodec{ - DefaultCodec: tt.fields.DefaultCodec, - requestContext: tt.fields.requestContext, - cbusOptions: tt.fields.cbusOptions, - monitoredMMIs: tt.fields.monitoredMMIs, - monitoredSALs: tt.fields.monitoredSALs, - log: testutils.ProduceTestingLogger(t), - } - if tt.manipulator != nil { - tt.manipulator(t, m) - } - assert.Equalf(t, tt.want, m.String(), "String()") - }) - } -} diff --git a/plc4go/internal/cbus/Tag_test.go b/plc4go/internal/cbus/Tag_test.go index e5b6fd52245..9c35a00f1b6 100644 --- a/plc4go/internal/cbus/Tag_test.go +++ b/plc4go/internal/cbus/Tag_test.go @@ -521,43 +521,6 @@ func Test_calGetStatusTag_SerializeWithWriteBuffer(t *testing.T) { } } -func Test_calGetStatusTag_String(t *testing.T) { - type fields struct { - calTag calTag - tagType TagType - parameter readWriteModel.Parameter - count uint8 - numElements uint16 - } - tests := []struct { - name string - fields fields - want string - }{ - { - name: "default to string", - want: ` -╔═STATUS════════════════════╗ -║╔═Parameter═══════╗╔═count╗║ -║║0x00 0 UNKNOWN_01║║0x00 0║║ -║╚═════════════════╝╚══════╝║ -╚═══════════════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := calGetStatusTag{ - calTag: tt.fields.calTag, - tagType: tt.fields.tagType, - parameter: tt.fields.parameter, - count: tt.fields.count, - numElements: tt.fields.numElements, - } - assert.Equalf(t, tt.want, c.String(), "String()") - }) - } -} - func Test_calIdentifyTag_GetAddressString(t *testing.T) { type fields struct { calTag calTag @@ -795,39 +758,6 @@ func Test_calIdentifyTag_SerializeWithWriteBuffer(t *testing.T) { } } -func Test_calIdentifyTag_String(t *testing.T) { - type fields struct { - calTag calTag - tagType TagType - attribute readWriteModel.Attribute - numElements uint16 - } - tests := []struct { - name string - fields fields - want string - }{ - { - name: "default to string", - want: ` -╔═STATUS/Attribute══╗ -║0x00 0 Manufacturer║ -╚═══════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := calIdentifyTag{ - calTag: tt.fields.calTag, - tagType: tt.fields.tagType, - attribute: tt.fields.attribute, - numElements: tt.fields.numElements, - } - assert.Equalf(t, tt.want, c.String(), "String()") - }) - } -} - func Test_calRecallTag_GetAddressString(t *testing.T) { type fields struct { calTag calTag @@ -1110,43 +1040,6 @@ func Test_calRecallTag_SerializeWithWriteBuffer(t *testing.T) { } } -func Test_calRecallTag_String(t *testing.T) { - type fields struct { - calTag calTag - tagType TagType - parameter readWriteModel.Parameter - count uint8 - numElements uint16 - } - tests := []struct { - name string - fields fields - want string - }{ - { - name: "default to string", - want: ` -╔═STATUS════════════════════╗ -║╔═Parameter═══════╗╔═count╗║ -║║0x00 0 UNKNOWN_01║║0x00 0║║ -║╚═════════════════╝╚══════╝║ -╚═══════════════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := calRecallTag{ - calTag: tt.fields.calTag, - tagType: tt.fields.tagType, - parameter: tt.fields.parameter, - count: tt.fields.count, - numElements: tt.fields.numElements, - } - assert.Equalf(t, tt.want, c.String(), "String()") - }) - } -} - func Test_calTag_GetBridgeAddresses(t *testing.T) { type fields struct { bridgeAddresses []readWriteModel.BridgeAddress @@ -2262,41 +2155,6 @@ func Test_salTag_SerializeWithWriteBuffer(t *testing.T) { } } -func Test_salTag_String(t *testing.T) { - type fields struct { - bridgeAddresses []readWriteModel.BridgeAddress - tagType TagType - application readWriteModel.ApplicationIdContainer - salCommand string - numElements uint16 - } - tests := []struct { - name string - fields fields - want string - }{ - { - name: "default to string", - want: ` -╔═STATUS/ApplicationIdContainer╗ -║ 0x00 0 RESERVED_00 ║ -╚══════════════════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - s := salTag{ - bridgeAddresses: tt.fields.bridgeAddresses, - tagType: tt.fields.tagType, - application: tt.fields.application, - salCommand: tt.fields.salCommand, - numElements: tt.fields.numElements, - } - assert.Equalf(t, tt.want, s.String(), "String()") - }) - } -} - func Test_statusTag_GetAddressString(t *testing.T) { type fields struct { bridgeAddresses []readWriteModel.BridgeAddress @@ -2715,42 +2573,3 @@ func Test_statusTag_SerializeWithWriteBuffer(t *testing.T) { }) } } - -func Test_statusTag_String(t *testing.T) { - type fields struct { - bridgeAddresses []readWriteModel.BridgeAddress - tagType TagType - statusRequestType StatusRequestType - startingGroupAddressLabel *byte - application readWriteModel.ApplicationIdContainer - numElements uint16 - } - tests := []struct { - name string - fields fields - want string - }{ - { - name: "default to string", - want: ` -╔═STATUS══════════════════════════════════════════════════╗ -║╔═statusRequestType═════════════════╗╔═application══════╗║ -║║0x00 0 StatusRequestTypeBinaryState║║0x00 0 RESERVED_00║║ -║╚═══════════════════════════════════╝╚══════════════════╝║ -╚═════════════════════════════════════════════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - s := statusTag{ - bridgeAddresses: tt.fields.bridgeAddresses, - tagType: tt.fields.tagType, - statusRequestType: tt.fields.statusRequestType, - startingGroupAddressLabel: tt.fields.startingGroupAddressLabel, - application: tt.fields.application, - numElements: tt.fields.numElements, - } - assert.Equalf(t, tt.want, s.String(), "String()") - }) - } -} diff --git a/plc4go/spi/default/DefaultCodec_test.go b/plc4go/spi/default/DefaultCodec_test.go index db2acebdcbe..f7437fa7f9f 100644 --- a/plc4go/spi/default/DefaultCodec_test.go +++ b/plc4go/spi/default/DefaultCodec_test.go @@ -37,7 +37,6 @@ import ( "github.com/apache/plc4x/plc4go/spi/options" "github.com/apache/plc4x/plc4go/spi/testutils" "github.com/apache/plc4x/plc4go/spi/transports" - "github.com/apache/plc4x/plc4go/spi/transports/test" ) func TestDefaultExpectation_GetAcceptsMessage(t *testing.T) { @@ -1453,71 +1452,6 @@ func Test_defaultCodec_Work(t *testing.T) { } } -func Test_defaultCodec_String(t *testing.T) { - type fields struct { - DefaultCodecRequirements DefaultCodecRequirements - transportInstance transports.TransportInstance - defaultIncomingMessageChannel chan spi.Message - expectations []spi.Expectation - running bool - customMessageHandling func(codec DefaultCodecRequirements, message spi.Message) bool - } - tests := []struct { - name string - fields fields - want string - }{ - { - name: "string it", - fields: fields{ - transportInstance: test.NewTransportInstance(test.NewTransport()), - defaultIncomingMessageChannel: func() chan spi.Message { - messages := make(chan spi.Message, 1) - messages <- NewMockMessage(t) - return messages - }(), - expectations: []spi.Expectation{ - func() spi.Expectation { - expectation := NewMockExpectation(t) - expectation.EXPECT().String().Return("yoink1") - return expectation - }(), - func() spi.Expectation { - expectation := NewMockExpectation(t) - expectation.EXPECT().String().Return("yoink2") - return expectation - }(), - }, - customMessageHandling: nil, - }, - want: ` -╔═defaultCodec═══════════════════════════════════════════════════════════════════════════════════════════╗ -║╔═transportInstance╗╔═expectations═══╗╔═defaultIncomingMessageChannel╗╔═customMessageHandling╗╔═running╗║ -║║ test ║║╔═value╗╔═value╗║║ 1 element(s) ║║ b0 false ║║b0 false║║ -║╚══════════════════╝║║yoink1║║yoink2║║╚══════════════════════════════╝╚══════════════════════╝╚════════╝║ -║ ║╚══════╝╚══════╝║ ║ -║ ╚════════════════╝ ║ -║╔═receiveTimeout╗╔═traceDefaultMessageCodecWorker╗ ║ -║║ 0s ║║ b0 false ║ ║ -║╚═══════════════╝╚═══════════════════════════════╝ ║ -╚════════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - m := &defaultCodec{ - DefaultCodecRequirements: tt.fields.DefaultCodecRequirements, - transportInstance: tt.fields.transportInstance, - defaultIncomingMessageChannel: tt.fields.defaultIncomingMessageChannel, - expectations: tt.fields.expectations, - customMessageHandling: tt.fields.customMessageHandling, - log: testutils.ProduceTestingLogger(t), - } - assert.Equalf(t, tt.want, m.String(), "String()") - }) - } -} - func Test_defaultCodec_startWorker(t *testing.T) { type fields struct { DefaultCodecRequirements DefaultCodecRequirements diff --git a/plc4go/spi/default/DefaultConnection_test.go b/plc4go/spi/default/DefaultConnection_test.go index 64873d64bc3..289043a2081 100644 --- a/plc4go/spi/default/DefaultConnection_test.go +++ b/plc4go/spi/default/DefaultConnection_test.go @@ -33,7 +33,6 @@ import ( apiModel "github.com/apache/plc4x/plc4go/pkg/api/model" "github.com/apache/plc4x/plc4go/spi" "github.com/apache/plc4x/plc4go/spi/options" - "github.com/apache/plc4x/plc4go/spi/testutils" "github.com/apache/plc4x/plc4go/spi/tracer" "github.com/apache/plc4x/plc4go/spi/transports" "github.com/apache/plc4x/plc4go/spi/utils" @@ -1295,47 +1294,3 @@ func Test_plcConnectionPingResult_GetErr(t *testing.T) { }) } } - -func Test_defaultConnection_String(t *testing.T) { - type fields struct { - DefaultConnectionRequirements DefaultConnectionRequirements - defaultTtl time.Duration - tagHandler spi.PlcTagHandler - valueHandler spi.PlcValueHandler - } - tests := []struct { - name string - fields fields - connected bool - want string - }{ - { - name: "string it", - fields: fields{ - defaultTtl: 20 * time.Hour, - }, - connected: true, - want: ` -╔═defaultConnection═══════╗ -║╔═defaultTtl╗╔═connected╗║ -║║ 20h0m0s ║║ b1 true ║║ -║╚═══════════╝╚══════════╝║ -╚═════════════════════════╝`[1:], - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - d := &defaultConnection{ - DefaultConnectionRequirements: tt.fields.DefaultConnectionRequirements, - defaultTtl: tt.fields.defaultTtl, - tagHandler: tt.fields.tagHandler, - valueHandler: tt.fields.valueHandler, - log: testutils.ProduceTestingLogger(t), - } - if tt.connected { - d.connected.Store(true) - } - assert.Equalf(t, tt.want, d.String(), "String()") - }) - } -} diff --git a/plc4go/spi/testutils/TestUtils.go b/plc4go/spi/testutils/TestUtils.go index 80512b974de..d4c8cc276e2 100644 --- a/plc4go/spi/testutils/TestUtils.go +++ b/plc4go/spi/testutils/TestUtils.go @@ -34,6 +34,7 @@ import ( "github.com/ajankovic/xdiff" "github.com/ajankovic/xdiff/parser" + "github.com/fatih/color" "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -169,16 +170,23 @@ func getOrLeaveDuration(key string, setting *time.Duration) { } func shouldNoColor() bool { + if _, forceColorEnv := os.LookupEnv("FORCE_COLOR"); forceColorEnv { + color.NoColor = false // Apparently the color.NoColor is a bit to eager + return false + } noColor := false { - // TODO: this is really an issue with go-junit-report not sanitizing output before dumping into xml... + _, noColorEnv := os.LookupEnv("NO_COLOR") onJenkins := os.Getenv("JENKINS_URL") != "" onGithubAction := os.Getenv("GITHUB_ACTIONS") != "" onCI := os.Getenv("CI") != "" - if onJenkins || onGithubAction || onCI { + if noColorEnv || onJenkins || onGithubAction || onCI { noColor = true } } + if !noColor { + color.NoColor = false // Apparently the color.NoColor is a bit to eager + } return noColor }