Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for passing the limit and category code to the testlists pkg #39

Merged
merged 3 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion orchestra/testlists/testlists.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testlists

import (
"context"
"strings"
"net/http"
"net/url"

Expand Down Expand Up @@ -45,6 +46,9 @@ type Client struct {

// UserAgent is the user agent to use.
UserAgent string

// EnabledCategories is a list of category codes that are enabled
EnabledCategories []string
}

// NewClient creates a new client in the context of the given session.
Expand All @@ -57,15 +61,26 @@ func NewClient(sess *session.Session) *Client {
}
}

// SetEnabledCategories configures the client category codes
func (c *Client) SetEnabledCategories(categories []string) error {
c.EnabledCategories = categories
}

// Do retrieves the test list for the specified country.
func (c *Client) Do(
ctx context.Context, countryCode string,
ctx context.Context, countryCode string, limit int,
) ([]URLInfo, error) {
var resp response
query := url.Values{}
if countryCode != "" {
query.Set("probe_cc", countryCode)
}
if (limit > 0) {
query.Set("limit", limit)
}
if (len(c.EnabledCategories) > 0) {
query.Set("category_codes", strings.Join(c.EnabledCategories, ","))
}
err := (&jsonapi.Client{
BaseURL: c.BaseURL,
HTTPClient: c.HTTPClient,
Expand Down
2 changes: 1 addition & 1 deletion orchestra/testlists/testlists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func makeClient() *testlists.Client {

func TestIntegration(t *testing.T) {
log.SetLevel(log.DebugLevel)
urls, err := makeClient().Do(context.Background(), "IT")
urls, err := makeClient().Do(context.Background(), "IT", 0)
if err != nil {
t.Fatal(err)
}
Expand Down