feat(oonirun): add support for OONIRun v2 links (#844)

This diff adds support for OONIRun v2 links.

Part of https://github.com/ooni/probe/issues/2184.
This commit is contained in:
Simone Basso 2022-07-08 16:53:59 +02:00 committed by GitHub
commit 9a0153a349
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 644 additions and 22 deletions

View file

@ -94,12 +94,27 @@ func newAPIClient() *apiClient {
}
func TestJoinURLPath(t *testing.T) {
t.Run("the whole path is inside basePath and there's no resource path", func(t *testing.T) {
ac := newAPIClient()
ac.BaseURL = "https://example.com/robots.txt"
req, err := ac.newRequest(context.Background(), "GET", "", nil, nil)
if err != nil {
t.Fatal(err)
}
if req.URL.String() != "https://example.com/robots.txt" {
t.Fatal("unexpected result", req.URL.String())
}
})
t.Run("empty baseURL path and slash-prefixed resource path", func(t *testing.T) {
ac := newAPIClient()
ac.BaseURL = "https://example.com"
req, err := ac.newRequest(context.Background(), "GET", "/foo", nil, nil)
if err != nil {
t.Fatal(err)
}
if req.URL.String() != "https://example.com/foo" {
t.Fatal("unexpected result", err)
t.Fatal("unexpected result", req.URL.String())
}
})
@ -107,8 +122,11 @@ func TestJoinURLPath(t *testing.T) {
ac := newAPIClient()
ac.BaseURL = "https://example.com/"
req, err := ac.newRequest(context.Background(), "GET", "/foo", nil, nil)
if err != nil {
t.Fatal(err)
}
if req.URL.String() != "https://example.com/foo" {
t.Fatal("unexpected result", err)
t.Fatal("unexpected result", req.URL.String())
}
})
@ -116,8 +134,11 @@ func TestJoinURLPath(t *testing.T) {
ac := newAPIClient()
ac.BaseURL = "https://example.com"
req, err := ac.newRequest(context.Background(), "GET", "", nil, nil)
if err != nil {
t.Fatal(err)
}
if req.URL.String() != "https://example.com/" {
t.Fatal("unexpected result", err)
t.Fatal("unexpected result", req.URL.String())
}
})
@ -125,8 +146,11 @@ func TestJoinURLPath(t *testing.T) {
ac := newAPIClient()
ac.BaseURL = "http://example.com/foo"
req, err := ac.newRequest(context.Background(), "GET", "/bar", nil, nil)
if err != nil {
t.Fatal(err)
}
if req.URL.String() != "http://example.com/foo/bar" {
t.Fatal("unexpected result", err)
t.Fatal("unexpected result", req.URL.String())
}
})
@ -134,8 +158,11 @@ func TestJoinURLPath(t *testing.T) {
ac := newAPIClient()
ac.BaseURL = "http://example.com/foo/"
req, err := ac.newRequest(context.Background(), "GET", "/bar", nil, nil)
if err != nil {
t.Fatal(err)
}
if req.URL.String() != "http://example.com/foo/bar" {
t.Fatal("unexpected result", err)
t.Fatal("unexpected result", req.URL.String())
}
})
@ -143,8 +170,11 @@ func TestJoinURLPath(t *testing.T) {
ac := newAPIClient()
ac.BaseURL = "http://example.com/foo/"
req, err := ac.newRequest(context.Background(), "GET", "bar", nil, nil)
if err != nil {
t.Fatal(err)
}
if req.URL.String() != "http://example.com/foo/bar" {
t.Fatal("unexpected result", err)
t.Fatal("unexpected result", req.URL.String())
}
})
}