Enable gometalinter on tests and fix static analysis issues #631 (#644)

* Enable gometalinter on tests and fix static analysis issues

* Remove unneeded change

* Fix additional lint errors

* Add nolint directives and error checks

* Add error assertions instead of nolint directives

* Go back to using lint directive for loop.Run goroutine

* Add error check to loop.Run
This commit is contained in:
Alex Kohler 2018-02-12 06:16:06 -05:00 committed by Dmitry Shulyak
parent a4c36fe96a
commit 365bc662a2
8 changed files with 39 additions and 12 deletions

View File

@ -5,6 +5,7 @@
],
"Skip": ["helpers", "static"],
"Vendor": true,
"Test": true,
"Enable": [
"deadcode",
"errcheck",

View File

@ -151,7 +151,10 @@ func (s *CellTestSuite) TestCellFetchErrorRace() {
// Find a free port in localhost
freeportListener, err := net.Listen("tcp", "127.0.0.1:0")
s.Require().NoError(err)
defer freeportListener.Close()
defer func() {
err := freeportListener.Close()
s.NoError(err)
}()
// Send an HTTP request to the free port that we found above
_, err = cell.Run(fmt.Sprintf(`fetch('%s').then(function(r) {
@ -237,7 +240,8 @@ func (s *CellTestSuite) TestCellCallAsync() {
fn, err := s.cell.Get("testCallAsync")
s.NoError(err)
s.cell.CallAsync(fn, "success")
err = s.cell.CallAsync(fn, "success")
s.NoError(err)
s.Equal("success", <-datac)
}

View File

@ -53,7 +53,10 @@ func (s *LoopSuite) SetupTest() {
ctx, cancel := context.WithCancel(context.Background())
s.cancel = cancel
go s.loop.Run(ctx)
go func() {
err := s.loop.Run(ctx)
s.Equal(context.Canceled, err)
}()
}
func (s *LoopSuite) TestAddAndReady() {

View File

@ -27,7 +27,10 @@ func TestRequestMessagesFailures(t *testing.T) {
nodeA, nodeErr := node.New(&node.Config{NoUSB: true})
require.NoError(t, nodeErr)
require.NoError(t, nodeA.Start())
defer nodeA.Stop()
defer func() {
err := nodeA.Stop()
require.NoError(t, err)
}()
const (
mailServerPeer = "enode://b7e65e1bedc2499ee6cbd806945af5e7df0e59e4070c96821570bd581473eade24a489f5ec95d060c0db118c879403ab88d827d3766978f28708989d35474f87@[::]:51920"

View File

@ -19,7 +19,10 @@ func TestSubscribeServerEvents(t *testing.T) {
require.NoError(t, err)
err = node.Start()
require.NoError(t, err)
defer node.Stop()
defer func() {
err := node.Stop()
require.NoError(t, err)
}()
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})

View File

@ -26,7 +26,10 @@ func TestProfilingCPU(t *testing.T) {
// Verify that the file has some content.
file, err := os.Open(filepath.Join(dir, CPUFilename))
require.NoError(t, err)
defer file.Close()
defer func() {
err := file.Close()
require.NoError(t, err)
}()
t.Logf("CPU profile saved in %s for %s", filepath.Join(dir, CPUFilename), os.Args[0])
@ -45,7 +48,10 @@ func TestProfilingMem(t *testing.T) {
// Verify that the file has some content.
file, err := os.Open(filepath.Join(dir, MemFilename))
require.NoError(t, err)
defer file.Close()
defer func() {
err := file.Close()
require.NoError(t, err)
}()
t.Logf("Memory profile saved in %s for %s", filepath.Join(dir, MemFilename), os.Args[0])

View File

@ -53,7 +53,10 @@ func (s *MailServiceSuite) TestShhRequestMessagesRPCMethodAvailability() {
r.NoError(err)
resp, err := http.DefaultClient.Do(req)
r.NoError(err)
defer resp.Body.Close()
defer func() {
err := resp.Body.Close()
r.NoError(err)
}()
r.Equal(200, resp.StatusCode)
data, err := ioutil.ReadAll(resp.Body)
r.NoError(err)

View File

@ -213,7 +213,8 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() {
messages := s.getMessagesByMessageFilterID(bobRPCClient, bobMessageFilterID)
s.Require().Equal(1, len(messages))
bobGroupChatData := groupChatParams{}
bobGroupChatData.Decode(messages[0]["payload"].(string))
err = bobGroupChatData.Decode(messages[0]["payload"].(string))
s.Require().NoError(err)
s.EqualValues(groupChatPayload, bobGroupChatData)
//2. bob add symkey to his node
@ -228,7 +229,8 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() {
messages = s.getMessagesByMessageFilterID(charlieRPCClient, charlieMessageFilterID)
s.Require().Equal(1, len(messages))
charlieGroupChatData := groupChatParams{}
charlieGroupChatData.Decode(messages[0]["payload"].(string))
err = charlieGroupChatData.Decode(messages[0]["payload"].(string))
s.Require().NoError(err)
s.EqualValues(groupChatPayload, charlieGroupChatData)
//2. charlie add symkey to his node
@ -319,7 +321,8 @@ func (s *WhisperMailboxSuite) startBackend(name string) (*api.StatusBackend, fun
s.True(backend.IsNodeRunning())
s.NoError(backend.StopNode())
s.False(backend.IsNodeRunning())
os.RemoveAll(datadir)
err = os.RemoveAll(datadir)
s.Require().NoError(err)
}
}
@ -346,7 +349,8 @@ func (s *WhisperMailboxSuite) startMailboxBackend() (*api.StatusBackend, func())
s.True(mailboxBackend.IsNodeRunning())
s.NoError(mailboxBackend.StopNode())
s.False(mailboxBackend.IsNodeRunning())
os.RemoveAll(datadir)
err = os.RemoveAll(datadir)
s.Require().NoError(err)
}
}