-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_test.go
55 lines (46 loc) · 1.08 KB
/
service_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
package cepgo_test
import (
"errors"
"testing"
"github.com/victorfernandesraton/cepgo"
)
var ErrorSumulated = errors.New("Simulated error")
func TestValidConcurrentSameRequest(t *testing.T) {
data, err := cepgo.New().GetCEP("41342315")
if err != nil {
t.Fail()
}
if data == nil {
t.Fail()
}
if data.State != "BA" {
t.Fail()
}
}
type CustonError struct {
}
func (c *CustonError) Execute(cep string, ch chan<- *cepgo.CEP, errCh chan<- error) {
errCh <- ErrorSumulated
return
}
func TestWithAllErrorInRequest(t *testing.T) {
data, err := cepgo.OverrideProvider(&CustonError{}, &CustonError{}).GetCEP("41342315")
if err != cepgo.ErrorInAllRequests {
t.Fatalf("expect %v, got %v", cepgo.ErrorInAllRequests, err)
}
if data != nil {
t.Fatalf("expect %v, got %v", true, data)
}
}
func TestWithOneErrorANdOneSucess(t *testing.T) {
data, err := cepgo.OverrideProvider(&cepgo.ServiceBrasilAPi{}, &CustonError{}).GetCEP("41342315")
if err != nil {
t.Fatalf("expect %v, got %v", ErrorSumulated, err)
}
if data == nil {
t.Fail()
}
if data.State != "BA" {
t.Fail()
}
}