-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_test.go
74 lines (65 loc) · 1.5 KB
/
option_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
package mobilepulsa_test
import (
"context"
"net/http"
"testing"
mobilepulsa "github.com/pandudpn/mobile-pulsa-go"
"github.com/stretchr/testify/mock"
)
type apiRequestMock struct {
mock.Mock
}
func (a *apiRequestMock) Call(ctx context.Context, httpMethod, url string, header http.Header, body interface{}, result interface{}) error {
a.Called(ctx, httpMethod, url, header, body, result)
return nil
}
func TestNewOption(t *testing.T) {
testCases := []struct {
name string
username string
apikey string
development bool
httpClient *http.Client
}{
{
name: "success valid",
username: "test",
apikey: "test-api-key",
development: true,
httpClient: &http.Client{},
},
{
name: "get error username is nil",
username: "",
apikey: "test-api-key",
development: true,
httpClient: &http.Client{},
},
{
name: "get error api-key is nil",
username: "test",
apikey: "",
development: false,
httpClient: &http.Client{},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
apiRequestMockObj := new(apiRequestMock)
opts := mobilepulsa.NewOption()
opts.SetUsername(tc.username)
opts.SetAPIKey(tc.apikey)
opts.SetHTTPClient(tc.httpClient)
opts.SetAPIRequest(apiRequestMockObj)
opts.Valid()
opts.GetUsername()
opts.GetAccessType()
opts.Sign("")
if tc.development {
opts.SetAccessDevelopment()
} else {
opts.SetAccessProduction()
}
})
}
}