-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9586c7d
commit 8f966c2
Showing
1 changed file
with
23 additions
and
25 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 |
---|---|---|
|
@@ -8,7 +8,6 @@ MailerLite Golang SDK | |
|
||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Testing](#testing) | ||
- [Subscribers](#subscribers) | ||
- [Get a list of subscribers](#get-a-list-of-subscribers) | ||
- [Get a single subscriber](#get-a-single-subscriber) | ||
|
@@ -65,30 +64,6 @@ MailerLite Golang SDK | |
- [Campaign languages](#languages) | ||
- [Get a list of languages](#get-a-list-of-languages) | ||
|
||
## Testing | ||
We provide interfaces for all services to help with testing | ||
|
||
```go | ||
type mockSubscriberService struct { | ||
mailerlite.SubscriberService | ||
} | ||
|
||
func (m *mockSubscriberService) List(ctx context.Context, options *mailerlite.ListSubscriberOptions) (*mailerlite.RootSubscribers, *mailerlite.Response, error) { | ||
return &mailerlite.RootSubscribers{Data: []mailerlite.Subscriber{{Email: "[email protected]"}}}, nil, nil | ||
} | ||
|
||
func TestListSubscribers(t *testing.T) { | ||
client := &mailerlite.Client{} | ||
client.Subscriber = &mockSubscriberService{} | ||
|
||
ctx := context.Background() | ||
result, _, err := client.Subscriber.List(ctx, nil) | ||
if err != nil || len(result.Data) == 0 || result.Data[0].Email != "[email protected]" { | ||
t.Fatalf("mock failed") | ||
} | ||
} | ||
``` | ||
|
||
## Subscribers | ||
|
||
### Get a list of subscribers | ||
|
@@ -1449,6 +1424,29 @@ func main() { | |
|
||
# Testing | ||
|
||
We provide interfaces for all services to help with testing | ||
|
||
```go | ||
type mockSubscriberService struct { | ||
mailerlite.SubscriberService | ||
} | ||
|
||
func (m *mockSubscriberService) List(ctx context.Context, options *mailerlite.ListSubscriberOptions) (*mailerlite.RootSubscribers, *mailerlite.Response, error) { | ||
return &mailerlite.RootSubscribers{Data: []mailerlite.Subscriber{{Email: "[email protected]"}}}, nil, nil | ||
} | ||
|
||
func TestListSubscribers(t *testing.T) { | ||
client := &mailerlite.Client{} | ||
client.Subscriber = &mockSubscriberService{} | ||
|
||
ctx := context.Background() | ||
result, _, err := client.Subscriber.List(ctx, nil) | ||
if err != nil || len(result.Data) == 0 || result.Data[0].Email != "[email protected]" { | ||
t.Fatalf("mock failed") | ||
} | ||
} | ||
``` | ||
|
||
[pkg/testing](https://golang.org/pkg/testing/) | ||
|
||
``` | ||
|