Skip to content

Commit

Permalink
fix linter issue for UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyufan2 committed Apr 16, 2024
1 parent e3aa698 commit e688535
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cns/restserver/v2/server_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v2

import (
"fmt"
"net"
"net/url"
"os"
Expand All @@ -13,6 +12,7 @@ import (
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/restserver"
acncommon "github.com/Azure/azure-container-networking/common"
"github.com/pkg/errors"
)

// TestStartServices will test three scenarios:
Expand All @@ -28,7 +28,7 @@ func TestStartServerWithCNSPort(t *testing.T) {

// Create the service with -p 8000
if err = startService(cnsPort, ""); err != nil {
fmt.Printf("Failed to start CNS Service. Error: %v", err)
t.Errorf("Failed to start CNS Service. Error: %v", err)
os.Exit(1)
}
}
Expand All @@ -40,7 +40,7 @@ func TestStartServerWithNoInput(t *testing.T) {
logger.InitLogger("testlogs", 0, 0, "./")

if err = startService("", ""); err != nil {
fmt.Printf("Failed to start CNS Service. Error: %v", err)
t.Errorf("Failed to start CNS Service. Error: %v", err)
os.Exit(1)
}
}
Expand All @@ -52,7 +52,7 @@ func TestStartServerWithCNSURL(t *testing.T) {

// Create the service with -c "localhost:8000"
if err = startService("", "tcp://localhost:8000"); err != nil {
fmt.Printf("Failed to start CNS Service. Error: %v", err)
t.Errorf("Failed to start CNS Service. Error: %v", err)
os.Exit(1)
}
}
Expand All @@ -66,7 +66,7 @@ func startService(cnsPort, cnsURL string) error {
nmagentClient := &fakes.NMAgentClientFake{}
service, err := restserver.NewHTTPRestService(&config, &fakes.WireserverClientFake{}, &fakes.WireserverProxyFake{}, nmagentClient, nil, nil, nil)
if err != nil {
return err
return errors.Wrap(err, "Failed to initialize service")
}
service.Name = "cns-test-server"

Check failure on line 71 in cns/restserver/v2/server_test.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

SA5011: possible nil pointer dereference (staticcheck)

Check failure on line 71 in cns/restserver/v2/server_test.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

SA5011: possible nil pointer dereference (staticcheck)

Expand All @@ -79,13 +79,13 @@ func startService(cnsPort, cnsURL string) error {
err = service.Init(&config)
if err != nil {
logger.Errorf("Failed to Init CNS, err:%v.\n", err)
return err
return errors.Wrap(err, "Failed to Init CNS")
}

err = service.Start(&config)
if err != nil {
logger.Errorf("Failed to start CNS, err:%v.\n", err)
return err
return errors.Wrap(err, "Failed to Start CNS")
}
}

Expand All @@ -103,7 +103,7 @@ func startService(cnsPort, cnsURL string) error {

_, err = net.DialTimeout("tcp", urls, 10*time.Millisecond)
if err != nil {
return err
return errors.Wrapf(err, "Failed to check reachability to urls %+v", urls)
}

return nil
Expand Down

0 comments on commit e688535

Please sign in to comment.