-
Notifications
You must be signed in to change notification settings - Fork 0
/
aapi_options_test.go
76 lines (70 loc) · 1.8 KB
/
aapi_options_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
65
66
67
68
69
70
71
72
73
74
75
76
package emailvalidator
import (
"net/url"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_parseAbstractAPIOptions(t *testing.T) {
defURL, err := url.Parse(defaultAbstractAPIURL)
assert.NoError(t, err)
baseURL, err := url.Parse("https://baseUrl.com")
assert.NoError(t, err)
tests := []struct {
name string
options []AbstractAPIOptionFunc
expectedOptions *AbstractAPIOption
expectedError error
}{
{
name: "Should parse with default options",
options: []AbstractAPIOptionFunc{},
expectedOptions: &AbstractAPIOption{
baseURL: defURL,
apiVersion: defaultAbstractAPIVersion,
blocking: false,
rate: AbstractAPIFree,
},
},
{
name: "Should parse with custom options",
options: []AbstractAPIOptionFunc{
WithAbstractAPIBaseURL(baseURL),
WithAbstractAPIVersion("/v10"),
WithAbstractAPIBlocking(),
WithAbstractAPIRate(AbstractAPIBusiness),
},
expectedOptions: &AbstractAPIOption{
baseURL: baseURL,
apiVersion: "/v10",
blocking: true,
rate: AbstractAPIBusiness,
},
},
{
name: "Should return error if baseURL is empty",
options: []AbstractAPIOptionFunc{
WithAbstractAPIBaseURL(nil),
},
expectedOptions: nil,
expectedError: ErrEmptyBaseURL,
},
{
name: "Should return error if apiVersion is empty",
options: []AbstractAPIOptionFunc{
WithAbstractAPIVersion(""),
},
expectedOptions: nil,
expectedError: ErrEmptyAPIVersion,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseAbstractAPIOptions(tt.options...)
assert.Equal(t, tt.expectedError, err)
if !reflect.DeepEqual(got, tt.expectedOptions) {
t.Errorf("parseAbstractAPIOptions() = %v, want %v", got, tt.expectedOptions)
}
})
}
}