diff --git a/db/Makefile b/db/Makefile index 10edc3eb..8b2ba670 100644 --- a/db/Makefile +++ b/db/Makefile @@ -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) diff --git a/db/pkg/cli/search/search_test.go b/db/pkg/cli/search/search_test.go index 376bc219..56b1a2d4 100644 --- a/db/pkg/cli/search/search_test.go +++ b/db/pkg/cli/search/search_test.go @@ -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, @@ -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) { diff --git a/db/pkg/db/db.go b/db/pkg/db/db.go index 46fda544..bdb151c1 100644 --- a/db/pkg/db/db.go +++ b/db/pkg/db/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.21.0 +// sqlc v1.25.0 package db diff --git a/db/pkg/db/models.go b/db/pkg/db/models.go index 2ff3d515..8f767aa2 100644 --- a/db/pkg/db/models.go +++ b/db/pkg/db/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.21.0 +// sqlc v1.25.0 package db diff --git a/db/pkg/db/note_test.go b/db/pkg/db/note_test.go index c5ea3252..b8294e2c 100644 --- a/db/pkg/db/note_test.go +++ b/db/pkg/db/note_test.go @@ -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) { @@ -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 @@ -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) { diff --git a/db/pkg/db/queries.sql.go b/db/pkg/db/queries.sql.go index 28e28986..ef2cac5b 100644 --- a/db/pkg/db/queries.sql.go +++ b/db/pkg/db/queries.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.21.0 +// sqlc v1.25.0 // source: queries.sql package db diff --git a/db/pkg/db/source_test.go b/db/pkg/db/source_test.go index aaf3ad1b..da1f71db 100644 --- a/db/pkg/db/source_test.go +++ b/db/pkg/db/source_test.go @@ -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()) }) } } @@ -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) { @@ -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) { @@ -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) { @@ -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) }) } } diff --git a/db/pkg/db/term_test.go b/db/pkg/db/term_test.go index 4407b4c1..fc1454f6 100644 --- a/db/pkg/db/term_test.go +++ b/db/pkg/db/term_test.go @@ -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) { @@ -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) }) } } @@ -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) { diff --git a/db/pkg/db/testdb/models_test.go b/db/pkg/db/testdb/models_test.go index bb487f0a..deae6833 100644 --- a/db/pkg/db/testdb/models_test.go +++ b/db/pkg/db/testdb/models_test.go @@ -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) }) } } diff --git a/db/pkg/seedkrdict/seed_test.go b/db/pkg/seedkrdict/seed_test.go index 89451403..f68f5b01 100644 --- a/db/pkg/seedkrdict/seed_test.go +++ b/db/pkg/seedkrdict/seed_test.go @@ -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() @@ -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)) }) } @@ -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) { @@ -55,7 +57,7 @@ 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) { @@ -63,9 +65,9 @@ func TestUnmarshallRscXML(t *testing.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) { @@ -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{} @@ -89,7 +91,7 @@ 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) { @@ -97,7 +99,7 @@ func TestLexicalEntry_Term(t *testing.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{} @@ -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) { diff --git a/pkg/anki/anki_test.go b/pkg/anki/anki_test.go index 0e0ac586..5283c921 100644 --- a/pkg/anki/anki_test.go +++ b/pkg/anki/anki_test.go @@ -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) { diff --git a/pkg/api/api_test.go b/pkg/api/api_test.go index a028e5ad..e7c40e26 100644 --- a/pkg/api/api_test.go +++ b/pkg/api/api_test.go @@ -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{} @@ -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 } @@ -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) diff --git a/pkg/api/parts_test.go b/pkg/api/parts_test.go index dd5d5485..e8db37ac 100644 --- a/pkg/api/parts_test.go +++ b/pkg/api/parts_test.go @@ -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") @@ -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) }) @@ -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) }) diff --git a/pkg/dictionary/koreanbasic/koreanbasic_test.go b/pkg/dictionary/koreanbasic/koreanbasic_test.go index 76fd4290..c26ce56a 100644 --- a/pkg/dictionary/koreanbasic/koreanbasic_test.go +++ b/pkg/dictionary/koreanbasic/koreanbasic_test.go @@ -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) }) } } diff --git a/pkg/dictionary/krdict/krdict_test.go b/pkg/dictionary/krdict/krdict_test.go index 94caa6b2..9e1812a4 100644 --- a/pkg/dictionary/krdict/krdict_test.go +++ b/pkg/dictionary/krdict/krdict_test.go @@ -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) } } diff --git a/pkg/extractor/extractor_test.go b/pkg/extractor/extractor_test.go index 02001979..0010cc73 100644 --- a/pkg/extractor/extractor_test.go +++ b/pkg/extractor/extractor_test.go @@ -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" diff --git a/pkg/extractor/instagram/instagram_test.go b/pkg/extractor/instagram/instagram_test.go index 6561b6df..ef8a63e5 100644 --- a/pkg/extractor/instagram/instagram_test.go +++ b/pkg/extractor/instagram/instagram_test.go @@ -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) { @@ -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) }) } } @@ -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) } diff --git a/pkg/storage/db_storage_test.go b/pkg/storage/db_storage_test.go index 171230e1..39527ef0 100644 --- a/pkg/storage/db_storage_test.go +++ b/pkg/storage/db_storage_test.go @@ -58,7 +58,7 @@ func TestDBStorage_SignPut(t *testing.T) { req, err := newTestDBStorage().SignPut("test_table", "test_column", ".txt") require.NoError(err) - fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, req)) + fixture.CompareReadOrUpdateJSON(t, testName, req) } var basicConfig = SignPutConfig{ @@ -119,7 +119,7 @@ func TestDBStorage_SignPutTree(t *testing.T) { } require.NoError(err) require.NotEmpty(resp.ID) - fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+".json"), fixture.JSON(t, resp)) + fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), resp) }) } } @@ -180,8 +180,8 @@ func TestDBStorage_PutTree(t *testing.T) { return } require.NoError(err) - fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+".json"), fixture.JSON(t, keyTree)) - fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+"_storeMap.json"), fixture.JSON(t, api.storeMap)) + fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), keyTree) + fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name+"_storeMap"), api.storeMap) }) } } @@ -249,7 +249,7 @@ func TestDBStorage_KeyTree(t *testing.T) { err := newTestDBStorage().KeyTree("sources", "parts", testUUID, &prePartList) require.NoError(err) - fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, prePartList)) + fixture.CompareReadOrUpdateJSON(t, testName, prePartList) err = newTestDBStorage().SignGetTree("sources", "parts", "some_bad_id", nil) require.Error(err) @@ -294,7 +294,7 @@ func TestDBStorage_SignGetTree(t *testing.T) { return } require.NoError(err) - fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+".json"), fixture.JSON(t, prePartList)) + fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), prePartList) }) } } @@ -313,7 +313,7 @@ func TestDBStorage_SignGetTreeFromKeyTree(t *testing.T) { err := newTestDBStorage().SignGetTreeFromKeyTree(media, &signedTree) require.NoError(err) - fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, signedTree)) + fixture.CompareReadOrUpdateJSON(t, testName, signedTree) err = newTestDBStorage().SignGetTreeFromKeyTree(media, signedTree) require.Equal(fmt.Errorf("signedTree, storage.SourcePartMediaResponse, is not a pointer"), err) @@ -329,7 +329,7 @@ func TestDBStorage_KeyTreeFromSignGetTree(t *testing.T) { err := newTestDBStorage().KeyTreeFromSignGetTree(signedTree, &media) require.NoError(err) - fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, media)) + fixture.CompareReadOrUpdateJSON(t, testName, media) err = newTestDBStorage().KeyTreeFromSignGetTree(signedTree, media) require.Equal(fmt.Errorf("keyTree, storage.SourcePartMedia, is not a pointer"), err) diff --git a/pkg/storage/tree_test.go b/pkg/storage/tree_test.go index 3108d3c0..410951c1 100644 --- a/pkg/storage/tree_test.go +++ b/pkg/storage/tree_test.go @@ -112,7 +112,7 @@ func TestTreeFromKeys(t *testing.T) { return } require.NoError(err) - fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+".json"), fixture.JSON(t, tree)) + fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), tree) }) } } @@ -131,7 +131,7 @@ func TestUnmarshallTree(t *testing.T) { return path.Join("testPrefix", key), nil }) require.NoError(err) - fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, obj)) + fixture.CompareReadOrUpdateJSON(t, testName, obj) } func TestMapTree(t *testing.T) { @@ -144,7 +144,7 @@ func TestMapTree(t *testing.T) { tree, err := mapTree(basicTree, keySuffix) require.NoError(err) - fixture.CompareReadOrUpdate(t, testName+".json", fixture.JSON(t, tree)) + fixture.CompareReadOrUpdateJSON(t, testName, tree) basicTree = nil tree, err = mapTree(basicTree, keySuffix) diff --git a/pkg/text/text_test.go b/pkg/text/text_test.go index 7777c72b..8e7d1ec4 100644 --- a/pkg/text/text_test.go +++ b/pkg/text/text_test.go @@ -56,7 +56,7 @@ func TestParser_Texts(t *testing.T) { } require.NoError(err) - fixture.CompareReadOrUpdate(t, testNamePath+tc.name+".json", fixture.JSON(t, texts)) + fixture.CompareReadOrUpdateJSON(t, testNamePath+tc.name, texts) }) } } diff --git a/pkg/util/httptyped/httptyped_test.go b/pkg/util/httptyped/httptyped_test.go index 188a96b6..95e8f372 100644 --- a/pkg/util/httptyped/httptyped_test.go +++ b/pkg/util/httptyped/httptyped_test.go @@ -144,7 +144,7 @@ func TestStructureMap(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.name, func(t *testing.T) { - fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+".json"), fixture.JSON(t, StructureMap(reflect.TypeOf(tc.str)))) + fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), StructureMap(reflect.TypeOf(tc.str))) }) } } @@ -185,7 +185,7 @@ func TestPrepareModel(t *testing.T) { return } require.NoError(err) - fixture.CompareReadOrUpdate(t, path.Join(testName, tc.name+".json"), fixture.JSON(t, tc.model)) + fixture.CompareReadOrUpdateJSON(t, path.Join(testName, tc.name), tc.model) }) } } diff --git a/pkg/util/jhttp/reqtx/reqtx_test.go b/pkg/util/jhttp/reqtx/reqtx_test.go index 1b3ad460..32ba847a 100644 --- a/pkg/util/jhttp/reqtx/reqtx_test.go +++ b/pkg/util/jhttp/reqtx/reqtx_test.go @@ -133,7 +133,7 @@ func TestIntegrator_ResponseWrap(t *testing.T) { } req = integrator.SetTxModeContext(req, tc.mode) - model, httpErr := integrator.ResponseWrap(func(r *http.Request, tx Tx) (any, *jhttp.HTTPError) { + model, httpErr := integrator.ResponseWrap(func(_ *http.Request, _ Tx) (any, *jhttp.HTTPError) { return nil, tc.reqErr })(req) diff --git a/pkg/util/test/fixture/fixture.go b/pkg/util/test/fixture/fixture.go index 9970777f..f55af4d5 100644 --- a/pkg/util/test/fixture/fixture.go +++ b/pkg/util/test/fixture/fixture.go @@ -89,6 +89,11 @@ func CompareReadOrUpdate(t *testing.T, fixturePath string, resultBytes []byte) { require.Equal(string(expected), strings.TrimSpace(string(resultBytes))) } +// CompareReadOrUpdateJSON calls CompareReadOrUpdate, but adds .json to the fixturePath and calls JSON on the resultBytes +func CompareReadOrUpdateJSON(t *testing.T, fixturePath string, obj any) { + CompareReadOrUpdate(t, fixturePath+".json", JSON(t, obj)) +} + // CompareRead calls Read and compares the result against it func CompareRead(t *testing.T, fixturePath string, resultBytes []byte) { require := require.New(t)