diff --git a/backend/.golangci.yml b/backend/.golangci.yml
index 119d8dc7d7..f8c0c7af89 100644
--- a/backend/.golangci.yml
+++ b/backend/.golangci.yml
@@ -1,5 +1,4 @@
run:
- tests: false
output:
format: tab
skip-dirs:
@@ -62,6 +61,10 @@ issues:
- text: "should have a package comment, unless it's in another file for this package"
linters:
- golint
+ - path: _test\.go
+ linters:
+ - gosec
+ - dupl
exclude-use-default: false
service:
diff --git a/backend/_example/memory_store/accessor/admin_test.go b/backend/_example/memory_store/accessor/admin_test.go
index d55b255b30..3aedd6290b 100644
--- a/backend/_example/memory_store/accessor/admin_test.go
+++ b/backend/_example/memory_store/accessor/admin_test.go
@@ -47,9 +47,11 @@ func TestMemAdmin_Get(t *testing.T) {
admins, err = ms.Admins("no-site-in-db")
assert.EqualError(t, err, "site no-site-in-db not found")
+ assert.Empty(t, admins)
email, err = ms.Email("no-site-in-db")
assert.EqualError(t, err, "site no-site-in-db not found")
+ assert.Empty(t, email)
enabled, err := ms.Enabled("site1")
assert.NoError(t, err)
@@ -61,6 +63,7 @@ func TestMemAdmin_Get(t *testing.T) {
enabled, err = ms.Enabled("no-site-in-db")
assert.EqualError(t, err, "site no-site-in-db not found")
+ assert.False(t, enabled)
err = ms.OnEvent("site1", admin.EvCreate)
assert.NoError(t, err)
diff --git a/backend/_example/memory_store/accessor/data_test.go b/backend/_example/memory_store/accessor/data_test.go
index 9fc8471843..fa24036dda 100644
--- a/backend/_example/memory_store/accessor/data_test.go
+++ b/backend/_example/memory_store/accessor/data_test.go
@@ -425,6 +425,7 @@ func TestMemData_FlagReadOnlyPost(t *testing.T) {
Update: engine.FlagTrue}
val, err = b.Flag(req)
assert.NoError(t, err)
+ assert.True(t, val)
req = engine.FlagRequest{Locator: store.Locator{SiteID: "radio-t", URL: "url-1"}, Flag: engine.ReadOnly}
val, err = b.Flag(req)
assert.NoError(t, err)
@@ -546,9 +547,9 @@ func TestMemData_FlagListBlocked(t *testing.T) {
assert.NoError(t, err)
blockedList := toBlocked(vv)
- var blockedIds []string
- for _, x := range blockedList {
- blockedIds = append(blockedIds, x.ID)
+ var blockedIds = make([]string, len(blockedList))
+ for i, x := range blockedList {
+ blockedIds[i] = x.ID
}
require.Equal(t, 2, len(blockedList), b.metaUsers)
assert.ElementsMatch(t, []string{"user1", "user2"}, blockedIds)
diff --git a/backend/_example/memory_store/server/admin_test.go b/backend/_example/memory_store/server/admin_test.go
index 4719f42524..380fa00cdc 100644
--- a/backend/_example/memory_store/server/admin_test.go
+++ b/backend/_example/memory_store/server/admin_test.go
@@ -19,7 +19,7 @@ import (
)
func TestRPC_admKeyHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -30,7 +30,7 @@ func TestRPC_admKeyHndl(t *testing.T) {
}
func TestRPC_admAdminsHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -44,7 +44,7 @@ func TestRPC_admAdminsHndl(t *testing.T) {
}
func TestRPC_admEmailHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -58,7 +58,7 @@ func TestRPC_admEmailHndl(t *testing.T) {
}
func TestRPC_admEnabledHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -76,7 +76,7 @@ func TestRPC_admEnabledHndl(t *testing.T) {
}
func TestRPC_admEventHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
diff --git a/backend/_example/memory_store/server/data_test.go b/backend/_example/memory_store/server/data_test.go
index c4deb5cb56..baefa27bd7 100644
--- a/backend/_example/memory_store/server/data_test.go
+++ b/backend/_example/memory_store/server/data_test.go
@@ -21,7 +21,7 @@ import (
)
func TestRPC_createHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -33,7 +33,7 @@ func TestRPC_createHndl(t *testing.T) {
}
func TestRPC_findHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -56,7 +56,7 @@ func TestRPC_findHndl(t *testing.T) {
}
func TestRPC_getHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -80,7 +80,7 @@ func TestRPC_getHndl(t *testing.T) {
}
func TestRPC_updateHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -108,7 +108,7 @@ func TestRPC_updateHndl(t *testing.T) {
}
func TestRPC_countHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -130,7 +130,7 @@ func TestRPC_countHndl(t *testing.T) {
}
func TestRPC_infoHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -151,7 +151,7 @@ func TestRPC_infoHndl(t *testing.T) {
}
func TestRPC_flagHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -186,7 +186,7 @@ func TestRPC_flagHndl(t *testing.T) {
}
func TestRPC_listFlagsHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -220,7 +220,7 @@ func TestRPC_listFlagsHndl(t *testing.T) {
}
func TestRPC_userDetailHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -273,7 +273,7 @@ func TestRPC_userDetailHndl(t *testing.T) {
}
func TestRPC_deleteHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -296,7 +296,7 @@ func TestRPC_deleteHndl(t *testing.T) {
}
func TestRPC_closeHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
diff --git a/backend/_example/memory_store/server/image_test.go b/backend/_example/memory_store/server/image_test.go
index 18b94dcb70..d264f3ece0 100644
--- a/backend/_example/memory_store/server/image_test.go
+++ b/backend/_example/memory_store/server/image_test.go
@@ -51,7 +51,7 @@ func gopherPNGBytes() []byte {
}
func TestRPC_imgLoadHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -78,7 +78,7 @@ func TestRPC_imgLoadHndl(t *testing.T) {
assert.Equal(t, gopherPNGBytes(), img)
// cleanup
- err = ri.Cleanup(nil, time.Second)
+ err = ri.Cleanup(context.TODO(), time.Second)
assert.NoError(t, err)
// load after cleanup
@@ -89,7 +89,7 @@ func TestRPC_imgLoadHndl(t *testing.T) {
}
func TestRPC_imgCommitHndlFail(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
@@ -99,7 +99,7 @@ func TestRPC_imgCommitHndlFail(t *testing.T) {
}
func TestRPC_imgCleanupHndl(t *testing.T) {
- _, port, teardown := prepTestStore(t)
+ port, teardown := prepTestStore(t)
defer teardown()
api := fmt.Sprintf("http://localhost:%d/test", port)
diff --git a/backend/_example/memory_store/server/rpc_test.go b/backend/_example/memory_store/server/rpc_test.go
index 5ea06cf7cd..d8cb9ca29d 100644
--- a/backend/_example/memory_store/server/rpc_test.go
+++ b/backend/_example/memory_store/server/rpc_test.go
@@ -43,11 +43,11 @@ func waitForHTTPServerStart(port int) {
}
}
-func prepTestStore(t *testing.T) (s *RPC, port int, teardown func()) {
+func prepTestStore(t *testing.T) (port int, teardown func()) {
mg := accessor.NewMemData()
adm := accessor.NewMemAdminStore("secret")
img := accessor.NewMemImageStore()
- s = NewRPC(mg, adm, img, &jrpc.Server{API: "/test", Logger: jrpc.NoOpLogger})
+ s := NewRPC(mg, adm, img, &jrpc.Server{API: "/test", Logger: jrpc.NoOpLogger})
admRec := accessor.AdminRec{
SiteID: "test-site",
@@ -68,7 +68,7 @@ func prepTestStore(t *testing.T) (s *RPC, port int, teardown func()) {
waitForHTTPServerStart(port)
- return s, port, func() {
+ return port, func() {
require.NoError(t, s.Shutdown())
}
}
diff --git a/backend/app/cmd/cleanup_test.go b/backend/app/cmd/cleanup_test.go
index b95e1f9953..5335c8d0f7 100644
--- a/backend/app/cmd/cleanup_test.go
+++ b/backend/app/cmd/cleanup_test.go
@@ -46,6 +46,7 @@ func TestCleanup_IsSpam(t *testing.T) {
}
for n, tt := range tbl {
+ tt := tt
checkName := fmt.Sprintf("check-%d-%s", n, tt.name)
t.Run(checkName, func(t *testing.T) {
c := store.Comment{ID: checkName, Text: tt.text, Score: tt.score}
diff --git a/backend/app/main_test.go b/backend/app/main_test.go
index 46c7569fe5..0b45517965 100644
--- a/backend/app/main_test.go
+++ b/backend/app/main_test.go
@@ -30,8 +30,8 @@ func Test_Main(t *testing.T) {
done := make(chan struct{})
go func() {
<-done
- err := syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
- require.NoError(t, err)
+ e := syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
+ require.NoError(t, e)
}()
finished := make(chan struct{})
diff --git a/backend/app/migrator/wordpress_test.go b/backend/app/migrator/wordpress_test.go
index cea8bf191b..e3cf497c04 100644
--- a/backend/app/migrator/wordpress_test.go
+++ b/backend/app/migrator/wordpress_test.go
@@ -190,7 +190,7 @@ var xmlTestWP = `
-
+
diff --git a/backend/app/notify/email_test.go b/backend/app/notify/email_test.go
index 0690e760d7..127cd16fc8 100644
--- a/backend/app/notify/email_test.go
+++ b/backend/app/notify/email_test.go
@@ -61,6 +61,7 @@ func TestEmailNew(t *testing.T) {
},
}
for _, d := range testSet {
+ d := d
t.Run(d.name, func(t *testing.T) {
email, err := NewEmail(d.emailParams, d.smtpParams)
@@ -152,6 +153,7 @@ func TestEmailSendClientError(t *testing.T) {
err: "can't make email writer: failed to send"},
}
for _, d := range testSet {
+ d := d
t.Run(d.name, func(t *testing.T) {
e := Email{smtp: d.smtp}
if d.err != "" {
@@ -182,8 +184,8 @@ func TestEmail_Send(t *testing.T) {
email, err := NewEmail(EmailParams{From: "from@example.org"}, SMTPParams{})
assert.NoError(t, err)
assert.NotNil(t, email)
- fakeSmtp := fakeTestSMTP{}
- email.smtp = &fakeSmtp
+ fakeSMTP := fakeTestSMTP{}
+ email.smtp = &fakeSMTP
email.TokenGenFn = TokenGenFn
email.UnsubscribeURL = "https://remark42.com/api/v1/email/unsubscribe"
req := Request{
@@ -192,9 +194,9 @@ func TestEmail_Send(t *testing.T) {
Email: "test@example.org",
}
assert.NoError(t, email.Send(context.TODO(), req))
- assert.Equal(t, "from@example.org", fakeSmtp.readMail())
- assert.Equal(t, 1, fakeSmtp.readQuitCount())
- assert.Equal(t, "test@example.org", fakeSmtp.readRcpt())
+ assert.Equal(t, "from@example.org", fakeSMTP.readMail())
+ assert.Equal(t, 1, fakeSMTP.readQuitCount())
+ assert.Equal(t, "test@example.org", fakeSMTP.readRcpt())
// test buildMessageFromRequest separately for message text
res, err := email.buildMessageFromRequest(req, req.ForAdmin)
assert.NoError(t, err)
@@ -230,8 +232,8 @@ func TestEmail_SendVerification(t *testing.T) {
email, err := NewEmail(EmailParams{From: "from@example.org"}, SMTPParams{})
assert.NoError(t, err)
assert.NotNil(t, email)
- fakeSmtp := fakeTestSMTP{}
- email.smtp = &fakeSmtp
+ fakeSMTP := fakeTestSMTP{}
+ email.smtp = &fakeSMTP
email.TokenGenFn = TokenGenFn
req := Request{
Email: "test@example.org",
@@ -242,9 +244,9 @@ func TestEmail_SendVerification(t *testing.T) {
},
}
assert.NoError(t, email.Send(context.TODO(), req))
- assert.Equal(t, "from@example.org", fakeSmtp.readMail())
- assert.Equal(t, 1, fakeSmtp.readQuitCount())
- assert.Equal(t, "test@example.org", fakeSmtp.readRcpt())
+ assert.Equal(t, "from@example.org", fakeSMTP.readMail())
+ assert.Equal(t, 1, fakeSMTP.readQuitCount())
+ assert.Equal(t, "test@example.org", fakeSMTP.readRcpt())
// test buildMessageFromRequest separately for message text
res, err := email.buildVerificationMessage(req.Verification.User, req.Email, req.Verification.Token, req.Verification.SiteID)
assert.NoError(t, err)
diff --git a/backend/app/rest/api/migrator_test.go b/backend/app/rest/api/migrator_test.go
index 196f764afd..e39f07ab17 100644
--- a/backend/app/rest/api/migrator_test.go
+++ b/backend/app/rest/api/migrator_test.go
@@ -458,7 +458,7 @@ var xmlTestWP = `
-
+
diff --git a/backend/app/rest/api/rest_private_test.go b/backend/app/rest/api/rest_private_test.go
index 05d43f6086..39d4518949 100644
--- a/backend/app/rest/api/rest_private_test.go
+++ b/backend/app/rest/api/rest_private_test.go
@@ -548,6 +548,7 @@ func TestRest_Email(t *testing.T) {
}
client := http.Client{}
for _, x := range testData {
+ x := x
t.Run(x.description, func(t *testing.T) {
req, err := http.NewRequest(x.method, ts.URL+x.url, nil)
require.NoError(t, err)
diff --git a/backend/app/rest/api/rest_test.go b/backend/app/rest/api/rest_test.go
index d5219a01c2..cf1f2c1d98 100644
--- a/backend/app/rest/api/rest_test.go
+++ b/backend/app/rest/api/rest_test.go
@@ -49,12 +49,12 @@ func TestRest_FileServer(t *testing.T) {
ts, _, teardown := startupT(t)
defer teardown()
- testHtmlName := "test-remark.html"
- testHTMLFile := os.TempDir() + "/" + testHtmlName
+ testHTMLName := "test-remark.html"
+ testHTMLFile := os.TempDir() + "/" + testHTMLName
err := ioutil.WriteFile(testHTMLFile, []byte("some html"), 0700)
assert.NoError(t, err)
- body, code := get(t, ts.URL+"/web/"+testHtmlName)
+ body, code := get(t, ts.URL+"/web/"+testHTMLName)
assert.Equal(t, 200, code)
assert.Equal(t, "some html", body)
_ = os.Remove(testHTMLFile)
@@ -233,6 +233,7 @@ func Test_URLKey(t *testing.T) {
}
for i, tt := range tbl {
+ tt := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
r, err := http.NewRequest("GET", tt.url, nil)
require.NoError(t, err)
@@ -258,6 +259,7 @@ func Test_URLKeyWithUser(t *testing.T) {
}
for i, tt := range tbl {
+ tt := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
r, err := http.NewRequest("GET", tt.url, nil)
require.NoError(t, err)
@@ -285,6 +287,7 @@ func TestRest_parseError(t *testing.T) {
}
for n, tt := range tbl {
+ tt := tt
t.Run(strconv.Itoa(n), func(t *testing.T) {
res := parseError(tt.err, rest.ErrInternal)
assert.Equal(t, tt.res, res)
@@ -308,6 +311,7 @@ func TestRest_cacheControl(t *testing.T) {
}
for i, tt := range tbl {
+ tt := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
req := httptest.NewRequest("GET", tt.url, nil)
w := httptest.NewRecorder()
diff --git a/backend/app/rest/proxy/image_test.go b/backend/app/rest/proxy/image_test.go
index fd0458e05e..6eb84f0661 100644
--- a/backend/app/rest/proxy/image_test.go
+++ b/backend/app/rest/proxy/image_test.go
@@ -80,6 +80,7 @@ func TestImage_Extract(t *testing.T) {
img := Image{HTTP2HTTPS: true}
for i, tt := range tbl {
+ tt := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
res, err := img.extract(tt.inp, func(src string) bool { return strings.HasPrefix(src, "http://") })
assert.NoError(t, err)
diff --git a/backend/app/store/comment_test.go b/backend/app/store/comment_test.go
index 709eb13d21..29495d2cb3 100644
--- a/backend/app/store/comment_test.go
+++ b/backend/app/store/comment_test.go
@@ -148,6 +148,7 @@ func TestComment_Snippet(t *testing.T) {
}
for i, tt := range tbl {
+ tt := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
c := Comment{Text: tt.inp}
out := c.Snippet(tt.limit)
diff --git a/backend/app/store/formatter_test.go b/backend/app/store/formatter_test.go
index ef282303b2..7bc5182e26 100644
--- a/backend/app/store/formatter_test.go
+++ b/backend/app/store/formatter_test.go
@@ -33,6 +33,7 @@ func TestFormatter_FormatText(t *testing.T) {
}
f := NewCommentFormatter(mockConverter{})
for _, tt := range tbl {
+ tt := tt
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.out, f.FormatText(tt.in))
})
diff --git a/backend/app/store/image/fs_store_test.go b/backend/app/store/image/fs_store_test.go
index 8171b80847..17668cce14 100644
--- a/backend/app/store/image/fs_store_test.go
+++ b/backend/app/store/image/fs_store_test.go
@@ -153,6 +153,7 @@ func TestFsStore_location(t *testing.T) {
{0, "user/12345", "/tmp/user/12345"},
}
for n, tt := range tbl {
+ tt := tt
t.Run(strconv.Itoa(n), func(t *testing.T) {
svc := FileSystem{Location: "/tmp", Partitions: tt.partitions}
assert.Equal(t, tt.res, svc.location("/tmp", tt.id))
diff --git a/backend/app/store/image/image_test.go b/backend/app/store/image/image_test.go
index 42157b15b7..228ac45ef9 100644
--- a/backend/app/store/image/image_test.go
+++ b/backend/app/store/image/image_test.go
@@ -198,6 +198,7 @@ func TestGetProportionalSizes(t *testing.T) {
}
for i, tt := range tbl {
+ tt := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
resW, resH := getProportionalSizes(tt.inpW, tt.inpH, tt.limitW, tt.limitH)
assert.Equal(t, tt.resW, resW, "width")
diff --git a/backend/app/store/service/service_test.go b/backend/app/store/service/service_test.go
index 66e5959bd1..e662b041e2 100644
--- a/backend/app/store/service/service_test.go
+++ b/backend/app/store/service/service_test.go
@@ -572,6 +572,7 @@ func TestService_Controversy(t *testing.T) {
b := DataStore{}
for i, tt := range tbl {
+ tt := tt
t.Run(fmt.Sprintf("check-%d-%d:%d", i, tt.ups, tt.downs), func(t *testing.T) {
assert.InDelta(t, tt.res, b.controversy(tt.ups, tt.downs), 0.01)
})
diff --git a/backend/app/store/service/title_test.go b/backend/app/store/service/title_test.go
index 75f7fc480d..640f80ccef 100644
--- a/backend/app/store/service/title_test.go
+++ b/backend/app/store/service/title_test.go
@@ -31,6 +31,7 @@ func TestTitle_GetTitle(t *testing.T) {
ex := NewTitleExtractor(http.Client{Timeout: 5 * time.Second})
for i, tt := range tbl {
+ tt := tt
t.Run(fmt.Sprintf("check-%d", i), func(t *testing.T) {
title, ok := ex.getTitle(strings.NewReader(tt.page))
assert.Equal(t, tt.ok, ok)