Skip to content

Commit

Permalink
Fix a few linter warnings (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi authored Sep 1, 2024
2 parents 8e03168 + 1735909 commit 262116b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion mdns/avahi.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func (a *AvahiProvider) Announce(serviceName string, port int, txt []string) err
}

for _, iface := range a.ifaceIndexes {
err = entryGroup.AddService(iface, avahi.ProtoUnspec, 0, serviceName, shipZeroConfServiceType, shipZeroConfDomain, "", uint16(port), btxt)
// conversion is safe, as port values are always positive
err = entryGroup.AddService(iface, avahi.ProtoUnspec, 0, serviceName, shipZeroConfServiceType, shipZeroConfDomain, "", uint16(port), btxt) // #nosec G115
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion mdns/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (m *MdnsManager) interfaces() ([]net.Interface, []int32, error) {
return nil, nil, err
}
ifaces[i] = *iface
ifaceIndexes[i] = int32(iface.Index)
// conversion is safe, as the index is always positive and not higher than int32
ifaceIndexes[i] = int32(iface.Index) // #nosec G115
}
}

Expand Down
6 changes: 4 additions & 2 deletions ship/hs_hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func (c *ShipConnection) handshakeHello_PendingListen(timeout bool, message []by

c.stopHandshakeTimer()

newDuration := time.Duration(*hello.Waiting) * time.Millisecond
// conversion is safe
newDuration := time.Duration(*hello.Waiting) * time.Millisecond // #nosec G115
duration := tHelloProlongThrInc
if newDuration >= duration {
// the duration has to be reduced
Expand All @@ -162,7 +163,8 @@ func (c *ShipConnection) handshakeHello_PendingListen(timeout bool, message []by
if hello.Waiting != nil && hello.ProlongationRequest == nil {
c.stopHandshakeTimer()

newDuration := time.Duration(*hello.Waiting) * time.Millisecond
// conversion is safe
newDuration := time.Duration(*hello.Waiting) * time.Millisecond // #nosec G115
c.lastReceivedWaitingValue = newDuration
duration := tHelloProlongThrInc
if newDuration >= duration {
Expand Down
2 changes: 0 additions & 2 deletions ws/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ func (w *WebsocketConnection) close() {
if w.conn != nil {
_ = w.conn.Close()
}

})
}

Expand Down Expand Up @@ -294,7 +293,6 @@ func (w *WebsocketConnection) writeMessageWithoutErrorHandling(messageType int,

// shutdown the connection and all internals
func (w *WebsocketConnection) CloseDataConnection(closeCode int, reason string) {

// send a close message to the remote side if we have a reason
if reason != "" {
_ = w.writeMessageWithoutErrorHandling(websocket.CloseMessage, websocket.FormatCloseMessage(closeCode, reason))
Expand Down
17 changes: 11 additions & 6 deletions ws/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type WebsocketSuite struct {

sut *WebsocketConnection

testServer *httptest.Server
testWsConn *websocket.Conn
testServer *httptest.Server
testResponse *http.Response
testWsConn *websocket.Conn

wsDataReader *mocks.WebsocketDataReaderInterface
}
Expand All @@ -38,13 +39,17 @@ func (s *WebsocketSuite) BeforeTest(suiteName, testName string) {
s.wsDataReader.EXPECT().HandleIncomingWebsocketMessage(mock.Anything).Return().Maybe()

ts := &testServer{}
s.testServer, s.testWsConn = newWSServer(s.T(), ts)

// body close is done in AfterTest
//nolint:bodyclose
s.testServer, s.testResponse, s.testWsConn = newWSServer(s.T(), ts)

s.sut = NewWebsocketConnection(s.testWsConn, "remoteSki")
s.sut.InitDataProcessing(s.wsDataReader)
}

func (s *WebsocketSuite) AfterTest(suiteName, testName string) {
s.testResponse.Body.Close()
_ = s.testWsConn.Close()
s.testServer.Close()
}
Expand Down Expand Up @@ -156,19 +161,19 @@ func (s *WebsocketSuite) TestCloseWithError() {

var upgrader = websocket.Upgrader{}

func newWSServer(t *testing.T, h http.Handler) (*httptest.Server, *websocket.Conn) {
func newWSServer(t *testing.T, h http.Handler) (*httptest.Server, *http.Response, *websocket.Conn) {
t.Helper()

s := httptest.NewServer(h)
wsURL := strings.Replace(s.URL, "http://", "ws://", -1)
wsURL = strings.Replace(wsURL, "https://", "wss://", -1)

ws, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
ws, resp, err := websocket.DefaultDialer.Dial(wsURL, nil)
if err != nil {
t.Fatal(err)
}

return s, ws
return s, resp, ws
}

type testServer struct {
Expand Down

0 comments on commit 262116b

Please sign in to comment.