From 86a8fa5441b4f0d91db9c22882f2f12384b995c6 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Thu, 5 Sep 2024 15:19:13 -0400 Subject: [PATCH 01/14] Add gettls null backend test --- pkg/backends/null_test.go | 41 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/pkg/backends/null_test.go b/pkg/backends/null_test.go index 61f432004..c9d16e788 100644 --- a/pkg/backends/null_test.go +++ b/pkg/backends/null_test.go @@ -1,6 +1,12 @@ -package backends +package backends_test -import "testing" +import ( + "crypto/tls" + "reflect" + "testing" + + "github.com/ansible/receptor/pkg/backends" +) func TestNullBackendCfgGetAddr(t *testing.T) { type fields struct { @@ -21,7 +27,7 @@ func TestNullBackendCfgGetAddr(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg := &NullBackendCfg{ + cfg := &backends.NullBackendCfg{ Local: tt.fields.Local, } if got := cfg.GetAddr(); got != tt.want { @@ -30,3 +36,32 @@ func TestNullBackendCfgGetAddr(t *testing.T) { }) } } + +func TestNullBackendCfgGetTLS(t *testing.T) { + type fields struct { + Local bool + } + tests := []struct { + name string + fields fields + want *tls.Config + }{ + { + name: "Positive", + fields: fields{ + Local: true, + }, + want: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cfg := &backends.NullBackendCfg{ + Local: tt.fields.Local, + } + if got := cfg.GetTLS(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NullBackendCfg.GetTLS() = %v, want %v", got, tt.want) + } + }) + } +} From a86e560ce08de40d24166d2c6a45d0e8a5ae8f8e Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Thu, 5 Sep 2024 15:22:16 -0400 Subject: [PATCH 02/14] Fix lint issue --- pkg/backends/null_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/backends/null_test.go b/pkg/backends/null_test.go index c9d16e788..1f32a9ccd 100644 --- a/pkg/backends/null_test.go +++ b/pkg/backends/null_test.go @@ -47,11 +47,11 @@ func TestNullBackendCfgGetTLS(t *testing.T) { want *tls.Config }{ { - name: "Positive", - fields: fields{ - Local: true, + name: "Positive", + fields: fields{ + Local: true, }, - want: nil, + want: nil, }, } for _, tt := range tests { From 2f7e7687f600e63264ec4709d7dcd4183a59d765 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Thu, 5 Sep 2024 15:25:01 -0400 Subject: [PATCH 03/14] Update golangci-lint version --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 7998730b9..4e23b0348 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -6,7 +6,7 @@ on: # yamllint disable-line rule:truthy env: DESIRED_GO_VERSION: '1.20' - DESIRED_GOLANGCI_LINT_VERSION: 'v1.56' + DESIRED_GOLANGCI_LINT_VERSION: 'v1.60' DESIRED_PYTHON_VERSION: '3.12' jobs: From 4f3ebca4c871853f8c54292f5d99900f92f28c3f Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Thu, 5 Sep 2024 15:42:02 -0400 Subject: [PATCH 04/14] Add nolint for lines with new issues for now --- pkg/controlsvc/controlsvc.go | 2 +- pkg/framer/framer.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/controlsvc/controlsvc.go b/pkg/controlsvc/controlsvc.go index 0c2015afd..6f23fdd81 100644 --- a/pkg/controlsvc/controlsvc.go +++ b/pkg/controlsvc/controlsvc.go @@ -516,7 +516,7 @@ func (cfg CmdlineConfigUnix) Run() error { } } err = MainInstance.RunControlSvc(context.Background(), cfg.Service, tlscfg, cfg.Filename, - os.FileMode(cfg.Permissions), cfg.TCPListen, tcptls) + os.FileMode(cfg.Permissions), cfg.TCPListen, tcptls) //nolint:gosec if err != nil { return err } diff --git a/pkg/framer/framer.go b/pkg/framer/framer.go index 7e15af92a..0224c037a 100644 --- a/pkg/framer/framer.go +++ b/pkg/framer/framer.go @@ -32,7 +32,7 @@ func New() Framer { // SendData takes a data buffer and returns a framed buffer. func (f *framer) SendData(data []byte) []byte { buf := make([]byte, len(data)+2) - binary.LittleEndian.PutUint16(buf[0:2], uint16(len(data))) + binary.LittleEndian.PutUint16(buf[0:2], uint16(len(data))) //nolint:gosec copy(buf[2:], data) return buf From 00780da95758422dd9a687fb73501066e5016364 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Thu, 5 Sep 2024 18:02:34 -0400 Subject: [PATCH 05/14] Fix remaining lint issues --- pkg/backends/websockets_test.go | 28 ++++++++--------- pkg/controlsvc/controlsvc.go | 2 +- pkg/netceptor/netceptor.go | 6 ++-- pkg/netceptor/ping.go | 2 +- pkg/services/unix_proxy.go | 2 +- pkg/utils/error_kind_test.go | 2 +- pkg/workceptor/command.go | 2 +- pkg/workceptor/kubernetes.go | 38 ++++++++++++------------ pkg/workceptor/stdio_utils_test.go | 2 +- tests/functional/mesh/receptorcontrol.go | 4 +-- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/pkg/backends/websockets_test.go b/pkg/backends/websockets_test.go index 9122e6c98..b6d43e3eb 100644 --- a/pkg/backends/websockets_test.go +++ b/pkg/backends/websockets_test.go @@ -158,7 +158,7 @@ func TestWebsocketDialerStart(t *testing.T) { mockWebsocketConner.EXPECT().ReadMessage().Return(0, []byte{}, nil).AnyTimes() sess, err := wd.Start(ctx, &sync.WaitGroup{}) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } s := <-sess @@ -214,7 +214,7 @@ func TestNewWebsocketListener(t *testing.T) { wi, err := backends.NewWebsocketListener("address", &tls.Config{}, logger.NewReceptorLogger("test"), mockWebsocketUpgrader, mockServer) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { @@ -227,7 +227,7 @@ func TestWebsocketListenerSetandGetPath(t *testing.T) { wi, err := backends.NewWebsocketListener("address", &tls.Config{}, logger.NewReceptorLogger("test"), mockWebsocketUpgrader, mockServer) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { @@ -251,7 +251,7 @@ func TestWebsocketListenerStart(t *testing.T) { wi, err := backends.NewWebsocketListener("localhost:21700", &tls.Config{}, logger.NewReceptorLogger("test"), mockWebsocketUpgrader, mockServer) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { t.Errorf("Websocket listener expected, nil returned") @@ -264,7 +264,7 @@ func TestWebsocketListenerStart(t *testing.T) { bs, err := wi.Start(ctx, &sync.WaitGroup{}) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if bs == nil { t.Errorf("Expected Websocket Listener, got nil") @@ -278,7 +278,7 @@ func TestWebsocketListenerStartUpgradeError(t *testing.T) { wi, err := backends.NewWebsocketListener("localhost:21701", &tls.Config{}, logger.NewReceptorLogger("test"), mockWebsocketUpgrader, mockServer) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { t.Errorf("Websocket listener expected, nil returned") @@ -309,7 +309,7 @@ func TestWebsocketListenerStartNetError(t *testing.T) { badAddress := "127.0.0.1:80" wi, err := backends.NewWebsocketListener(badAddress, &tls.Config{}, logger.NewReceptorLogger("test"), mockWebsocketUpgrader, mockServer) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { t.Errorf("Websocket listener expected, nil returned") @@ -319,7 +319,7 @@ func TestWebsocketListenerStartNetError(t *testing.T) { bs, err := wi.Start(ctx, &sync.WaitGroup{}) if !strings.Contains(err.Error(), "listen tcp 127.0.0.1:80: bind: permission denied") { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if bs != nil { t.Errorf("Expected Websocket Listener to be nil") @@ -335,7 +335,7 @@ func TestWebsocketListenerStartTLSNil(t *testing.T) { wi, err := backends.NewWebsocketListener("localhost:21702", nil, logger.NewReceptorLogger("test"), mockWebsocketUpgrader, mockServer) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { t.Errorf("Websocket listener expected, nil returned") @@ -347,7 +347,7 @@ func TestWebsocketListenerStartTLSNil(t *testing.T) { bs, err := wi.Start(ctx, &sync.WaitGroup{}) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if bs == nil { t.Errorf("Expected Websocket Listener not be nil") @@ -364,7 +364,7 @@ func TestWebsocketListenerGetAddr(t *testing.T) { wi, err := backends.NewWebsocketListener(address, &tls.Config{}, logger.NewReceptorLogger("test"), mockWebsocketUpgrader, mockServer) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { t.Errorf("Websocket listener expected, nil returned") @@ -377,7 +377,7 @@ func TestWebsocketListenerGetAddr(t *testing.T) { bs, err := wi.Start(ctx, &sync.WaitGroup{}) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if bs == nil { t.Errorf("Expected Websocket Listener, got nil") @@ -395,7 +395,7 @@ func TestWebsocketListenerGetTLS(t *testing.T) { blankTLS := &tls.Config{} wi, err := backends.NewWebsocketListener("127.0.0.1:21704", blankTLS, logger.NewReceptorLogger("test"), mockWebsocketUpgrader, mockServer) if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { t.Errorf("Websocket listener expected, nil returned") @@ -442,6 +442,6 @@ func TestWebsocketListenerCfg(t *testing.T) { err := wlc.Prepare() if err != nil { - t.Errorf(err.Error()) + t.Errorf(err.Error()) //nolint:govet,staticcheck } } diff --git a/pkg/controlsvc/controlsvc.go b/pkg/controlsvc/controlsvc.go index 6f23fdd81..f483cacde 100644 --- a/pkg/controlsvc/controlsvc.go +++ b/pkg/controlsvc/controlsvc.go @@ -516,7 +516,7 @@ func (cfg CmdlineConfigUnix) Run() error { } } err = MainInstance.RunControlSvc(context.Background(), cfg.Service, tlscfg, cfg.Filename, - os.FileMode(cfg.Permissions), cfg.TCPListen, tcptls) //nolint:gosec + os.FileMode(cfg.Permissions), cfg.TCPListen, tcptls) //nolint:gosec if err != nil { return err } diff --git a/pkg/netceptor/netceptor.go b/pkg/netceptor/netceptor.go index 96f532f7e..01b372eaf 100644 --- a/pkg/netceptor/netceptor.go +++ b/pkg/netceptor/netceptor.go @@ -1025,7 +1025,7 @@ func ReceptorVerifyFunc(tlscfg *tls.Config, pinnedFingerprints [][]byte, expecte if err != nil { logger.Error("RVF failed to parse: %s", err) - return fmt.Errorf("failed to parse certificate from server: " + err.Error()) + return fmt.Errorf("failed to parse certificate from server: " + err.Error()) //nolint:govet } certs[i] = cert } @@ -1383,7 +1383,7 @@ func (s *Netceptor) printRoutingTable() { _, _ = fmt.Fprintf(sb, "%s(%.2f) ", peer, s.knownConnectionCosts[conn][peer]) } _, _ = fmt.Fprintf(sb, "\n") - s.Logger.Log(logLevel, sb.String()) + s.Logger.Log(logLevel, sb.String()) //nolint:govet } s.Logger.Log(logLevel, "Routing Table:\n") for node := range s.routingTable { @@ -1656,7 +1656,7 @@ func (s *Netceptor) handleMessageData(md *MessageData) error { if !ok || pc.context.Err() != nil { s.listenerLock.RUnlock() if md.FromNode == s.nodeID { - return fmt.Errorf(ProblemServiceUnknown) + return fmt.Errorf(ProblemServiceUnknown) //nolint:staticcheck } _ = s.sendUnreachable(md.FromNode, &UnreachableMessage{ FromNode: md.FromNode, diff --git a/pkg/netceptor/ping.go b/pkg/netceptor/ping.go index af4acf021..028eb3c8b 100644 --- a/pkg/netceptor/ping.go +++ b/pkg/netceptor/ping.go @@ -43,7 +43,7 @@ func SendPing(ctx context.Context, s NetcForPing, target string, hopsToLive byte go func() { for msg := range unrCh { errorChan <- errorResult{ - err: fmt.Errorf(msg.Problem), + err: fmt.Errorf(msg.Problem), //nolint:govet fromNode: msg.ReceivedFromNode, } } diff --git a/pkg/services/unix_proxy.go b/pkg/services/unix_proxy.go index de56b25e6..a3c463818 100644 --- a/pkg/services/unix_proxy.go +++ b/pkg/services/unix_proxy.go @@ -92,7 +92,7 @@ func (cfg UnixProxyInboundCfg) Run() error { return err } - return UnixProxyServiceInbound(netceptor.MainInstance, cfg.Filename, os.FileMode(cfg.Permissions), + return UnixProxyServiceInbound(netceptor.MainInstance, cfg.Filename, os.FileMode(cfg.Permissions), //nolint:gosec cfg.RemoteNode, cfg.RemoteService, tlscfg) } diff --git a/pkg/utils/error_kind_test.go b/pkg/utils/error_kind_test.go index b7da476bd..69b39e477 100644 --- a/pkg/utils/error_kind_test.go +++ b/pkg/utils/error_kind_test.go @@ -13,7 +13,7 @@ const ( goodErrorString string = "unit was already started" ) -var errUnitWasAlreadyStarted error = fmt.Errorf(goodErrorString) +var errUnitWasAlreadyStarted error = fmt.Errorf(goodErrorString) //nolint:staticcheck func TestErrorWithKind_Error(t *testing.T) { type fields struct { diff --git a/pkg/workceptor/command.go b/pkg/workceptor/command.go index a51fd9ba0..2ff793ce5 100644 --- a/pkg/workceptor/command.go +++ b/pkg/workceptor/command.go @@ -436,7 +436,7 @@ func filenameExists(filename string) error { func (cfg SigningKeyPrivateCfg) Prepare() error { duration, err := cfg.PrepareSigningKeyPrivateCfg() if err != nil { - return fmt.Errorf(err.Error()) + return fmt.Errorf(err.Error()) //nolint:govet,staticcheck } MainInstance.SigningExpiration = *duration diff --git a/pkg/workceptor/kubernetes.go b/pkg/workceptor/kubernetes.go index 67e4ae461..ce094303c 100644 --- a/pkg/workceptor/kubernetes.go +++ b/pkg/workceptor/kubernetes.go @@ -261,7 +261,7 @@ func (kw *KubeUnit) kubeLoggingConnectionHandler(timestamps bool, sinceTime time } if err != nil { errMsg := fmt.Sprintf("Error opening log stream for pod %s/%s. Error: %s", podNamespace, podName, err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) return nil, err @@ -329,7 +329,7 @@ func (kw *KubeUnit) kubeLoggingWithReconnect(streamWait *sync.WaitGroup, stdout } if err != nil { errMsg := fmt.Sprintf("Error getting pod %s/%s. Error: %s", podNamespace, podName, err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) // fail to get pod, no need to continue @@ -559,10 +559,10 @@ func (kw *KubeUnit) createPod(env map[string]string) error { stdout, err2 := NewStdoutWriter(FileSystem{}, kw.UnitDir()) if err2 != nil { errMsg := fmt.Sprintf("Error opening stdout file: %s", err2) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) - return fmt.Errorf(errMsg) + return fmt.Errorf(errMsg) //nolint:govet,staticcheck } var stdoutErr error var streamWait sync.WaitGroup @@ -611,7 +611,7 @@ func (kw *KubeUnit) runWorkUsingLogger() { if err := kw.createPod(nil); err != nil { if err != ErrPodCompleted { errMsg := fmt.Sprintf("Error creating pod: %s", err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) return @@ -628,7 +628,7 @@ func (kw *KubeUnit) runWorkUsingLogger() { errMsg := fmt.Sprintf("Error creating pod: pod namespace is empty for pod %s", podName, ) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) return @@ -641,7 +641,7 @@ func (kw *KubeUnit) runWorkUsingLogger() { select { case <-kw.GetContext().Done(): errMsg := fmt.Sprintf("Context Done while getting pod %s/%s. Error: %s", podNamespace, podName, kw.GetContext().Err()) - kw.GetWorkceptor().nc.GetLogger().Warning(errMsg) + kw.GetWorkceptor().nc.GetLogger().Warning(errMsg) //nolint:govet return default: @@ -662,7 +662,7 @@ func (kw *KubeUnit) runWorkUsingLogger() { } if err != nil { errMsg := fmt.Sprintf("Error getting pod %s/%s. Error: %s", podNamespace, podName, err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) return @@ -715,7 +715,7 @@ func (kw *KubeUnit) runWorkUsingLogger() { skipStdin = true } else { errMsg := fmt.Sprintf("Error opening stdin file: %s", err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) return @@ -740,7 +740,7 @@ func (kw *KubeUnit) runWorkUsingLogger() { stdout, err := NewStdoutWriter(FileSystem{}, kw.UnitDir()) if err != nil { errMsg := fmt.Sprintf("Error opening stdout file: %s", err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) return @@ -806,7 +806,7 @@ func (kw *KubeUnit) runWorkUsingLogger() { podName, err, ) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, stdout.Size()) close(stdinErrChan) // signal STDOUT goroutine to stop @@ -816,7 +816,7 @@ func (kw *KubeUnit) runWorkUsingLogger() { } else { // this is probably not possible... errMsg := fmt.Sprintf("Error reading stdin: %s", stdin.Error()) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.GetWorkceptor().nc.GetLogger().Error("Pod status at time of error %s", kw.pod.Status.String()) kw.UpdateBasicStatus(WorkStateFailed, errMsg, stdout.Size()) @@ -1008,7 +1008,7 @@ func (kw *KubeUnit) runWorkUsingTCP() { if err != nil { errMsg := fmt.Sprintf("Error listening: %s", err) kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet return } @@ -1032,7 +1032,7 @@ func (kw *KubeUnit) runWorkUsingTCP() { if err != nil { errMsg := fmt.Sprintf("Error accepting: %s", err) kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet cancel() return @@ -1045,7 +1045,7 @@ func (kw *KubeUnit) runWorkUsingTCP() { if err != nil { errMsg := fmt.Sprintf("Error creating pod: %s", err) kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet cancel() return @@ -1064,7 +1064,7 @@ func (kw *KubeUnit) runWorkUsingTCP() { stdin, err = NewStdinReader(FileSystem{}, kw.UnitDir()) if err != nil { errMsg := fmt.Sprintf("Error opening stdin file: %s", err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) cancel() @@ -1075,7 +1075,7 @@ func (kw *KubeUnit) runWorkUsingTCP() { stdout, err := NewStdoutWriter(FileSystem{}, kw.UnitDir()) if err != nil { errMsg := fmt.Sprintf("Error opening stdout file: %s", err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) cancel() @@ -1093,7 +1093,7 @@ func (kw *KubeUnit) runWorkUsingTCP() { _ = conn.CloseWrite() if err != nil { errMsg := fmt.Sprintf("Error sending stdin to pod: %s", err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) cancel() @@ -1125,7 +1125,7 @@ func (kw *KubeUnit) runWorkUsingTCP() { } if err != nil { errMsg := fmt.Sprintf("Error reading stdout from pod: %s", err) - kw.GetWorkceptor().nc.GetLogger().Error(errMsg) + kw.GetWorkceptor().nc.GetLogger().Error(errMsg) //nolint:govet kw.UpdateBasicStatus(WorkStateFailed, errMsg, 0) cancel() diff --git a/pkg/workceptor/stdio_utils_test.go b/pkg/workceptor/stdio_utils_test.go index 2b6c73e17..a2e40cbc3 100644 --- a/pkg/workceptor/stdio_utils_test.go +++ b/pkg/workceptor/stdio_utils_test.go @@ -54,7 +54,7 @@ func setupReader(t *testing.T) (*gomock.Controller, *workceptor.STDinReader) { wc, err := workceptor.NewStdinReader(mockfilesystemer, "") if err != nil { - t.Errorf(stdinError) + t.Errorf(stdinError) //nolint:staticcheck } return ctrl, wc diff --git a/tests/functional/mesh/receptorcontrol.go b/tests/functional/mesh/receptorcontrol.go index 3ddc2ec51..b680ddcfb 100644 --- a/tests/functional/mesh/receptorcontrol.go +++ b/tests/functional/mesh/receptorcontrol.go @@ -161,7 +161,7 @@ func (r *ReceptorControl) ReadAndParseJSON() (map[string]interface{}, error) { } if str := string(data); strings.HasPrefix(str, "ERROR") { - return nil, fmt.Errorf(str) + return nil, fmt.Errorf(str) //nolint:govet,staticcheck } jsonData := make(map[string]interface{}) err = json.Unmarshal(data, &jsonData) @@ -213,7 +213,7 @@ func (r *ReceptorControl) getWorkSubmitResponse() (string, error) { msg, err := r.ReadStr() // flush getWorkSubmitResponse if !strings.Contains(msg, "Send stdin data and EOF.") { - return "", fmt.Errorf(msg) + return "", fmt.Errorf(msg) //nolint:govet,staticcheck } if err != nil { From 5f47e0e024ab42b3892b805cdacfc329675383d6 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Fri, 6 Sep 2024 05:42:31 -0400 Subject: [PATCH 06/14] Sonarlint fixes --- pkg/backends/websockets_test.go | 50 +++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/pkg/backends/websockets_test.go b/pkg/backends/websockets_test.go index b6d43e3eb..9c4b5efd7 100644 --- a/pkg/backends/websockets_test.go +++ b/pkg/backends/websockets_test.go @@ -24,6 +24,14 @@ import ( "github.com/golang/mock/gomock" ) +const ( + expectedWebsocketListenerError = "Expected Websocket Listener, got nil" + newWebsocketDialerError = "NewWebsockerDialer return error: %+v" + websocketListenerExpectedError = "Websocket listener expected, nil returned" + websocketsTestNewWebsocketDialer = "websockets_test.go>TestNewWebsocketDialer" + wssTestTesting = "wss://test.testing" +) + func setupTLSCfg(t *testing.T) tls.Certificate { // Create a server TLS certificate for "localhost" key, err := rsa.GenerateKey(rand.Reader, 2048) @@ -66,7 +74,7 @@ func TestNewWebsocketDialer(t *testing.T) { }{ { name: "NewWebsocketDialer wss Success ", - address: "wss://test.testing", + address: wssTestTesting, redial: false, tlscfg: &tls.Config{ Certificates: []tls.Certificate{setupTLSCfg(t)}, @@ -74,7 +82,7 @@ func TestNewWebsocketDialer(t *testing.T) { PreferServerCipherSuites: true, }, extraHeader: "", - logger: logger.NewReceptorLogger("websockets_test.go>TestNewWebsocketDialer"), + logger: logger.NewReceptorLogger(websocketsTestNewWebsocketDialer), expectedErr: "", failedTestString: "Expected no error, but got: %v", }, @@ -88,7 +96,7 @@ func TestNewWebsocketDialer(t *testing.T) { PreferServerCipherSuites: true, }, extraHeader: "", - logger: logger.NewReceptorLogger("websockets_test.go>TestNewWebsocketDialer"), + logger: logger.NewReceptorLogger(websocketsTestNewWebsocketDialer), expectedErr: "", failedTestString: "Expected no error, but got: %v", }, @@ -130,9 +138,9 @@ func TestWebsocketDialerStart(t *testing.T) { ctx := context.Background() defer ctx.Done() - wd, wdErr := backends.NewWebsocketDialer("wss://test.testing", &tls.Config{}, "", false, logger.NewReceptorLogger("websockets_test.go>TestNewWebsocketDialer"), mockWebsocketDialer) + wd, wdErr := backends.NewWebsocketDialer(wssTestTesting, &tls.Config{}, "", false, logger.NewReceptorLogger(websocketsTestNewWebsocketDialer), mockWebsocketDialer) if wdErr != nil { - t.Errorf("NewWebsockerDialer return error: %v", wdErr) + t.Errorf(newWebsocketDialerError, wdErr) } resp := &http.Response{ Body: io.NopCloser(bytes.NewBufferString("Hello World")), @@ -175,10 +183,10 @@ func TestWebsocketDialerStart(t *testing.T) { func TestWebsocketDialerGetAddr(t *testing.T) { _, mockWebsocketDialer := setUpDialer(t) - address := "wss://test.testing" - wd, wdErr := backends.NewWebsocketDialer(address, &tls.Config{}, "", false, logger.NewReceptorLogger("websockets_test.go>TestNewWebsocketDialer"), mockWebsocketDialer) + address := wssTestTesting + wd, wdErr := backends.NewWebsocketDialer(address, &tls.Config{}, "", false, logger.NewReceptorLogger(websocketsTestNewWebsocketDialer), mockWebsocketDialer) if wdErr != nil { - t.Errorf("NewWebsockerDialer return error: %v", wdErr) + t.Errorf(newWebsocketDialerError, wdErr) } add := wd.GetAddr() if add != address { @@ -190,9 +198,9 @@ func TestWebsocketDialerGetTLS(t *testing.T) { _, mockWebsocketDialer := setUpDialer(t) blankTLS := &tls.Config{} - wd, wdErr := backends.NewWebsocketDialer("wss://test.testing", blankTLS, "", false, logger.NewReceptorLogger("websockets_test.go>TestNewWebsocketDialer"), mockWebsocketDialer) + wd, wdErr := backends.NewWebsocketDialer(wssTestTesting, blankTLS, "", false, logger.NewReceptorLogger(websocketsTestNewWebsocketDialer), mockWebsocketDialer) if wdErr != nil { - t.Errorf("NewWebsockerDialer return error: %v", wdErr) + t.Errorf(newWebsocketDialerError, wdErr) } TLS := wd.GetTLS() if TLS != blankTLS { @@ -218,7 +226,7 @@ func TestNewWebsocketListener(t *testing.T) { } if wi == nil { - t.Errorf("Websocket listener expected, nil returned") + t.Error(websocketListenerExpectedError) } } @@ -231,7 +239,7 @@ func TestWebsocketListenerSetandGetPath(t *testing.T) { } if wi == nil { - t.Errorf("Websocket listener expected, nil returned") + t.Error(websocketListenerExpectedError) } pathName := "Test Path" @@ -254,7 +262,7 @@ func TestWebsocketListenerStart(t *testing.T) { t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { - t.Errorf("Websocket listener expected, nil returned") + t.Error(websocketListenerExpectedError) } mockWebsocketUpgrader.EXPECT().Upgrade(gomock.Any(), gomock.Any(), gomock.Any()).Return(mockWebsocketConner, nil).AnyTimes() @@ -267,7 +275,7 @@ func TestWebsocketListenerStart(t *testing.T) { t.Errorf(err.Error()) //nolint:govet,staticcheck } if bs == nil { - t.Errorf("Expected Websocket Listener, got nil") + t.Error(expectedWebsocketListenerError) } } @@ -281,7 +289,7 @@ func TestWebsocketListenerStartUpgradeError(t *testing.T) { t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { - t.Errorf("Websocket listener expected, nil returned") + t.Error(websocketListenerExpectedError) } returnError := errors.New("Upgrade Error") @@ -295,7 +303,7 @@ func TestWebsocketListenerStartUpgradeError(t *testing.T) { t.Errorf("Expected error %v, got %v instead", nil, err) } if bs == nil { - t.Errorf("Expected Websocket Listener, got nil") + t.Error(expectedWebsocketListenerError) } } @@ -312,7 +320,7 @@ func TestWebsocketListenerStartNetError(t *testing.T) { t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { - t.Errorf("Websocket listener expected, nil returned") + t.Error(websocketListenerExpectedError) } mockWebsocketUpgrader.EXPECT().Upgrade(gomock.Any(), gomock.Any(), gomock.Any()).Return(mockWebsocketConner, nil).AnyTimes() @@ -338,7 +346,7 @@ func TestWebsocketListenerStartTLSNil(t *testing.T) { t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { - t.Errorf("Websocket listener expected, nil returned") + t.Error(websocketListenerExpectedError) } mockWebsocketUpgrader.EXPECT().Upgrade(gomock.Any(), gomock.Any(), gomock.Any()).Return(mockWebsocketConner, nil).AnyTimes() @@ -367,7 +375,7 @@ func TestWebsocketListenerGetAddr(t *testing.T) { t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { - t.Errorf("Websocket listener expected, nil returned") + t.Error(websocketListenerExpectedError) } mockWebsocketUpgrader.EXPECT().Upgrade(gomock.Any(), gomock.Any(), gomock.Any()).Return(mockWebsocketConner, nil).AnyTimes() @@ -380,7 +388,7 @@ func TestWebsocketListenerGetAddr(t *testing.T) { t.Errorf(err.Error()) //nolint:govet,staticcheck } if bs == nil { - t.Errorf("Expected Websocket Listener, got nil") + t.Error(expectedWebsocketListenerError) } add := wi.GetAddr() @@ -398,7 +406,7 @@ func TestWebsocketListenerGetTLS(t *testing.T) { t.Errorf(err.Error()) //nolint:govet,staticcheck } if wi == nil { - t.Errorf("Websocket listener expected, nil returned") + t.Error(websocketListenerExpectedError) } TLS := wi.GetTLS() From 0ff0de0d42dbb3dbf7460745e1d3acd943507f42 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Fri, 6 Sep 2024 09:24:35 -0400 Subject: [PATCH 07/14] Add sonarcloud properties file --- .sonarcloud.properties | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .sonarcloud.properties diff --git a/.sonarcloud.properties b/.sonarcloud.properties new file mode 100644 index 000000000..bd69c4403 --- /dev/null +++ b/.sonarcloud.properties @@ -0,0 +1,2 @@ +sonar.python.version=3.8,3.9,3.11,3.12 +sonar.tests=**/*_test.go,receptorctl/tets/ From ecda5c054413929b4b3e233f0ccb4a18b772a494 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Fri, 6 Sep 2024 10:51:47 -0400 Subject: [PATCH 08/14] Fix typo in path --- .sonarcloud.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.sonarcloud.properties b/.sonarcloud.properties index bd69c4403..ca33c10ee 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,2 +1,2 @@ sonar.python.version=3.8,3.9,3.11,3.12 -sonar.tests=**/*_test.go,receptorctl/tets/ +sonar.tests=**/*_test.go,receptorctl/tests/ From 6135750806d075f3030381749cf4002d87bc71dc Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Fri, 6 Sep 2024 11:02:50 -0400 Subject: [PATCH 09/14] Add sonar.sources explicitly --- .sonarcloud.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/.sonarcloud.properties b/.sonarcloud.properties index ca33c10ee..1b67dd193 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,2 +1,3 @@ sonar.python.version=3.8,3.9,3.11,3.12 +sonar.sources=./ sonar.tests=**/*_test.go,receptorctl/tests/ From 043f9d40f96f9fd3d1f1622a1f4be7f8d90a583f Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Fri, 6 Sep 2024 12:55:10 -0400 Subject: [PATCH 10/14] Try to get automatic analysis to work --- .sonarcloud.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.sonarcloud.properties b/.sonarcloud.properties index 1b67dd193..e2a36da5c 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,3 +1,3 @@ sonar.python.version=3.8,3.9,3.11,3.12 -sonar.sources=./ +sonar.sources=. sonar.tests=**/*_test.go,receptorctl/tests/ From 5d0c790eca5c40b87f33965f854ea69433372b1c Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Fri, 6 Sep 2024 13:06:16 -0400 Subject: [PATCH 11/14] Added space to python versions --- .sonarcloud.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.sonarcloud.properties b/.sonarcloud.properties index e2a36da5c..bc82ce279 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,3 +1,3 @@ -sonar.python.version=3.8,3.9,3.11,3.12 +sonar.python.version=3.8, 3.9, 3.11, 3.12 sonar.sources=. sonar.tests=**/*_test.go,receptorctl/tests/ From a19e359d0febe95e84950b646d42179c6937080a Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Fri, 6 Sep 2024 13:10:25 -0400 Subject: [PATCH 12/14] Added space to tests --- .sonarcloud.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.sonarcloud.properties b/.sonarcloud.properties index bc82ce279..c42755a7d 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,3 +1,3 @@ sonar.python.version=3.8, 3.9, 3.11, 3.12 sonar.sources=. -sonar.tests=**/*_test.go,receptorctl/tests/ +sonar.tests=**/*_test.go, receptorctl/tests/ From e718f95ad8b035cb31e71d75ca9a26463157ec0d Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Fri, 6 Sep 2024 13:12:43 -0400 Subject: [PATCH 13/14] Added sonar.test.inclusions --- .sonarcloud.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.sonarcloud.properties b/.sonarcloud.properties index c42755a7d..08c1b9e1d 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,3 +1,4 @@ sonar.python.version=3.8, 3.9, 3.11, 3.12 sonar.sources=. -sonar.tests=**/*_test.go, receptorctl/tests/ +sonar.tests=. +sonar.test.inclusions=**/*_test.go, receptorctl/tests/ From 5726188288f2632fe6de519c4f87c8c36014b047 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Fri, 6 Sep 2024 13:21:09 -0400 Subject: [PATCH 14/14] Final check --- .sonarcloud.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.sonarcloud.properties b/.sonarcloud.properties index 08c1b9e1d..d08e0660a 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,4 +1,4 @@ sonar.python.version=3.8, 3.9, 3.11, 3.12 sonar.sources=. -sonar.tests=. sonar.test.inclusions=**/*_test.go, receptorctl/tests/ +sonar.tests=.