-
Notifications
You must be signed in to change notification settings - Fork 0
/
apicep_test.go
64 lines (60 loc) · 1.26 KB
/
apicep_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cepgo_test
import (
"testing"
"github.com/victorfernandesraton/cepgo"
)
func TestAPICep(t *testing.T) {
var stub = &cepgo.ServiceApiCEP{}
testCases := []struct {
desc string
cep string
expect *cepgo.CEP
waitError error
}{
{
desc: "should be a valid cep",
cep: "41342315",
expect: &cepgo.CEP{
Cep: "41342315",
State: "BA",
City: "Salvador",
},
waitError: nil,
},
{
desc: "should be a valid cep",
cep: "41342-315",
expect: &cepgo.CEP{
Cep: "41342315",
State: "BA",
City: "Salvador",
},
waitError: nil,
},
{
desc: "should be a valid cep",
cep: "41342A",
expect: nil,
waitError: cepgo.ErrorUnexpectedResponse,
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
chRes := make(chan *cepgo.CEP)
chErr := make(chan error)
go stub.Execute(tC.cep, chRes, chErr)
select {
case res := <-chRes:
if res != nil {
if res.Cep != tC.expect.Cep || res.State != tC.expect.State || res.City != tC.expect.City {
t.Fatalf("Expected %v, got %v", tC.expect, res)
}
}
case errorInCh := <-chErr:
if errorInCh != tC.waitError {
t.Fatalf("Expected %v, got %v", tC.waitError, errorInCh)
}
}
})
}
}