diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-27 21:12:05 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-27 21:12:05 -0300 |
| commit | 97b49ae7081b989274b313532ff17c71694097a9 (patch) | |
| tree | 6595e0d5a39d04971a71e886bc3f8cc589741f5d /internal/bot/format_test.go | |
| parent | 83ce95cf10fd9e9d581362453c558239d37ae06e (diff) | |
| download | telegram-0.2.1.tar.gz | |
cep.is/go v0.2.0 exposes the municipality as Error.Faixa, which is what
internal/lookup existed to work around: v0.1.0 discarded the 404 body, so
the bot re-issued the request just to read the block back.
The extra GET on the 404 path is gone, and with it the second timeout,
the body size cap and the "is it still a 404?" check that guarded it.
The replies are byte for byte what they were -- the formatting tests did
not change a single assertion, only the type they build.
Diffstat (limited to 'internal/bot/format_test.go')
| -rw-r--r-- | internal/bot/format_test.go | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/internal/bot/format_test.go b/internal/bot/format_test.go index 513db36..8e10b3e 100644 --- a/internal/bot/format_test.go +++ b/internal/bot/format_test.go @@ -7,8 +7,6 @@ import ( "testing" cepis "cep.is/go" - - "cep.is/telegrambot/internal/lookup" ) func decodeAddress(t *testing.T, body string) *cepis.Address { @@ -118,11 +116,14 @@ func TestErrorMessagesAreDistinct(t *testing.T) { } } -func notFound(faixa *lookup.Faixa) error { - return &lookup.NotFoundError{Faixa: faixa, Err: cepis.ErrCEPNotFound} +// notFound builds the error the client library returns for a CEP absent from +// the DNE, with the municipality the API named on the 404 — or without one, +// for a CEP in a band no municipality owns. +func notFound(faixa *cepis.Faixa) error { + return &cepis.Error{Kind: cepis.ErrCEPNotFound, Faixa: faixa} } -var areal = &lookup.Faixa{ +var areal = &cepis.Faixa{ Localidade: "Areal", UF: "RJ", Estado: "Rio de Janeiro", Regiao: "Sudeste", IBGE: "3300225", CEPIni: "25845001", CEPFim: "25849899", CEPs: 118, } @@ -168,7 +169,7 @@ func TestNotFoundWithoutFaixaIsUnchanged(t *testing.T) { for name, err := range map[string]error{ "plain sentinel": cepis.ErrCEPNotFound, "no faixa": notFound(nil), - "empty faixa": notFound(&lookup.Faixa{}), + "empty faixa": notFound(&cepis.Faixa{}), } { if got := ErrorMessage(err); got != want { t.Fatalf("%s:\n got %q\nwant %q", name, got, want) @@ -177,7 +178,7 @@ func TestNotFoundWithoutFaixaIsUnchanged(t *testing.T) { } func TestNotFoundEscapesTheMunicipality(t *testing.T) { - text := ErrorMessage(notFound(&lookup.Faixa{ + text := ErrorMessage(notFound(&cepis.Faixa{ Localidade: "Santa <b>Rita</b> & Cia", UF: "M&G", CEPIni: "25845001", CEPFim: "25849899", CEPs: 2, })) @@ -194,32 +195,32 @@ func TestNotFoundEscapesTheMunicipality(t *testing.T) { // take the sentence down with it. func TestNotFoundDegradesFieldByField(t *testing.T) { cases := map[string]struct { - faixa *lookup.Faixa + faixa *cepis.Faixa present []string absent []string }{ "no count": { - faixa: &lookup.Faixa{Localidade: "Areal", UF: "RJ", CEPIni: "25845001", CEPFim: "25849899"}, + faixa: &cepis.Faixa{Localidade: "Areal", UF: "RJ", CEPIni: "25845001", CEPFim: "25849899"}, present: []string{"Areal/RJ", "25845-001", "25849-899", "esparsa"}, absent: []string{"CEPs,"}, }, "no range": { - faixa: &lookup.Faixa{Localidade: "Areal", UF: "RJ", CEPs: 118}, + faixa: &cepis.Faixa{Localidade: "Areal", UF: "RJ", CEPs: 118}, present: []string{"Areal/RJ", "118 CEPs"}, absent: []string{"<code>", "esparsa"}, }, "only the name": { - faixa: &lookup.Faixa{Localidade: "Areal"}, + faixa: &cepis.Faixa{Localidade: "Areal"}, present: []string{"cairia em <b>Areal</b>."}, absent: []string{"<code>", "esparsa", "Areal/"}, }, "single CEP": { - faixa: &lookup.Faixa{Localidade: "Vila", UF: "SP", CEPIni: "12345678", CEPFim: "12345678", CEPs: 1}, + faixa: &cepis.Faixa{Localidade: "Vila", UF: "SP", CEPIni: "12345678", CEPFim: "12345678", CEPs: 1}, present: []string{"1 CEP."}, absent: []string{"12345-678"}, }, "unusable range": { - faixa: &lookup.Faixa{Localidade: "Areal", UF: "RJ", CEPIni: "abc", CEPFim: "2584", CEPs: 118}, + faixa: &cepis.Faixa{Localidade: "Areal", UF: "RJ", CEPIni: "abc", CEPFim: "2584", CEPs: 118}, present: []string{"118 CEPs."}, absent: []string{"abc", "2584"}, }, @@ -251,7 +252,7 @@ func TestInlineErrorDescriptionNamesTheMunicipality(t *testing.T) { } // Titles and descriptions are plain text: escaping them would show the // entities to the user. - got := inlineErrorDescription(notFound(&lookup.Faixa{Localidade: "Santa & Cia", UF: "SP"})) + got := inlineErrorDescription(notFound(&cepis.Faixa{Localidade: "Santa & Cia", UF: "SP"})) if !strings.Contains(got, "Santa & Cia/SP") { t.Fatalf("description = %q", got) } |