You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/04/26 11:32:36 UTC

[plc4x] branch develop updated: test(plc4go/spi): add test for Tracer

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new cfbc3a720a test(plc4go/spi): add test for Tracer
cfbc3a720a is described below

commit cfbc3a720a736d8253a5ac84c521a4c9c3e38084
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Apr 26 13:32:27 2023 +0200

    test(plc4go/spi): add test for Tracer
---
 plc4go/spi/Tracer_test.go | 325 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 325 insertions(+)

diff --git a/plc4go/spi/Tracer_test.go b/plc4go/spi/Tracer_test.go
new file mode 100644
index 0000000000..ae2d10f265
--- /dev/null
+++ b/plc4go/spi/Tracer_test.go
@@ -0,0 +1,325 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package spi
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+	"time"
+)
+
+func TestNewTracer(t *testing.T) {
+	type args struct {
+		connectionId string
+	}
+	tests := []struct {
+		name string
+		args args
+		want *Tracer
+	}{
+		{
+			name: "create it",
+			want: &Tracer{
+				traceEntries: []TraceEntry{},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			assert.Equalf(t, tt.want, NewTracer(tt.args.connectionId), "NewTracer(%v)", tt.args.connectionId)
+		})
+	}
+}
+
+func TestTracer_AddTrace(t1 *testing.T) {
+	type fields struct {
+		connectionId string
+		traceEntries []TraceEntry
+	}
+	type args struct {
+		operation string
+		message   string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		args   args
+	}{
+		{
+			name: "Add a trace",
+		},
+	}
+	for _, tt := range tests {
+		t1.Run(tt.name, func(t1 *testing.T) {
+			t := &Tracer{
+				connectionId: tt.fields.connectionId,
+				traceEntries: tt.fields.traceEntries,
+			}
+			t.AddTrace(tt.args.operation, tt.args.message)
+		})
+	}
+}
+
+func TestTracer_AddTransactionalStartTrace(t1 *testing.T) {
+	type fields struct {
+		connectionId string
+		traceEntries []TraceEntry
+	}
+	type args struct {
+		operation string
+		message   string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		args   args
+	}{
+		{
+			name: "start a trace",
+		},
+	}
+	for _, tt := range tests {
+		t1.Run(tt.name, func(t1 *testing.T) {
+			t := &Tracer{
+				connectionId: tt.fields.connectionId,
+				traceEntries: tt.fields.traceEntries,
+			}
+			id := t.AddTransactionalStartTrace(tt.args.operation, tt.args.message)
+			assert.NotNil(t1, id, "AddTransactionalStartTrace(%v, %v)", tt.args.operation, tt.args.message)
+		})
+	}
+}
+
+func TestTracer_AddTransactionalTrace(t1 *testing.T) {
+	type fields struct {
+		connectionId string
+		traceEntries []TraceEntry
+	}
+	type args struct {
+		transactionId string
+		operation     string
+		message       string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		args   args
+	}{
+		{
+			name: "add more trace",
+		},
+	}
+	for _, tt := range tests {
+		t1.Run(tt.name, func(t1 *testing.T) {
+			t := &Tracer{
+				connectionId: tt.fields.connectionId,
+				traceEntries: tt.fields.traceEntries,
+			}
+			t.AddTransactionalTrace(tt.args.transactionId, tt.args.operation, tt.args.message)
+		})
+	}
+}
+
+func TestTracer_FilterTraces(t1 *testing.T) {
+	type fields struct {
+		connectionId string
+		traceEntries []TraceEntry
+	}
+	type args struct {
+		traces              []TraceEntry
+		connectionIdFilter  string
+		transactionIdFilter string
+		operationFilter     string
+		messageFilter       string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		args   args
+		want   []TraceEntry
+	}{
+		{
+			name: "filter",
+			args: args{
+				traces: []TraceEntry{
+					{
+						Timestamp:     time.Time{},
+						ConnectionId:  "_",
+						TransactionId: "2",
+						Operation:     "3",
+						Message:       "4",
+					},
+					{
+						Timestamp:     time.Time{},
+						ConnectionId:  "1",
+						TransactionId: "_",
+						Operation:     "3",
+						Message:       "4",
+					},
+					{
+						Timestamp:     time.Time{},
+						ConnectionId:  "1",
+						TransactionId: "2",
+						Operation:     "_",
+						Message:       "4",
+					},
+					{
+						Timestamp:     time.Time{},
+						ConnectionId:  "1",
+						TransactionId: "2",
+						Operation:     "3",
+						Message:       "_",
+					},
+					{
+						Timestamp:     time.Time{},
+						ConnectionId:  "1",
+						TransactionId: "2",
+						Operation:     "3",
+						Message:       "4",
+					},
+				},
+				connectionIdFilter:  "1",
+				transactionIdFilter: "2",
+				operationFilter:     "3",
+				messageFilter:       "4",
+			},
+			want: []TraceEntry{
+				{
+					Timestamp:     time.Time{},
+					ConnectionId:  "1",
+					TransactionId: "2",
+					Operation:     "3",
+					Message:       "4",
+				},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t1.Run(tt.name, func(t1 *testing.T) {
+			t := &Tracer{
+				connectionId: tt.fields.connectionId,
+				traceEntries: tt.fields.traceEntries,
+			}
+			assert.Equalf(t1, tt.want, t.FilterTraces(tt.args.traces, tt.args.connectionIdFilter, tt.args.transactionIdFilter, tt.args.operationFilter, tt.args.messageFilter), "FilterTraces(%v, %v, %v, %v, %v)", tt.args.traces, tt.args.connectionIdFilter, tt.args.transactionIdFilter, tt.args.operationFilter, tt.args.messageFilter)
+		})
+	}
+}
+
+func TestTracer_GetConnectionId(t1 *testing.T) {
+	type fields struct {
+		connectionId string
+		traceEntries []TraceEntry
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   string
+	}{
+		{
+			name: "get it",
+		},
+	}
+	for _, tt := range tests {
+		t1.Run(tt.name, func(t1 *testing.T) {
+			t := &Tracer{
+				connectionId: tt.fields.connectionId,
+				traceEntries: tt.fields.traceEntries,
+			}
+			assert.Equalf(t1, tt.want, t.GetConnectionId(), "GetConnectionId()")
+		})
+	}
+}
+
+func TestTracer_GetTraces(t1 *testing.T) {
+	type fields struct {
+		connectionId string
+		traceEntries []TraceEntry
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   []TraceEntry
+	}{
+		{
+			name: "get it",
+		},
+	}
+	for _, tt := range tests {
+		t1.Run(tt.name, func(t1 *testing.T) {
+			t := &Tracer{
+				connectionId: tt.fields.connectionId,
+				traceEntries: tt.fields.traceEntries,
+			}
+			assert.Equalf(t1, tt.want, t.GetTraces(), "GetTraces()")
+		})
+	}
+}
+
+func TestTracer_ResetTraces(t1 *testing.T) {
+	type fields struct {
+		connectionId string
+		traceEntries []TraceEntry
+	}
+	tests := []struct {
+		name   string
+		fields fields
+	}{
+		{
+			name: "reset it",
+		},
+	}
+	for _, tt := range tests {
+		t1.Run(tt.name, func(t1 *testing.T) {
+			t := &Tracer{
+				connectionId: tt.fields.connectionId,
+				traceEntries: tt.fields.traceEntries,
+			}
+			t.ResetTraces()
+		})
+	}
+}
+
+func TestTracer_SetConnectionId(t1 *testing.T) {
+	type fields struct {
+		connectionId string
+		traceEntries []TraceEntry
+	}
+	type args struct {
+		connectionId string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		args   args
+	}{
+		{
+			name: "set it",
+		},
+	}
+	for _, tt := range tests {
+		t1.Run(tt.name, func(t1 *testing.T) {
+			t := &Tracer{
+				connectionId: tt.fields.connectionId,
+				traceEntries: tt.fields.traceEntries,
+			}
+			t.SetConnectionId(tt.args.connectionId)
+		})
+	}
+}