Skip to content

Commit

Permalink
update golang-lint and sqlc
Browse files Browse the repository at this point in the history
  • Loading branch information
s12chung committed Mar 24, 2024
1 parent 9373dda commit 62e9caf
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 53 deletions.
2 changes: 1 addition & 1 deletion db/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test.fixtures: testdb
@echo; echo
UPDATE_FIXTURES=true make test | $(FIXTURE_CLEAN_OUTPUT)

SQLC_VERSION = 1.21.0
SQLC_VERSION = 1.25.0
SQLC_URL := https://github.com/kyleconroy/sqlc/releases/download/v$(SQLC_VERSION)/sqlc_$(SQLC_VERSION)_linux_amd64.tar.gz
ci.setup:
curl -sSL $(SQLC_URL) | tar zxvf - -C ../$(CI_BIN)
Expand Down
4 changes: 2 additions & 2 deletions db/pkg/cli/search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestTermsSearchToCSVRows(t *testing.T) {
require.NoError(err)
rows, err := TermsSearchToCSVRows(terms)
require.NoError(err)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, rows))
fixture.CompareReadOrUpdateJSON(t, testName, rows)

_, err = txQs.TermsSearchRaw(txQs.Ctx(), testdb.SearchTerm, testdb.SearchPOS, db.TermsSearchConfig{
PosWeight: 30,
Expand All @@ -46,7 +46,7 @@ var changedTestConfig = Config{
func TestConfigToCSVRows(t *testing.T) {
testName := "TestConfigToCSVRows"
rows := ConfigToCSVRows()
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, rows))
fixture.CompareReadOrUpdateJSON(t, testName, rows)
}

func TestGetOrDefaultConfig(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion db/pkg/db/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion db/pkg/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions db/pkg/db/note_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestNote_CreateParams(t *testing.T) {

createParams := firstNote(t, txQs).CreateParams()
test.EmptyFieldsMatch(t, createParams)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, createParams))
fixture.CompareReadOrUpdateJSON(t, testName, createParams)
}

func TestNote_Anki(t *testing.T) {
Expand All @@ -41,7 +41,7 @@ func TestNote_Anki(t *testing.T) {
ankiNote, err := firstNote(t, txQs).Anki()
require.NoError(err)
test.EmptyFieldsMatch(t, ankiNote, "usageSoundSource")
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, ankiNote))
fixture.CompareReadOrUpdateJSON(t, testName, ankiNote)

note := firstNote(t, txQs)
note.CommonLevel = -1
Expand All @@ -67,7 +67,7 @@ func TestAnkiNotes(t *testing.T) {
for _, note := range ankiNotes {
test.EmptyFieldsMatch(t, note, "usageSoundSource")
}
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, ankiNotes))
fixture.CompareReadOrUpdateJSON(t, testName, ankiNotes)
}

func TestQueries_NoteCreate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion db/pkg/db/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions db/pkg/db/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestSourcePartMedia_MarshalJSON(t *testing.T) {
if tc.prepareSerialize {
source.PrepareSerialize()
}
fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+".json"), fixture.JSON(t, source.StaticCopy()))
fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), source.StaticCopy())
})
}
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestSourceStructured_UpdateParams(t *testing.T) {
test.EmptyFieldsMatch(t, firstSource(t, txQs))
updateParams := firstSource(t, txQs).ToSourceStructured().UpdateParams()
test.EmptyFieldsMatch(t, updateParams)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, updateParams))
fixture.CompareReadOrUpdateJSON(t, testName, updateParams)
}

func TestSourceStructured_UpdatePartsParams(t *testing.T) {
Expand All @@ -118,7 +118,7 @@ func TestSourceStructured_UpdatePartsParams(t *testing.T) {
test.EmptyFieldsMatch(t, firstSource(t, txQs))
updateParams := firstSource(t, txQs).ToSourceStructured().UpdatePartsParams()
test.EmptyFieldsMatch(t, updateParams)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, updateParams))
fixture.CompareReadOrUpdateJSON(t, testName, updateParams)
}

func TestSourceStructured_CreateParams(t *testing.T) {
Expand All @@ -128,7 +128,7 @@ func TestSourceStructured_CreateParams(t *testing.T) {
test.EmptyFieldsMatch(t, firstSource(t, txQs))
createParams := firstSource(t, txQs).ToSourceStructured().CreateParams()
test.EmptyFieldsMatch(t, createParams)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, createParams))
fixture.CompareReadOrUpdateJSON(t, testName, createParams)
}

func TestSource_ToSource_ToSourceStructured(t *testing.T) {
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestTextTokenizer_TokenizedTexts(t *testing.T) {
nonSpeaker := strings.TrimPrefix(tc.name, "speaker_")
mutex.Lock()
t.Cleanup(mutex.Unlock)
fixture.CompareReadOrUpdate(t, path.Join(testName, nonSpeaker+".json"), fixture.JSON(t, tokenizedTexts))
fixture.CompareReadOrUpdateJSON(t, path.Join(testName, nonSpeaker), tokenizedTexts)
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions db/pkg/db/term_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestToDBTerm(t *testing.T) {
require.NoError(err)
test.EmptyFieldsMatch(t, dbTerm)

fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, dbTerm))
fixture.CompareReadOrUpdateJSON(t, testName, dbTerm)
}

