cuducos/minha-receita

Testes de download na branch dev

andidevel opened this issue · 1 comments

Ao tentar fazer o build do container na branch dev, os testes falham:

--- FAIL: TestGetURLs (0.41s)
    download_test.go:221: "http://200.152.38.155/CNPJ/K3241.K03200Y4.D10911.SOCIOCSV.zip" appears 1 in the first array, but 0 in the second array
    download_test.go:221: "http://200.152.38.155/CNPJ/K3241.K03200Y7.D10911.SOCIOCSV.zip" appears 1 in the first array, but 0 in the second array
    download_test.go:221: "http://200.152.38.155/CNPJ/K3241.K03200Y7.D10710.ESTABELE.zip" appears 0 in the first array, but 1 in the second array
    download_test.go:221: "http://200.152.38.155/CNPJ/K3241.K03200Y4.D10710.ESTABELE.zip" appears 0 in the first array, but 1 in the second array
    download_test.go:221: "http://200.152.38.155/CNPJ/K3241.K03200Y5.D10710.SOCIOCSV.zip" appears 0 in the first array, but 1 in the second array
    download_test.go:221: "http://200.152.38.155/CNPJ/K3241.K03200Y2.D10710.SOCIOCSV.zip" appears 0 in the first array, but 1 in the second array
    download_test.go:221: "http://200.152.38.155/CNPJ/K3241.K03200Y0.D10710.SOCIOCSV.zip" appears 0 in the first array, but 1 in the second array

(... truncated ...)

--- FAIL: TestGetFiles (0.26s)
    download_test.go:98: Unexpected URL in getFiles result: http://200.152.38.155/CNPJ/K3241.K03200Y0.D10911.EMPRECSV.zip
    download_test.go:98: Unexpected URL in getFiles result: http://200.152.38.155/CNPJ/K3241.K03200Y1.D10911.EMPRECSV.zip
    download_test.go:98: Unexpected URL in getFiles result: http://200.152.38.155/CNPJ/K3241.K03200Y2.D10911.EMPRECSV.zip
    download_test.go:98: Unexpected URL in getFiles result: http://200.152.38.155/CNPJ/K3241.K03200Y3.D10911.EMPRECSV.zip
    download_test.go:98: Unexpected URL in getFiles result: http://200.152.38.155/CNPJ/K3241.K03200Y4.D10911.EMPRECSV.zip
    download_test.go:98: Unexpected URL in getFiles result: http://200.152.38.155/CNPJ/K3241.K03200Y5.D10911.EMPRECSV.zip
    download_test.go:98: Unexpected URL in getFiles result: http://200.152.38.155/CNPJ/K3241.K03200Y6.D10911.EMPRECSV.zip
    download_test.go:98: Unexpected URL in getFiles result: http://200.152.38.155/CNPJ/K3241.K03200Y7.D10911.EMPRECSV.zip

(... truncated ...)

Downloading 100% |█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| (428/428 kB, 11.476 MB/s)
FAIL
exit status 1
FAIL    github.com/cuducos/minha-receita/download       0.705s

Aparentemente o cliente http de httptest.Server, ao receber uma URL "válida", está fazendo uma conexão com os servidores oficiais ao invés de "baixar" o HTML de teste em "testdata/dados-publicos-cnpj.html". Alterando a função TestGetURLs():

//got, err := getURLs(ts.Client(), federalRevenue)
got, err := getURLs(ts.Client(), ts.URL)

Os testes em "TestGetURLs" passam, mas os testes em "TestGetFiles" falham, porque internamente, a função getFiles() utiliza a constante federalRevenue, que é a URL do site oficial.

Os testes em "TestGetURLs" passam, mas os testes em "TestGetFiles" falham, porque internamente, a função getFiles() utiliza a constante federalRevenue, que é a URL do site oficial.

Barbeiragem feia minha. PRs arrumando isso são bem-vindos, bom para #hacktoberfest : )