-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from WalterPaes/develop
Develop
- Loading branch information
Showing
5 changed files
with
137 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
|
||
# Go ViaCep | ||
|
||
##### This lib was developed for get an adress data by zipcode using [ViaCep](https://viacep.com.br/) API | ||
|
||
## Import and Usage | ||
|
||
``` | ||
go get github.com/WalterPaes/go-viacep | ||
``` | ||
|
||
### Create a New Integration | ||
```go | ||
// Parse zipcode to CEP type | ||
zipcode := cep.CEP("01001-000") | ||
|
||
// Create a new integration | ||
integration := viacep.NewIntegration(zipcode) | ||
```go | ||
viaCep, err := NewViaCEP("01001-000") | ||
``` | ||
|
||
### Get Address | ||
|
||
```go | ||
integration.GetAddress() | ||
address, err := viaCep.GetAddress() | ||
``` | ||
|
||
## :rocket: Technologies | ||
|
||
This project was developed with the following technologies: | ||
|
||
- [Go](https://golang.org/) | ||
- [GoLand](https://www.jetbrains.com/go/?gclid=EAIaIQobChMI5-ug_OvG6gIVBgiRCh0GGARZEAAYASAAEgKOSPD_BwE) | ||
- [ViaCep](https://viacep.com.br/) | ||
- [Go](https://golang.org/) | ||
- [GoLand](https://www.jetbrains.com/go/?gclid=EAIaIQobChMI5-ug_OvG6gIVBgiRCh0GGARZEAAYASAAEgKOSPD_BwE) | ||
- [ViaCep](https://viacep.com.br/) | ||
|
||
Made by [Walter Junior](https://www.linkedin.com/in/walter-paes/) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package viacep | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestViaCepIntegration(t *testing.T) { | ||
t.Run("SUCESS: Get a address by cep", func(t *testing.T) { | ||
cep := "01001-000" | ||
viaCep, err := NewViaCEP(cep) | ||
if err != nil { | ||
t.Fatal("Errors was not expected!", err.Error()) | ||
} | ||
|
||
address, err := viaCep.GetAddress() | ||
if err != nil { | ||
t.Fatal("Errors was not expected!", err.Error()) | ||
} | ||
|
||
if address.CEP != cep { | ||
t.Errorf("Was expected '%s', but got '%s'", cep, address.CEP) | ||
} | ||
|
||
expectedAddress := Address{ | ||
Logradouro: "Praça da Sé", | ||
Complemento: "lado ímpar", | ||
Bairro: "Sé", | ||
Localidade: "São Paulo", | ||
UF: "SP", | ||
} | ||
|
||
if address.Logradouro != expectedAddress.Logradouro { | ||
t.Errorf("Was expected '%s', but got '%s'", expectedAddress.Logradouro, address.Logradouro) | ||
} | ||
|
||
if address.Complemento != expectedAddress.Complemento { | ||
t.Errorf("Was expected '%s', but got '%s'", expectedAddress.Complemento, address.Complemento) | ||
} | ||
|
||
if address.Bairro != expectedAddress.Bairro { | ||
t.Errorf("Was expected '%s', but got '%s'", expectedAddress.Bairro, address.Bairro) | ||
} | ||
|
||
if address.Localidade != expectedAddress.Localidade { | ||
t.Errorf("Was expected '%s', but got '%s'", expectedAddress.Localidade, address.Localidade) | ||
} | ||
|
||
if address.UF != expectedAddress.UF { | ||
t.Errorf("Was expected '%s', but got '%s'", expectedAddress.UF, address.UF) | ||
} | ||
}) | ||
|
||
t.Run("ERROR: Not found zipcode", func(t *testing.T) { | ||
cep := "1234567" | ||
viaCep, err := NewViaCEP(cep) | ||
if err != nil { | ||
t.Fatal("Errors was not expected!", err.Error()) | ||
} | ||
|
||
_, err = viaCep.GetAddress() | ||
notFoundError := fmt.Errorf(cepNotFoundError, cep) | ||
if err.Error() != notFoundError.Error() { | ||
t.Errorf("Was expected '%s', but got '%s'", notFoundError.Error(), err.Error()) | ||
} | ||
}) | ||
|
||
t.Run("ERROR: Invalid zipcode", func(t *testing.T) { | ||
cep := "12345" | ||
_, err := NewViaCEP(cep) | ||
|
||
invalidError := fmt.Errorf(invalidCepError, cep) | ||
if err.Error() != invalidError.Error() { | ||
t.Errorf("Was expected '%s', but got '%s'", invalidError.Error(), err.Error()) | ||
} | ||
}) | ||
} |