func TestTerm_DictionaryTerm(t *testing.T) {
Expand All @@ -52,7 +52,7 @@ func TestTerm_DictionaryTerm(t *testing.T) {
require.NoError(err)
test.EmptyFieldsMatch(t, dictTerm)

fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+".json"), fixture.JSON(t, dictTerm))
fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), dictTerm)
})
}
}
Expand All @@ -68,7 +68,7 @@ func TestTerm_CreateParams(t *testing.T) {

createParams := term.CreateParams()
test.EmptyFieldsMatch(t, createParams)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, createParams))
fixture.CompareReadOrUpdateJSON(t, testName, createParams)
}

func TestQueries_TermsSearchRaw(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion db/pkg/db/testdb/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestSeedList(t *testing.T) {
require.True(ok)
resultMap[k] = s.seedCount
}
fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+".json"), fixture.JSON(t, resultMap))
fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), resultMap)
})
}
}
20 changes: 11 additions & 9 deletions db/pkg/seedkrdict/seed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/s12chung/text2anki/pkg/util/test/fixture"
)

const xmlExt = ".xml"

func TestSeed(t *testing.T) {
testName := "TestSeed"
t.Parallel()
Expand All @@ -27,7 +29,7 @@ func TestSeedFile(t *testing.T) {
t.Parallel()

testSeed(t, testName, func(tx db.Tx) error {
return SeedFile(tx, fixture.Read(t, testName+".xml"))
return SeedFile(tx, fixture.Read(t, testName+xmlExt))
})
}

Expand All @@ -45,7 +47,7 @@ func testSeed(t *testing.T, testName string, testFunc func(tx db.Tx) error) {

terms, err := txQs.TermsPopular(txQs.Ctx())
require.NoError(err)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, terms))
fixture.CompareReadOrUpdateJSON(t, testName, terms)
}

func TestUnmarshallRscPath(t *testing.T) {
Expand All @@ -55,17 +57,17 @@ func TestUnmarshallRscPath(t *testing.T) {

lexes, err := UnmarshallRscPath(fixture.JoinTestData(testName))
require.NoError(err)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, lexes))
fixture.CompareReadOrUpdateJSON(t, testName, lexes)
}

func TestUnmarshallRscXML(t *testing.T) {
require := require.New(t)
testName := "TestUnmarshallRscXML"
t.Parallel()

lex, err := UnmarshallRscXML(fixture.Read(t, testName+".xml"))
lex, err := UnmarshallRscXML(fixture.Read(t, testName+xmlExt))
require.NoError(err)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, lex))
fixture.CompareReadOrUpdateJSON(t, testName, lex)
}

func TestIsNoTranslationsFoundError(t *testing.T) {
Expand All @@ -80,7 +82,7 @@ func TestLexicalEntry_CreateParams(t *testing.T) {
testName := "TestLexicalEntry_CreateParams"
t.Parallel()

lex, err := UnmarshallRscXML(fixture.Read(t, testName+".xml"))
lex, err := UnmarshallRscXML(fixture.Read(t, testName+xmlExt))
require.NoError(err)

createParamsArray := []db.TermCreateParams{}
Expand All @@ -89,15 +91,15 @@ func TestLexicalEntry_CreateParams(t *testing.T) {
require.NoError(err)
createParamsArray = append(createParamsArray, createParams)
}
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, createParamsArray))
fixture.CompareReadOrUpdateJSON(t, testName, createParamsArray)
}

func TestLexicalEntry_Term(t *testing.T) {
require := require.New(t)
testName := "TestLexicalEntry_Term"
t.Parallel()

lex, err := UnmarshallRscXML(fixture.Read(t, testName+".xml"))
lex, err := UnmarshallRscXML(fixture.Read(t, testName+xmlExt))
require.NoError(err)

terms := []dictionary.Term{}
Expand All @@ -106,7 +108,7 @@ func TestLexicalEntry_Term(t *testing.T) {
require.NoError(err)
terms = append(terms, term)
}
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, terms))
fixture.CompareReadOrUpdateJSON(t, testName, terms)
}

