From c31310216147f2c3ffa6eb8a0eb66bf90d18fc71 Mon Sep 17 00:00:00 2001
From: Code by Ben
Date: Tue, 10 Sep 2024 10:45:11 +1000
Subject: [PATCH] lint corrections.
---
handler/app/app_test.go | 2 +-
handler/app/context.go | 3 +-
handler/app/internal/filerecord/filerecord.go | 2 +-
.../app/internal/fileslice/fileslice_test.go | 2 +-
handler/app/internal/simple/simple.go | 44 ++---
handler/app/internal/simple/simple_test.go | 33 ++--
handler/app/milestone.go | 2 +-
handler/app/remote/remote.go | 3 +-
handler/app/template_test.go | 3 +-
handler/form/form_test.go | 6 +-
handler/html3/html3_test.go | 16 +-
handler/htmx/htmx_test.go | 8 +-
handler/pouet/pouet_test.go | 2 +-
handler/readme/readme_test.go | 9 +-
init/.golangci.yaml | 1 +
internal/config/config_test.go | 36 ++--
internal/config/fixarc/fixarc.go | 3 +-
model/artifacts.go | 2 +
model/fix/fix.go | 8 +-
model/fix/fix_test.go | 5 +-
model/model_test.go | 170 +++++++++---------
model/one.go | 2 +-
model/summary.go | 7 +-
23 files changed, 187 insertions(+), 182 deletions(-)
diff --git a/handler/app/app_test.go b/handler/app/app_test.go
index 8be369b3..1f462905 100644
--- a/handler/app/app_test.go
+++ b/handler/app/app_test.go
@@ -14,7 +14,7 @@ import (
)
//go:embed*
-var emptyFS embed.FS
+var emptyFS embed.FS //nolint:gochecknoglobals
const (
exampleURL = "https://example.com"
diff --git a/handler/app/context.go b/handler/app/context.go
index 06f38565..b9d25f5b 100644
--- a/handler/app/context.go
+++ b/handler/app/context.go
@@ -192,8 +192,7 @@ func artifacts(c echo.Context, db *sql.DB, uri string, page int) error {
BaseURL: "/files/" + uri,
RangeStep: steps(lastPage),
}
- err = c.Render(http.StatusOK, name, data)
- if err != nil {
+ if err = c.Render(http.StatusOK, name, data); err != nil {
return InternalErr(c, errs, err)
}
return nil
diff --git a/handler/app/internal/filerecord/filerecord.go b/handler/app/internal/filerecord/filerecord.go
index dc3cbd57..1399331a 100644
--- a/handler/app/internal/filerecord/filerecord.go
+++ b/handler/app/internal/filerecord/filerecord.go
@@ -445,7 +445,7 @@ func (e *entry) parseMusicID3(path string) bool {
}
// ListContent returns a list of the files contained in the archive file.
-func ListContent(art *models.File, src string) template.HTML {
+func ListContent(art *models.File, src string) template.HTML { //nolint:funlen
if art == nil {
return "error, no artifact"
}
diff --git a/handler/app/internal/fileslice/fileslice_test.go b/handler/app/internal/fileslice/fileslice_test.go
index f69b4853..1d4dfffd 100644
--- a/handler/app/internal/fileslice/fileslice_test.go
+++ b/handler/app/internal/fileslice/fileslice_test.go
@@ -62,7 +62,7 @@ func TestRecords(t *testing.T) {
require.Error(t, err)
assert.Nil(t, x)
- var proof = fileslice.URI(45).String()
+ proof := fileslice.URI(45).String()
x, err = fileslice.Records(context.TODO(), nil, proof, 1, 1)
require.Error(t, err)
assert.Nil(t, x)
diff --git a/handler/app/internal/simple/simple.go b/handler/app/internal/simple/simple.go
index 5a802505..8ee77775 100644
--- a/handler/app/internal/simple/simple.go
+++ b/handler/app/internal/simple/simple.go
@@ -6,6 +6,9 @@ import (
"fmt"
"html/template"
"image"
+ _ "image/gif" // gif format decoder
+ _ "image/jpeg" // jpeg format decoder
+ _ "image/png" // png format decoder
"net/http"
"net/url"
"os"
@@ -15,12 +18,6 @@ import (
"strings"
"time"
- _ "image/gif" // gif format decoder
- _ "image/jpeg" // jpeg format decoder
- _ "image/png" // png format decoder
-
- _ "golang.org/x/image/webp" // webp format decoder
-
"github.com/Defacto2/helper"
"github.com/Defacto2/magicnumber"
"github.com/Defacto2/releaser"
@@ -30,6 +27,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/h2non/filetype"
"github.com/volatiletech/null/v8"
+ _ "golang.org/x/image/webp" // webp format decoder
)
var (
@@ -205,8 +203,10 @@ func ImageXY(name string) [2]string {
if err != nil {
return [2]string{err.Error(), ""}
}
- return [2]string{humanize.Comma(st.Size()),
- fmt.Sprintf("%dx%d", config.Width, config.Height)}
+ return [2]string{
+ humanize.Comma(st.Size()),
+ fmt.Sprintf("%dx%d", config.Width, config.Height),
+ }
}
// LinkID creates a URL to link to the record.
@@ -462,7 +462,6 @@ func ReleaserPair(a, b any) [2]string {
// Supported formats are webp, png, jpg and avif.
func Screenshot(unid, desc, previewDir string) template.HTML {
const separator = "/"
- class := "rounded mx-auto d-block img-fluid"
alt := strings.ToLower(desc) + " screenshot"
srcW := strings.Join([]string{config.StaticOriginal(), unid + webp}, separator)
@@ -485,40 +484,43 @@ func Screenshot(unid, desc, previewDir string) template.HTML {
elm := template.HTML("")
switch {
case sizeA > 0:
- elm += template.HTML(fmt.Sprintf(" ", srcA, hashA, hashA))
+ elm += template.HTML(fmt.Sprintf(" ", srcA, hashA, hashA))
case sizeW > 0:
- elm += template.HTML(fmt.Sprintf(" ", srcW, hashW, hashW))
+ elm += template.HTML(fmt.Sprintf(" ", srcW, hashW, hashW))
}
// the element is used to provide multiple sources for an image.
// if no element is provided, the element won't be rendered by the browser.
useSmallerJpg := sizeJ > 0 && sizeJ < sizeP
switch {
case useSmallerJpg:
- elm += img(srcJ, alt, class, hashJ)
+ elm += img(srcJ, alt, hashJ)
case sizeP > 0:
- elm += img(srcP, alt, class, hashP)
+ elm += img(srcP, alt, hashP)
default:
- elm += img(srcJ, alt, class, hashJ)
+ elm += img(srcJ, alt, hashJ)
}
return elm + " "
}
switch {
case sizeA > 0:
- return img(srcA, alt, class, hashA)
+ return img(srcA, alt, hashA)
case sizeW > 0:
- return img(srcW, alt, class, hashW)
+ return img(srcW, alt, hashW)
case sizeJ > 0:
- return img(srcJ, alt, class, hashJ)
+ return img(srcJ, alt, hashJ)
case sizeP > 0:
- return img(srcP, alt, class, hashP)
+ return img(srcP, alt, hashP)
}
return ""
}
// img returns a HTML image tag.
-func img(src, alt, class, integrity string) template.HTML {
- return template.HTML(fmt.Sprintf(" ",
- src, integrity, alt, class, integrity))
+func img(src, alt, integrity string) template.HTML {
+ return template.HTML(fmt.Sprintf(" ",
+ src, integrity, alt, integrity))
}
// StatHumanize returns the last modified date, size in bytes and size formatted
diff --git a/handler/app/internal/simple/simple_test.go b/handler/app/internal/simple/simple_test.go
index e823d9bb..59f5eb15 100644
--- a/handler/app/internal/simple/simple_test.go
+++ b/handler/app/internal/simple/simple_test.go
@@ -1,7 +1,6 @@
package simple_test
import (
- "fmt"
"os"
"path/filepath"
"runtime"
@@ -15,7 +14,8 @@ import (
"github.com/volatiletech/null/v8"
)
-func testImage(t *testing.T) string {
+func imagefiler(t *testing.T) string {
+ t.Helper()
_, file, _, ok := runtime.Caller(0)
require.True(t, ok)
return filepath.Join(filepath.Dir(file), "testdata", "TEST.png")
@@ -158,9 +158,9 @@ func TestImageSampleStat(t *testing.T) {
t.Parallel()
x := simple.ImageSampleStat("", "")
assert.False(t, x)
- name := filepath.Base(testImage(t))
+ name := filepath.Base(imagefiler(t))
name = strings.TrimSuffix(name, filepath.Ext(name))
- dir := filepath.Dir(testImage(t))
+ dir := filepath.Dir(imagefiler(t))
x = simple.ImageSampleStat(name, dir)
assert.True(t, x)
}
@@ -169,11 +169,10 @@ func TestImageXY(t *testing.T) {
t.Parallel()
s := simple.ImageXY("")
assert.Contains(t, s, "stat : no such file or directory")
- img := testImage(t)
+ img := imagefiler(t)
s = simple.ImageXY(img)
- fmt.Println(img)
- assert.Equal(t, s[0], "4,163")
- assert.Equal(t, s[1], "500x500")
+ assert.Equal(t, "4,163", s[0])
+ assert.Equal(t, "500x500", s[1])
}
func TestLinkID(t *testing.T) {
@@ -185,7 +184,7 @@ func TestLinkID(t *testing.T) {
require.Error(t, err)
assert.Empty(t, s)
s, err = simple.LinkID(1, "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "/9b1c6", s)
}
@@ -216,7 +215,7 @@ func TestMagicAsTitle(t *testing.T) {
t.Parallel()
s := simple.MagicAsTitle("")
assert.Equal(t, "file not found", s)
- s = simple.MagicAsTitle(testImage(t))
+ s = simple.MagicAsTitle(imagefiler(t))
assert.Contains(t, s, "Portable Network Graphics")
}
@@ -224,7 +223,7 @@ func TestMIME(t *testing.T) {
t.Parallel()
s := simple.MIME("")
assert.Equal(t, "file not found", s)
- s = simple.MIME(testImage(t))
+ s = simple.MIME(imagefiler(t))
assert.Equal(t, "image/png", s)
}
@@ -254,7 +253,7 @@ func TestScreenshot(t *testing.T) {
t.Parallel()
s := simple.Screenshot("", "", "")
assert.Empty(t, s)
- dir := filepath.Dir(testImage(t))
+ dir := filepath.Dir(imagefiler(t))
s = simple.Screenshot("TEST", "test", dir)
assert.Contains(t, s, `alt="test screenshot"`)
assert.Contains(t, s, ` ", s)
- name := filepath.Base(testImage(t))
+ name := filepath.Base(imagefiler(t))
name = strings.TrimSuffix(name, filepath.Ext(name))
- dir := filepath.Dir(testImage(t))
+ dir := filepath.Dir(imagefiler(t))
s = simple.Thumb(name, "a description", dir, false)
assert.Contains(t, s, `alt="a description thumbnail"`)
}
@@ -289,9 +288,9 @@ func TestThumbSample(t *testing.T) {
const missing = "No thumbnail"
x := simple.ThumbSample("", "")
assert.Contains(t, x, missing)
- name := filepath.Base(testImage(t))
+ name := filepath.Base(imagefiler(t))
name = strings.TrimSuffix(name, filepath.Ext(name))
- dir := filepath.Dir(testImage(t))
+ dir := filepath.Dir(imagefiler(t))
x = simple.ThumbSample(name, dir)
assert.Contains(t, x, "sha384-SK3qCpS11QMhNxUUnyeUeWWXBMPORDgLTI")
}
diff --git a/handler/app/milestone.go b/handler/app/milestone.go
index 7522f695..6bae8869 100644
--- a/handler/app/milestone.go
+++ b/handler/app/milestone.go
@@ -746,7 +746,7 @@ func Collection() Milestones {
"It is more believable that the kids formed these Berlin-based cracking groups at the earliest, in Christmas/New Years 1983-84, " +
"after the Commodore 64 dropped massively in price and became readily available.
" +
// citations
- "The controversal citations [8] " +
+ "The controversial citations [8] " +
ul0 +
"The first intro was a picture of the Berlin Bear from the city flag and was released by BCS in 1982 . " +
"It was a kind of co-production by several people... [9] " +
diff --git a/handler/app/remote/remote.go b/handler/app/remote/remote.go
index 9cbbe074..20208215 100644
--- a/handler/app/remote/remote.go
+++ b/handler/app/remote/remote.go
@@ -272,7 +272,8 @@ func (got *PouetLink) Download(c echo.Context, db *sql.DB, downloadDir string) e
if downloadURL == "" {
return nil
}
- df, err := GetFile(downloadURL, 10*time.Second)
+ const timeout = 10 * time.Second
+ df, err := GetFile(downloadURL, timeout)
if err != nil {
return fmt.Errorf("could not get file, %s: %w", downloadURL, err)
}
diff --git a/handler/app/template_test.go b/handler/app/template_test.go
index 7d29d93e..e1cb0a61 100644
--- a/handler/app/template_test.go
+++ b/handler/app/template_test.go
@@ -5,13 +5,14 @@ import (
"github.com/Defacto2/server/handler/app"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestTemplTemplates(t *testing.T) {
t.Parallel()
tpl := app.Templ{}
x, err := tpl.Templates(nil)
- assert.Error(t, err)
+ require.Error(t, err)
assert.Nil(t, x)
}
diff --git a/handler/form/form_test.go b/handler/form/form_test.go
index 453ef6fe..997eb560 100644
--- a/handler/form/form_test.go
+++ b/handler/form/form_test.go
@@ -7,17 +7,17 @@ import (
"github.com/Defacto2/server/handler/form"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestHumanizeCount(t *testing.T) {
t.Parallel()
html, err := form.HumanizeCount(nil, "", "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, html, `0 existing artifacts`)
htm := form.HumanizeCountStr(nil, "", "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, htm, `0 existing artifacts`)
-
}
func TestSanitizeFilename(t *testing.T) {
diff --git a/handler/html3/html3_test.go b/handler/html3/html3_test.go
index 7c3f5088..f5574d7a 100644
--- a/handler/html3/html3_test.go
+++ b/handler/html3/html3_test.go
@@ -122,25 +122,25 @@ func TestQuery(t *testing.T) {
assert.Empty(t, b)
assert.Empty(t, c)
assert.Empty(t, fs)
- assert.Error(t, err)
+ require.Error(t, err)
a, b, c, fs, err = html3.Query(newContext(), nil, html3.Everything, -1)
assert.Empty(t, a)
assert.Empty(t, b)
assert.Empty(t, c)
assert.Empty(t, fs)
- assert.Error(t, err)
+ require.Error(t, err)
_, _, _, _, err = html3.Query(newContext(), nil, html3.BySection, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, _, _, _, err = html3.Query(newContext(), nil, html3.ByPlatform, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, _, _, _, err = html3.Query(newContext(), nil, html3.ByGroup, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, _, _, _, err = html3.Query(newContext(), nil, html3.AsArt, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, _, _, _, err = html3.Query(newContext(), nil, html3.AsDocument, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, _, _, _, err = html3.Query(newContext(), nil, html3.AsSoftware, -1)
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestListInfo(t *testing.T) {
diff --git a/handler/htmx/htmx_test.go b/handler/htmx/htmx_test.go
index 97418a85..14e43ff2 100644
--- a/handler/htmx/htmx_test.go
+++ b/handler/htmx/htmx_test.go
@@ -111,21 +111,21 @@ func TestDataList(t *testing.T) {
func TestTemplates(t *testing.T) {
t.Parallel()
x := htmx.Templates(embed.FS{})
- assert.Equal(t, 3, len(x))
+ assert.Len(t, x, 3)
}
func TestTemplateFuncMap(t *testing.T) {
t.Parallel()
x := htmx.TemplateFuncMap()
- assert.Greater(t, len(x), 0)
+ assert.Empty(t, len(x))
}
func TestSuggestion(t *testing.T) {
t.Parallel()
s := htmx.Suggestion("", "", "")
- assert.Equal(t, s, "suggestion type error: string")
+ assert.Equal(t, "suggestion type error: string", s)
s = htmx.Suggestion("a group", "grp", 10)
- assert.Equal(t, s, "a group, grp (10 items)")
+ assert.Equal(t, "a group, grp (10 items)", s)
}
func TestHumanizeCount(t *testing.T) {
diff --git a/handler/pouet/pouet_test.go b/handler/pouet/pouet_test.go
index 9ce308a5..2d3b3053 100644
--- a/handler/pouet/pouet_test.go
+++ b/handler/pouet/pouet_test.go
@@ -124,5 +124,5 @@ func TestPlatformType(t *testing.T) {
pp := pouet.Production{}
a, b := pp.PlatformType()
assert.Equal(t, tags.Tag(-1), a)
- assert.Equal(t, tags.Tag(tags.Intro), b)
+ assert.Equal(t, tags.Intro, b)
}
diff --git a/handler/readme/readme_test.go b/handler/readme/readme_test.go
index 71cfc419..12b53802 100644
--- a/handler/readme/readme_test.go
+++ b/handler/readme/readme_test.go
@@ -6,6 +6,7 @@ import (
"github.com/Defacto2/server/handler/readme"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestSortContent(t *testing.T) {
@@ -126,7 +127,7 @@ func TestReadmeSuggest(t *testing.T) {
func TestRead(t *testing.T) {
t.Parallel()
p, err := readme.Read(nil, "", "")
- assert.Error(t, err)
+ require.Error(t, err)
assert.Empty(t, p)
}
@@ -140,14 +141,14 @@ func TestRemoveCtrls(t *testing.T) {
func TestIncompatibleANSI(t *testing.T) {
t.Parallel()
b, err := readme.IncompatibleANSI(nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, b)
r := strings.NewReader("a\x1b[1;cabc")
b, err = readme.IncompatibleANSI(r)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, b)
r = strings.NewReader("a\x1b[Acabc")
b, err = readme.IncompatibleANSI(r)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, b)
}
diff --git a/init/.golangci.yaml b/init/.golangci.yaml
index 2e406c2c..ef2fbfaa 100644
--- a/init/.golangci.yaml
+++ b/init/.golangci.yaml
@@ -33,6 +33,7 @@ issues:
- lll
- path: _test\.go$
linters: # Tests are allowed to be longer and don't need error wrapping.
+ - dogsled
- dupl
- funlen
- gocyclo
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 9dc83f9b..361f9f0d 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -27,7 +27,7 @@ func TestConfig(t *testing.T) {
cs := c.String()
assert.Contains(t, cs, "configuration")
cs, err := c.Addresses()
- assert.Error(t, err)
+ require.Error(t, err)
assert.Empty(t, cs)
}
@@ -35,11 +35,11 @@ func TestChecks(t *testing.T) {
t.Parallel()
c := config.Config{}
err := c.Checks(nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = c.LogStore()
- assert.NoError(t, err)
+ require.NoError(t, err)
err = c.SetupLogDir(nil)
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestCheckDir(t *testing.T) {
@@ -76,10 +76,10 @@ func TestSanityTmpDir(t *testing.T) {
func TestValidate(t *testing.T) {
t.Parallel()
err := config.Validate(0)
- assert.NoError(t, err)
+ require.NoError(t, err)
const tooLarge = 10000000
err = config.Validate(tooLarge)
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestError(t *testing.T) {
@@ -87,39 +87,39 @@ func TestError(t *testing.T) {
i, s, err := config.StringErr(nil)
assert.Zero(t, i)
assert.Empty(t, s)
- assert.NoError(t, err)
+ require.NoError(t, err)
i, s, err = config.StringErr(assert.AnError)
assert.Equal(t, 500, i)
assert.Contains(t, s, "internal server error")
- assert.NoError(t, err)
+ require.NoError(t, err)
}
func TestRepair(t *testing.T) {
t.Parallel()
c := config.Config{}
err := c.Archives(context.TODO(), nil)
- assert.Error(t, err)
+ require.Error(t, err)
r := config.Zip
assert.Equal(t, "zip", r.String())
err = c.Assets(context.TODO(), nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = c.MagicNumbers(context.TODO(), nil, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = c.Previews(context.TODO(), nil, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = config.ImageDirs(nil, c)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = config.DownloadDir(nil, "", "", "")
- assert.Error(t, err)
+ require.Error(t, err)
err = config.RenameDownload("", "")
- assert.Error(t, err)
+ require.Error(t, err)
err = config.RemoveDir("", "", "")
- assert.Error(t, err)
+ require.Error(t, err)
err = config.RemoveDownload("", "", "", "")
- assert.Error(t, err)
+ require.Error(t, err)
err = config.RemoveImage("", "", "")
- assert.Error(t, err)
+ require.Error(t, err)
}
diff --git a/internal/config/fixarc/fixarc.go b/internal/config/fixarc/fixarc.go
index 6c36f792..e2c0b469 100644
--- a/internal/config/fixarc/fixarc.go
+++ b/internal/config/fixarc/fixarc.go
@@ -2,6 +2,7 @@ package fixarc
import (
"context"
+ "errors"
"fmt"
"io/fs"
"os"
@@ -19,7 +20,7 @@ import (
"github.com/volatiletech/sqlboiler/v4/queries/qm"
)
-var ErrNoExecutor = fmt.Errorf("no context executor")
+var ErrNoExecutor = errors.New("no context executor")
// Check returns the UUID of the zipped file if it requires re-archiving because it uses a
// legacy compression method that is not supported by Go or JS libraries.
diff --git a/model/artifacts.go b/model/artifacts.go
index 01923b82..9fdc465e 100644
--- a/model/artifacts.go
+++ b/model/artifacts.go
@@ -5,6 +5,7 @@ package model
import (
"context"
"fmt"
+ "io"
"github.com/Defacto2/server/internal/postgres"
"github.com/Defacto2/server/internal/postgres/models"
@@ -155,6 +156,7 @@ func (f *Artifacts) ByForApproval(ctx context.Context, exec boil.ContextExecutor
return nil, ErrDB
}
if err := f.byForApproval(ctx, exec); err != nil {
+ fmt.Fprint(io.Discard, err)
return nil, nil
}
const clause = "id DESC"
diff --git a/model/fix/fix.go b/model/fix/fix.go
index 5cbf5186..43a47c96 100644
--- a/model/fix/fix.go
+++ b/model/fix/fix.go
@@ -285,10 +285,10 @@ func releasers(ctx context.Context, exec boil.ContextExecutor) error {
}
}
}
- return moreReleases(ctx, exec)
+ return moreReleases(exec)
}
-func moreReleases(ctx context.Context, exec boil.ContextExecutor) error {
+func moreReleases(exec boil.ContextExecutor) error {
_, err := queries.Raw(postgres.SetUpper("group_brand_for")).Exec(exec)
if err != nil {
return fmt.Errorf("set upper group_brand_for: %w", err)
@@ -301,7 +301,7 @@ func moreReleases(ctx context.Context, exec boil.ContextExecutor) error {
if err != nil {
return fmt.Errorf("set filesize 0: %w", err)
}
- if err := Magics(ctx, exec); err != nil {
+ if err := Magics(exec); err != nil {
return fmt.Errorf("magics: %w", err)
}
return nil
@@ -310,7 +310,7 @@ func moreReleases(ctx context.Context, exec boil.ContextExecutor) error {
// Magics will set invalid file_magic_type to NULL.
// Invalid file_magic_type values are those that start with "ERROR: " or contain a "/"
// such as a mimetype.
-func Magics(ctx context.Context, exec boil.ContextExecutor) error {
+func Magics(exec boil.ContextExecutor) error {
_, err := queries.Raw(`UPDATE files SET file_magic_type = NULL ` +
`WHERE file_magic_type ILIKE ANY(ARRAY['ERROR: %', '%/%']);`).Exec(exec)
if err != nil {
diff --git a/model/fix/fix_test.go b/model/fix/fix_test.go
index 7533b5f0..b95f7f1a 100644
--- a/model/fix/fix_test.go
+++ b/model/fix/fix_test.go
@@ -1,7 +1,6 @@
package fix_test
import (
- "context"
"testing"
"github.com/Defacto2/server/internal/postgres"
@@ -12,12 +11,10 @@ import (
func TestMagics(t *testing.T) {
// when testing, go may cache the test result after the first run
t.Parallel()
- ctx := context.TODO()
-
db, err := postgres.Open()
require.NoError(t, err)
defer db.Close()
- err = fix.Magics(ctx, db)
+ err = fix.Magics(db)
require.NoError(t, err)
}
diff --git a/model/model_test.go b/model/model_test.go
index 2c933964..2ea38c29 100644
--- a/model/model_test.go
+++ b/model/model_test.go
@@ -237,7 +237,7 @@ func TestValidString(t *testing.T) {
s = "hello world"
r = model.ValidString(s)
assert.True(t, r.Valid)
- assert.Equal(t, s, r.String)
+ assert.Equal(t, r.String, s)
const emoji = "😃"
r = model.ValidString(emoji)
@@ -304,79 +304,79 @@ func TestArtifacts(t *testing.T) {
ctx := context.TODO()
a := model.Artifacts{}
err := a.Public(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
x, err := a.ByKey(ctx, nil, -1, -1)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.ByNewest(ctx, nil, -1, -1)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.ByUpdated(ctx, nil, -1, -1)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.ByHidden(ctx, nil, -1, -1)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.ByForApproval(ctx, nil, -1, -1)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.ByMagicErr(ctx, nil, true)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.ByTextPlatform(ctx, nil)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.ByUnwanted(ctx, nil, -1, -1)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.Description(ctx, nil, nil)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.Filename(ctx, nil, nil)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
x, err = a.ID(ctx, nil, nil)
assert.Nil(t, x)
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestCount(t *testing.T) {
t.Parallel()
ctx := context.TODO()
_, _, _, err := model.Counts(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.CategoryCount(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.CategoryByteSum(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.ClassificationCount(ctx, nil, "", "")
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.PlatformCount(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.PlatformByteSum(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.ReleaserByteSum(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestDelete(t *testing.T) {
t.Parallel()
ctx := context.TODO()
err := model.DeleteOne(ctx, nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestExists(t *testing.T) {
t.Parallel()
ctx := context.TODO()
_, err := model.DemozooExists(ctx, nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.PouetExists(ctx, nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.SHA384Exists(ctx, nil, nil)
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.HashExists(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestFilter(t *testing.T) {
@@ -385,8 +385,8 @@ func TestFilter(t *testing.T) {
// Define a slice of structs that implement Stat and List methods
models := []interface {
- Stat(context.Context, boil.ContextExecutor) error
- List(context.Context, boil.ContextExecutor, int, int) (models.FileSlice, error)
+ Stat(ctx context.Context, exec boil.ContextExecutor) error
+ List(ctx context.Context, exec boil.ContextExecutor, x int, y int) (models.FileSlice, error)
}{
&model.Advert{},
&model.Announcement{},
@@ -442,9 +442,9 @@ func TestFilter(t *testing.T) {
}
for _, m := range models {
err := m.Stat(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
_, err = m.List(ctx, nil, -1, -1)
- assert.Error(t, err)
+ require.Error(t, err)
}
}
@@ -452,40 +452,40 @@ func TestInsert(t *testing.T) {
t.Parallel()
ctx := context.TODO()
_, _, err := model.InsertDemozoo(ctx, nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, _, err = model.InsertPouet(ctx, nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, _, err = model.InsertUpload(ctx, nil, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestModel(t *testing.T) {
t.Parallel()
_, err := model.JsDosBinary(nil)
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.JsDosConfig(nil)
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.JsDosCommand(nil)
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestOne(t *testing.T) {
t.Parallel()
ctx := context.TODO()
_, err := model.One(ctx, nil, false, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.OneEditByKey(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.OneByUUID(ctx, nil, false, "")
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.OneFile(ctx, nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, err = model.OneFileByKey(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
_, _, err = model.OneDemozoo(ctx, nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
_, _, err = model.OnePouet(ctx, nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestReleaser(t *testing.T) {
@@ -493,24 +493,24 @@ func TestReleaser(t *testing.T) {
ctx := context.TODO()
r := model.ReleaserNames{}
err := r.Distinct(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = r.DistinctGroups(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
rls := model.Releasers{}
_, err = rls.Where(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
err = rls.Limit(ctx, nil, 0, -1, -1)
- assert.Error(t, err)
+ require.Error(t, err)
err = rls.Similar(ctx, nil, 0)
- assert.Error(t, err)
+ require.Error(t, err)
err = rls.SimilarMagazine(ctx, nil, 0)
- assert.Error(t, err)
+ require.Error(t, err)
err = rls.FTP(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = rls.MagazineAZ(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = rls.Magazine(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
rls.Slugs()
}
@@ -519,20 +519,20 @@ func TestScener(t *testing.T) {
ctx := context.TODO()
s := model.Sceners{}
err := s.Distinct(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.Writer(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.Artist(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.Coder(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.Musician(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
x := s.Sort()
assert.Empty(t, x)
var o model.Scener
_, err = o.Where(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestSummary(t *testing.T) {
@@ -540,73 +540,73 @@ func TestSummary(t *testing.T) {
ctx := context.TODO()
s := model.Summary{}
err := s.ByDescription(ctx, nil, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.ByFilename(ctx, nil, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.ByForApproval(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.ByHidden(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.ByPublic(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.ByReleaser(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
err = s.ByUnwanted(ctx, nil)
- assert.Error(t, err)
+ require.Error(t, err)
err = s.ByMatch(ctx, nil, "")
- assert.Error(t, err)
+ require.Error(t, err)
for uri := range s.Matches() {
err = s.ByMatch(ctx, nil, uri)
- assert.Error(t, err)
+ require.Error(t, err)
}
}
func TestUpdateBoolFrom(t *testing.T) {
t.Parallel()
err := model.UpdateBoolFrom(nil, -1, -1, false)
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateEmulateRunProgram(nil, -1, "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateEmulateMachine(nil, -1, "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateEmulateCPU(nil, -1, "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateEmulateSfx(nil, -1, "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateInt64From(nil, -1, -1, "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateStringFrom(nil, -1, -1, "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateCreators(nil, -1, "", "", "", "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateLinks(nil, -1, "", "", "", "", "", -1, -1)
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateClassification(nil, -1, "", "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateDateIssued(nil, -1, "", "", "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateOffline(nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdatePlatform(nil, -1, "")
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateOnline(nil, -1)
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateReleasers(nil, -1, "")
- assert.Error(t, err)
+ require.Error(t, err)
x := null.Int16From(-1)
ctx := context.TODO()
err = model.UpdateYMD(ctx, nil, -1, x, x, x)
- assert.Error(t, err)
+ require.Error(t, err)
err = model.UpdateMagic(ctx, nil, -1, "")
- assert.Error(t, err)
+ require.Error(t, err)
fu := model.FileUpload{}
err = fu.Update(ctx, nil, 1)
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestValidate(t *testing.T) {
t.Parallel()
err := model.Validate(nil)
- assert.Error(t, err)
+ require.Error(t, err)
}
diff --git a/model/one.go b/model/one.go
index 1869c753..7ae49f99 100644
--- a/model/one.go
+++ b/model/one.go
@@ -109,7 +109,7 @@ func OneDemozoo(ctx context.Context, exec boil.ContextExecutor, id int64) (bool,
// If the record is not found then the function will return an ID of 0 but without an error.
func OnePouet(ctx context.Context, exec boil.ContextExecutor, id int64) (bool, int64, error) {
if invalidExec(exec) {
- return false, 0, fmt.Errorf("invalid context executor")
+ return false, 0, fmt.Errorf("model one pouet: %w", ErrDB)
}
f, err := models.Files(
qm.Select("id", "deletedat"),
diff --git a/model/summary.go b/model/summary.go
index d687f05a..ccb488d9 100644
--- a/model/summary.go
+++ b/model/summary.go
@@ -152,10 +152,11 @@ func (s *Summary) Update(c, b, y0, y1 int) {
s.MaxYear = sql.NullInt16{Int16: int16(y1)}
}
-type statFunc func(context.Context, boil.ContextExecutor) error
+// StatFunc is a function that updates the summary statistics.
+type StatFunc func(context.Context, boil.ContextExecutor) error
-func (s *Summary) Matches() map[string]statFunc {
- return map[string]statFunc{
+func (s *Summary) Matches() map[string]StatFunc {
+ return map[string]StatFunc{
"text-amiga": s.textAmiga,
"text-apple2": s.textApple2,
"text-atari-st": s.textAtariST,