-
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.
Merge pull request #30 from mailerlite/feature/no-ref/go-interface-mocks
chore: add interfaces and export types
- Loading branch information
Showing
11 changed files
with
278 additions
and
145 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 |
---|---|---|
|
@@ -64,6 +64,15 @@ MailerLite Golang SDK | |
- [Campaign languages](#languages) | ||
- [Get a list of languages](#get-a-list-of-languages) | ||
|
||
# Installation | ||
We recommend using this package with golang [modules](https://github.com/golang/go/wiki/Modules) | ||
|
||
``` | ||
$ go get github.com/mailerlite/mailerlite-go | ||
``` | ||
|
||
# Usage | ||
|
||
## Subscribers | ||
|
||
### Get a list of subscribers | ||
|
@@ -132,7 +141,7 @@ func main() { | |
log.Fatal(err) | ||
} | ||
|
||
log.Print(subscribers.Data.Email) | ||
log.Print(subscriber.Data.Email) | ||
} | ||
``` | ||
|
||
|
@@ -253,7 +262,7 @@ func main() { | |
|
||
ctx := context.TODO() | ||
|
||
_, _, err := client.Subscriber.Delete(ctx, "subscriber-id") | ||
_, err := client.Subscriber.Delete(ctx, "subscriber-id") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
@@ -457,7 +466,7 @@ func main() { | |
|
||
ctx := context.TODO() | ||
|
||
_, _, err := client.Group.UnAssign(ctx, "group-id", "subscriber-id") | ||
_, err := client.Group.UnAssign(ctx, "group-id", "subscriber-id") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
@@ -1424,6 +1433,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/) | ||
|
||
``` | ||
|
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
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
Oops, something went wrong.