From 2c70abd83ff23e62ba89121642d7d80b6bfe4231 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Tue, 15 Oct 2024 09:22:30 -0400 Subject: [PATCH 1/3] Add tcp listener test --- pkg/backends/tcp_test.go | 91 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 pkg/backends/tcp_test.go diff --git a/pkg/backends/tcp_test.go b/pkg/backends/tcp_test.go new file mode 100644 index 000000000..44282af48 --- /dev/null +++ b/pkg/backends/tcp_test.go @@ -0,0 +1,91 @@ +package backends + +import ( + "crypto/tls" + "reflect" + "testing" + + "github.com/ansible/receptor/pkg/logger" +) + +/* func TestNewTCPDialer(t *testing.T) { + type args struct { + address string + redial bool + tls *tls.Config + logger *logger.ReceptorLogger + } + tests := []struct { + name string + args args + want *backends.TCPDialer + wantErr bool + }{ + { + name: "Positive", + args: args{ + address: "127.0.0.1:9999", + redial: true, + tls: nil, + logger: nil, + }, + want: nil, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := backends.NewTCPDialer(tt.args.address, tt.args.redial, tt.args.tls, tt.args.logger) + if (err != nil) != tt.wantErr { + t.Errorf("NewTCPDialer() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewTCPDialer() = %v, want %v", got, tt.want) + } + }) + } +} */ + +func TestNewTCPListener(t *testing.T) { + type args struct { + address string + tls *tls.Config + logger *logger.ReceptorLogger + } + tests := []struct { + name string + args args + want *TCPListener + wantErr bool + }{ + { + name: "Positive", + args: args{ + address: "127.0.0.1:9999", + tls: nil, + logger: nil, + }, + want: &TCPListener{ + address: "127.0.0.1:9999", + TLS: nil, + li: nil, + innerLi: nil, + logger: nil, + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := NewTCPListener(tt.args.address, tt.args.tls, tt.args.logger) + if (err != nil) != tt.wantErr { + t.Errorf("NewTCPListener() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewTCPListener() = %+v, want %+v", got, tt.want) + } + }) + } +} From c8e044280c4601354fd7438a6807328a527bc377 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Tue, 15 Oct 2024 09:28:20 -0400 Subject: [PATCH 2/3] Fix lint issue --- pkg/backends/tcp_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/backends/tcp_test.go b/pkg/backends/tcp_test.go index 44282af48..070c87d24 100644 --- a/pkg/backends/tcp_test.go +++ b/pkg/backends/tcp_test.go @@ -81,6 +81,7 @@ func TestNewTCPListener(t *testing.T) { got, err := NewTCPListener(tt.args.address, tt.args.tls, tt.args.logger) if (err != nil) != tt.wantErr { t.Errorf("NewTCPListener() error = %v, wantErr %v", err, tt.wantErr) + return } if !reflect.DeepEqual(got, tt.want) { From 0353185c82419a1ddeb65d794ab155a14aebbd75 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Wed, 16 Oct 2024 12:11:53 -0400 Subject: [PATCH 3/3] Remove comment block --- pkg/backends/tcp_test.go | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/pkg/backends/tcp_test.go b/pkg/backends/tcp_test.go index 070c87d24..7ff5b93a4 100644 --- a/pkg/backends/tcp_test.go +++ b/pkg/backends/tcp_test.go @@ -8,45 +8,6 @@ import ( "github.com/ansible/receptor/pkg/logger" ) -/* func TestNewTCPDialer(t *testing.T) { - type args struct { - address string - redial bool - tls *tls.Config - logger *logger.ReceptorLogger - } - tests := []struct { - name string - args args - want *backends.TCPDialer - wantErr bool - }{ - { - name: "Positive", - args: args{ - address: "127.0.0.1:9999", - redial: true, - tls: nil, - logger: nil, - }, - want: nil, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := backends.NewTCPDialer(tt.args.address, tt.args.redial, tt.args.tls, tt.args.logger) - if (err != nil) != tt.wantErr { - t.Errorf("NewTCPDialer() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("NewTCPDialer() = %v, want %v", got, tt.want) - } - }) - } -} */ - func TestNewTCPListener(t *testing.T) { type args struct { address string