Skip to content

Commit

Permalink
test(plc4go): enable color in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Oct 1, 2024
1 parent 09439fb commit 6ba7dfa
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 494 deletions.
68 changes: 0 additions & 68 deletions plc4go/internal/cbus/Configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
})
}
}
62 changes: 0 additions & 62 deletions plc4go/internal/cbus/Connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 0 additions & 70 deletions plc4go/internal/cbus/MessageCodec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
})
}
}
Loading

0 comments on commit 6ba7dfa

Please sign in to comment.