Skip to content

Commit

Permalink
download+rest: code cosmetics (#4120)
Browse files Browse the repository at this point in the history
Not much of consequence here, a few code cleanups in tests and interfaces.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
  • Loading branch information
srenatus committed Dec 13, 2021
1 parent d817166 commit 7447346
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
27 changes: 13 additions & 14 deletions download/download_test.go
Expand Up @@ -489,7 +489,7 @@ func TestTriggerManualWithTimeout(t *testing.T) {
}

d := New(config, fixture.client, "/bundles/test/bundle1").
WithCallback(func(_ context.Context, u Update) {
WithCallback(func(context.Context, Update) {
time.Sleep(3 * time.Second) // this should cause the context deadline to exceed
})

Expand All @@ -512,12 +512,12 @@ func TestTriggerManualWithTimeout(t *testing.T) {
t.Fatal("Expected error but got nil")
}

exp := "context deadline exceeded"
if ctx.Err().Error() != exp {
t.Fatalf("Expected error %v but got %v", exp, ctx.Err().Error())
exp := context.DeadlineExceeded
if ctx.Err() != exp {
t.Fatalf("Expected error %v but got %v", exp, ctx.Err())
}

d.Stop(ctx)
d.Stop(context.Background())
}

func TestDownloadLongPollNotModifiedOn304(t *testing.T) {
Expand Down Expand Up @@ -696,15 +696,14 @@ func (t *testFixture) oneShot(ctx context.Context, u Update) {
}

type testServer struct {
t *testing.T
expCode int
expEtag string
expAuth string
bundles map[string]bundle.Bundle
server *httptest.Server
etagInResponse bool
longPoll bool
opaVendorMediaTypeEnabled bool
t *testing.T
expCode int
expEtag string
expAuth string
bundles map[string]bundle.Bundle
server *httptest.Server
etagInResponse bool
longPoll bool
}

func (t *testServer) handle(w http.ResponseWriter, r *http.Request) {
Expand Down
7 changes: 3 additions & 4 deletions plugins/rest/rest.go
Expand Up @@ -31,8 +31,8 @@ const (
// An HTTPAuthPlugin represents a mechanism to construct and configure HTTP authentication for a REST service
type HTTPAuthPlugin interface {
// implementations can assume NewClient will be called before Prepare
NewClient(c Config) (*http.Client, error)
Prepare(req *http.Request) error
NewClient(Config) (*http.Client, error)
Prepare(*http.Request) error
}

// Config represents configuration for a REST client.
Expand Down Expand Up @@ -236,8 +236,7 @@ func (c Client) Do(ctx context.Context, method, path string) (*http.Response, er
var body io.Reader

if c.bytes != nil {
buf := bytes.NewBuffer(*c.bytes)
body = buf
body = bytes.NewReader(*c.bytes)
} else if c.json != nil {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(*c.json); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions plugins/rest/rest_auth.go
Expand Up @@ -90,15 +90,15 @@ func DefaultRoundTripperClient(t *tls.Config, timeout int64) *http.Client {
// defaultAuthPlugin represents baseline 'no auth' behavior if no alternative plugin is specified for a service
type defaultAuthPlugin struct{}

func (ap *defaultAuthPlugin) NewClient(c Config) (*http.Client, error) {
func (*defaultAuthPlugin) NewClient(c Config) (*http.Client, error) {
t, err := DefaultTLSConfig(c)
if err != nil {
return nil, err
}
return DefaultRoundTripperClient(t, *c.ResponseHeaderTimeoutSeconds), nil
}

func (ap *defaultAuthPlugin) Prepare(req *http.Request) error {
func (*defaultAuthPlugin) Prepare(*http.Request) error {
return nil
}

Expand Down

0 comments on commit 7447346

Please sign in to comment.