Skip to content

Commit

Permalink
oonirun: use httpclientx (#1571)
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone authored Apr 29, 2024
1 parent 419ab2a commit 462bcca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
19 changes: 5 additions & 14 deletions internal/oonirun/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/hexops/gotextdiff"
"github.com/hexops/gotextdiff/myers"
"github.com/hexops/gotextdiff/span"
"github.com/ooni/probe-cli/v3/internal/httpx"
"github.com/ooni/probe-cli/v3/internal/httpclientx"
"github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/runtimex"
Expand Down Expand Up @@ -64,21 +64,12 @@ type V2Nettest struct {
// a static URL (e.g., from a GitHub repo or from a Gist).
func getV2DescriptorFromHTTPSURL(ctx context.Context, client model.HTTPClient,
logger model.Logger, URL string) (*V2Descriptor, error) {
template := httpx.APIClientTemplate{
Accept: "",
Authorization: "",
BaseURL: URL,
HTTPClient: client,
Host: "",
LogBody: true,
return httpclientx.GetJSON[*V2Descriptor](ctx, URL, &httpclientx.Config{
Authorization: "", // not needed
Client: client,
Logger: logger,
UserAgent: model.HTTPHeaderUserAgent,
}
var desc V2Descriptor
if err := template.Build().GetJSON(ctx, "", &desc); err != nil {
return nil, err
}
return &desc, nil
})
}

// v2DescriptorCache contains all the known v2Descriptor entries.
Expand Down
4 changes: 2 additions & 2 deletions internal/oonirun/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"github.com/ooni/probe-cli/v3/internal/httpclientx"
"github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/mocks"
"github.com/ooni/probe-cli/v3/internal/model"
Expand Down Expand Up @@ -200,8 +201,7 @@ func TestOONIRunV2LinkNilDescriptor(t *testing.T) {
r := NewLinkRunner(config, server.URL)

// make sure we correctly handled an invalid "null" descriptor
if err := r.Run(ctx); err != nil {
t.Fatal(err)
if err := r.Run(ctx); !errors.Is(err, httpclientx.ErrIsNil) {
t.Fatal("unexpected error", err)
}
}
Expand Down

0 comments on commit 462bcca

Please sign in to comment.