From 8db933f9c7365f0933f234b4c7b152ccd2e014f0 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 18 Jun 2018 15:31:58 -0500 Subject: [PATCH] lint: minor warns on tests --- README.md | 6 +++--- app/main_test.go | 6 ++++-- app/migrator/backup_test.go | 4 ++-- app/rest/api/rest_test.go | 3 ++- app/rest/auth/jwt_test.go | 6 +++--- app/rest/cache/memory_test.go | 4 ++-- app/rest/proxy/avatar_store_test.go | 3 ++- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c618025c..35c24d97 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ Add this snippet to the bottom of web page: (function() { var d = document, s = d.createElement('script'); - s.src = '/web/embed.js'; // prepend this address with domain where remark42 is placed + s.src = '/web/embed.js'; // prepends this address with domain where remark42 is placed (d.head || d.body).appendChild(s); })(); @@ -259,7 +259,7 @@ Add this snippet to the bottom of web page: (function() { var d = document, s = d.createElement('script'); - s.src = '/web/last-comments.js'; // prepend this address with domain where remark42 is placed + s.src = '/web/last-comments.js'; // prepends this address with domain where remark42 is placed (d.head || d.body).appendChild(s); })(); @@ -287,7 +287,7 @@ Add this snippet to the bottom of web page: (function() { var d = document, s = d.createElement('script'); - s.src = '/web/counter.js'; // prepend this address with domain where remark42 is placed + s.src = '/web/counter.js'; // prepends this address with domain where remark42 is placed (d.head || d.body).appendChild(s); })(); diff --git a/app/main_test.go b/app/main_test.go index f8004be5..e80018ff 100644 --- a/app/main_test.go +++ b/app/main_test.go @@ -84,7 +84,8 @@ func TestApplicationFailed(t *testing.T) { func TestApplicationShutdown(t *testing.T) { app, ctx := prepApp(t, 18090, 500*time.Millisecond) st := time.Now() - app.Run(ctx) + err := app.Run(ctx) + assert.Nil(t, err) assert.True(t, time.Since(st).Seconds() < 1, "should take about 500msec") app.Wait() } @@ -95,7 +96,8 @@ func TestApplicationMainSignal(t *testing.T) { go func() { time.Sleep(100 * time.Millisecond) - syscall.Kill(syscall.Getpid(), syscall.SIGTERM) + err := syscall.Kill(syscall.Getpid(), syscall.SIGTERM) + require.Nil(t, err) }() st := time.Now() main() diff --git a/app/migrator/backup_test.go b/app/migrator/backup_test.go index 55cbc231..781e95f4 100644 --- a/app/migrator/backup_test.go +++ b/app/migrator/backup_test.go @@ -76,6 +76,6 @@ func TestBackup_Do(t *testing.T) { type mockExporter struct{} func (mock *mockExporter) Export(w io.Writer, siteID string) (int, error) { - w.Write([]byte("some export blah blah 1234567890")) - return 1000, nil + _, err := w.Write([]byte("some export blah blah 1234567890")) + return 1000, err } diff --git a/app/rest/api/rest_test.go b/app/rest/api/rest_test.go index 3281eb61..2143090e 100644 --- a/app/rest/api/rest_test.go +++ b/app/rest/api/rest_test.go @@ -73,7 +73,8 @@ func prep(t *testing.T) (srv *Rest, ts *httptest.Server) { } srv.ScoreThresholds.Low, srv.ScoreThresholds.Critical = -5, -10 - ioutil.WriteFile(testHTML, []byte("some html"), 0700) + err = ioutil.WriteFile(testHTML, []byte("some html"), 0700) + assert.Nil(t, err) ts = httptest.NewServer(srv.routes()) return srv, ts } diff --git a/app/rest/auth/jwt_test.go b/app/rest/auth/jwt_test.go index 3c6ed0d7..817c6b33 100644 --- a/app/rest/auth/jwt_test.go +++ b/app/rest/auth/jwt_test.go @@ -152,7 +152,7 @@ func TestJWT_SetAndGetWithCookies(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/valid" { - j.Set(w, claims, true) + assert.Nil(t, j.Set(w, claims, true)) w.WriteHeader(200) } })) @@ -193,7 +193,7 @@ func TestJWT_SetAndGetWithXsrfMismatch(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/valid" { - j.Set(w, claims, true) + assert.Nil(t, j.Set(w, claims, true)) w.WriteHeader(200) } })) @@ -230,7 +230,7 @@ func TestJWT_SetAndGetWithCookiesExpired(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/expired" { - j.Set(w, claims, true) + assert.Nil(t, j.Set(w, claims, true)) w.WriteHeader(200) } })) diff --git a/app/rest/cache/memory_test.go b/app/rest/cache/memory_test.go index b4b5f99b..90396b5c 100644 --- a/app/rest/cache/memory_test.go +++ b/app/rest/cache/memory_test.go @@ -226,11 +226,11 @@ func TestMemoryCache_Scopes(t *testing.T) { lc.Flush("s1") assert.Equal(t, 1, lc.(*memoryCache).bytesCache.Len()) - lc.Get(Key("key2", "s2"), func() ([]byte, error) { + _, err = lc.Get(Key("key2", "s2"), func() ([]byte, error) { assert.Fail(t, "should stay") return nil, nil }) - + assert.Nil(t, err) res, err = lc.Get(Key("key", "s1", "s2"), func() ([]byte, error) { return []byte("value-upd"), nil }) diff --git a/app/rest/proxy/avatar_store_test.go b/app/rest/proxy/avatar_store_test.go index 2a6304b6..3d1f39e4 100644 --- a/app/rest/proxy/avatar_store_test.go +++ b/app/rest/proxy/avatar_store_test.go @@ -55,7 +55,8 @@ func TestAvatarStore_Get(t *testing.T) { p := NewFSAvatarStore("/tmp/avatars.test", 300) os.MkdirAll("/tmp/avatars.test/30", 0700) defer os.RemoveAll("/tmp/avatars.test") - ioutil.WriteFile("/tmp/avatars.test/30/b3daa77b4c04a9551b8781d03191fe098f325e67.image", []byte("something"), 0666) + err := ioutil.WriteFile("/tmp/avatars.test/30/b3daa77b4c04a9551b8781d03191fe098f325e67.image", []byte("something"), 0666) + assert.Nil(t, err) r, size, err := p.Get("b3daa77b4c04a9551b8781d03191fe098f325e67.image") assert.Nil(t, err) assert.Equal(t, 9, size)