func TestFindGoodExample(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/anki/anki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestNote_SetSound(t *testing.T) {

func TestNote_CSV(t *testing.T) {
testName := "TestNote_CSV"
fixture.CompareReadOrUpdate(t, testName+".json", test.JSON(t, notesFromFixture(t)[0].CSV()))
fixture.CompareReadOrUpdateJSON(t, testName, notesFromFixture(t)[0].CSV())
}

func TestNote_UsageSoundFilename(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
const testUUID = "123e4567-e89b-12d3-a456-426614174000"
const extractorType = "testy"
const sourcePartMediaImageContents = "api_test.init() image"
const jsonExt = ".json"

type UUIDTest struct{}

Expand Down Expand Up @@ -119,7 +120,7 @@ func TestHttpTypedRegistry(t *testing.T) {

fileNames := make([]string, len(httptyped.Types()))
for i, typ := range httptyped.Types() {
fileName := typ.String() + ".json"
fileName := typ.String() + jsonExt
fixture.CompareReadOrUpdate(t, path.Join(testName, fileName), fixture.JSON(t, httptyped.StructureMap(typ)))
fileNames[i] = fileName
}
Expand All @@ -143,7 +144,7 @@ func TestRoutes_Router(t *testing.T) {
require.NoError(err)
resp := test.HTTPDo(t, txPool.SetTx(t, req, txQs, txReadOnly))
resp.EqualCode(t, http.StatusOK)
fixture.CompareReadOrUpdate(t, testName+".json", test.StaticCopy(t, resp.Body.Bytes(), &db.SourceStructured{}))
fixture.CompareReadOrUpdate(t, testName+jsonExt, test.StaticCopy(t, resp.Body.Bytes(), &db.SourceStructured{}))

req, err = http.NewRequestWithContext(txQs.Ctx(), http.MethodGet, server.URL+"/healthz", nil)
require.NoError(err)
Expand Down
6 changes: 4 additions & 2 deletions pkg/api/parts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/s12chung/text2anki/pkg/util/test"
)

const txtExt = ".txt"

func TestRoutes_PartCreateMulti(t *testing.T) {
testName := "TestRoutes_PartCreateMulti"
test.CISkip(t, "can't run C environment in CI")
Expand Down Expand Up @@ -73,7 +75,7 @@ func TestRoutes_PartCreate(t *testing.T) {
txQs := testdb.TxQs(t, db.WriteOpts())
created := createdSource(t, txQs)

body := sourceCreateRequestPartFromFile(t, testName, tc.name+".txt")
body := sourceCreateRequestPartFromFile(t, testName, tc.name+txtExt)
req := sourcesServer.NewTxRequest(t, txQs, http.MethodPost, joinPath(created.ID, "parts"), bytes.NewReader(test.JSON(t, body)))
testSourceResponse(t, req, txQs, testName, tc.name, tc.expectedCode)
})
Expand Down Expand Up @@ -103,7 +105,7 @@ func TestRoutes_PartUpdate(t *testing.T) {
txQs := testdb.TxQs(t, db.WriteOpts())
created := createdSource(t, txQs)

body := sourceCreateRequestPartFromFile(t, testName, tc.name+".txt")
body := sourceCreateRequestPartFromFile(t, testName, tc.name+txtExt)
req := sourcesServer.NewTxRequest(t, txQs, http.MethodPatch, joinPath(created.ID, "parts", tc.index), bytes.NewReader(test.JSON(t, body)))
testSourceResponse(t, req, txQs, testName, tc.name, tc.expectedCode)
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/dictionary/koreanbasic/koreanbasic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestKoreanBasic_Search(t *testing.T) {

terms, err := dict.Search(context.Background(), tc.searchTerm, tc.pos)
require.NoError(err)
fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name)+".json", fixture.JSON(t, terms))
fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), terms)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dictionary/krdict/krdict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestKrDict_Search(t *testing.T) {
for _, pos := range []lang.PartOfSpeech{lang.PartOfSpeechEmpty, lang.PartOfSpeechOther} {
terms, err := dict.Search(context.Background(), "마음", pos)
require.NoError(err)
fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, terms))
fixture.CompareReadOrUpdateJSON(t, testName, terms)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/extractor/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/s12chung/text2anki/db/pkg/db"
. "github.com/s12chung/text2anki/pkg/extractor"
. "github.com/s12chung/text2anki/pkg/extractor" //nolint:revive // for testing
"github.com/s12chung/text2anki/pkg/extractor/extractortest"
"github.com/s12chung/text2anki/pkg/util/test"
"github.com/s12chung/text2anki/pkg/util/test/fixture"
Expand Down
6 changes: 3 additions & 3 deletions pkg/extractor/instagram/instagram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func init() {
args[i+1] = "2023-11-21_10-42-44_UTC_" + strconv.Itoa(suffix) + extensions[0]
}

extractToDirArgs = func(login, id string) []string { return args }
extractToDirArgs = func(_, _ string) []string { return args }
}

func TestPost_ExtractToDir(t *testing.T) {
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestPost_ExtractToDir(t *testing.T) {
for i, entry := range entries {
entryNames[i] = entry.Name()
}
fixture.CompareReadOrUpdate(t, filepath.Join(testName, tc.name+".json"), fixture.JSON(t, entryNames))
fixture.CompareReadOrUpdateJSON(t, filepath.Join(testName, tc.name), entryNames)
})
}
}
Expand All @@ -117,5 +117,5 @@ func TestPost_Info(t *testing.T) {

info, err := NewPost("https://testpostinfo.com").Info(fixture.JoinTestData(testName))
require.NoError(err)
fixture.CompareReadOrUpdate(t, filepath.Join(testName, "postInfo.json"), fixture.JSON(t, info))
fixture.CompareReadOrUpdateJSON(t, filepath.Join(testName, "postInfo"), info)
}
Loading

0 comments on commit 62e9caf

Please sign in to comment.