Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
robgordon89 authored Nov 19, 2024
1 parent 9586c7d commit 8f966c2
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/)

```
Expand Down

0 comments on commit 8f966c2

Please sign in to comment.