-
Notifications
You must be signed in to change notification settings - Fork 15
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
Showing
9 changed files
with
176 additions
and
200 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Package urls queries orchestra test-lists/urls API | ||
package urls | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
|
||
"github.com/ooni/probe-engine/httpx/jsonapi" | ||
"github.com/ooni/probe-engine/log" | ||
"github.com/ooni/probe-engine/model" | ||
) | ||
|
||
// Config contains configs for querying tests-lists/urls | ||
type Config struct { | ||
BaseURL string | ||
CountryCode string | ||
EnabledCategories []string | ||
HTTPClient *http.Client | ||
Limit int | ||
Logger log.Logger | ||
UserAgent string | ||
} | ||
|
||
// Result contains the result returned by tests-lists/urls | ||
type Result struct { | ||
Results []model.URLInfo `json:"results"` | ||
} | ||
|
||
// Query retrieves the test list for the specified country. | ||
func Query(ctx context.Context, config Config) (response Result, err error) { | ||
query := url.Values{} | ||
if config.CountryCode != "" { | ||
query.Set("probe_cc", config.CountryCode) | ||
} | ||
if config.Limit > 0 { | ||
query.Set("limit", fmt.Sprintf("%d", config.Limit)) | ||
} | ||
if len(config.EnabledCategories) > 0 { | ||
query.Set("category_codes", strings.Join(config.EnabledCategories, ",")) | ||
} | ||
err = (&jsonapi.Client{ | ||
BaseURL: config.BaseURL, | ||
HTTPClient: config.HTTPClient, | ||
Logger: config.Logger, | ||
UserAgent: config.UserAgent, | ||
}).ReadWithQuery(ctx, "/api/v1/test-list/urls", query, &response) | ||
return | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package urls | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/apex/log" | ||
) | ||
|
||
func TestIntegration(t *testing.T) { | ||
config := Config{ | ||
BaseURL: "https://orchestrate.ooni.io", | ||
CountryCode: "IT", | ||
EnabledCategories: []string{"NEWS", "CULTR"}, | ||
HTTPClient: http.DefaultClient, | ||
Limit: 17, | ||
Logger: log.Log, | ||
UserAgent: "ooniprobe-engine/v0.1.0-dev", | ||
} | ||
ctx := context.Background() | ||
result, err := Query(ctx, config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(result.Results) < 1 { | ||
t.Fatal("no results") | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.