From 8c7de93717ec777b9af8f9e60021b63cc10fd74b Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 8 Sep 2023 09:26:41 -0600 Subject: [PATCH] Fix some linting issues Signed-off-by: Jacob Weinstock --- providers/rpc/http_test.go | 8 ++++---- providers/rpc/rpc.go | 9 ++++----- providers/rpc/rpc_test.go | 1 - 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/providers/rpc/http_test.go b/providers/rpc/http_test.go index eebf06cf..e386ff60 100644 --- a/providers/rpc/http_test.go +++ b/providers/rpc/http_test.go @@ -14,10 +14,10 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" ) -func testRequest(method, url string, body RequestPayload, headers http.Header) *http.Request { +func testRequest(method, reqURL string, body RequestPayload, headers http.Header) *http.Request { var buf bytes.Buffer _ = json.NewEncoder(&buf).Encode(body) - req, _ := http.NewRequest(method, url, &buf) + req, _ := http.NewRequestWithContext(context.Background(), method, reqURL, &buf) req.Header = headers return req } @@ -58,7 +58,7 @@ func TestRequestKVS(t *testing.T) { func TestRequestKVSOneOffs(t *testing.T) { t.Run("nil body", func(t *testing.T) { - req, _ := http.NewRequest(http.MethodPost, "http://example.com", nil) + req, _ := http.NewRequestWithContext(context.Background(), http.MethodPost, "http://example.com", nil) got := requestKVS(req) if diff := cmp.Diff(got, []interface{}{"request", requestDetails{}}); diff != "" { t.Logf("got: %+v", got) @@ -72,7 +72,7 @@ func TestRequestKVSOneOffs(t *testing.T) { }) t.Run("failed to unmarshal body", func(t *testing.T) { - req, _ := http.NewRequest(http.MethodPost, "http://example.com", bytes.NewBufferString("invalid")) + req, _ := http.NewRequestWithContext(context.Background(), http.MethodPost, "http://example.com", bytes.NewBufferString("invalid")) got := requestKVS(req) if diff := cmp.Diff(got, []interface{}{"request", requestDetails{URL: "http://example.com", Method: http.MethodPost, Headers: http.Header{}}}); diff != "" { t.Logf("got: %+v", got) diff --git a/providers/rpc/rpc.go b/providers/rpc/rpc.go index e3f76013..e75d0f7d 100644 --- a/providers/rpc/rpc.go +++ b/providers/rpc/rpc.go @@ -190,9 +190,8 @@ func (p *Provider) Open(ctx context.Context) error { if err != nil { return err } - defer resp.Body.Close() - return nil + return resp.Body.Close() } // Close a connection to the rpc consumer. @@ -203,7 +202,7 @@ func (p *Provider) Close(_ context.Context) (err error) { // BootDeviceSet sends a next boot device rpc notification. func (p *Provider) BootDeviceSet(ctx context.Context, bootDevice string, setPersistent, efiBoot bool) (ok bool, err error) { rp := RequestPayload{ - ID: int64(time.Now().UnixNano()), + ID: time.Now().UnixNano(), Host: p.Host, Method: BootDeviceMethod, Params: BootDeviceParams{ @@ -228,7 +227,7 @@ func (p *Provider) PowerSet(ctx context.Context, state string) (ok bool, err err switch strings.ToLower(state) { case "on", "off", "cycle": rp := RequestPayload{ - ID: int64(time.Now().UnixNano()), + ID: time.Now().UnixNano(), Host: p.Host, Method: PowerSetMethod, Params: PowerSetParams{ @@ -252,7 +251,7 @@ func (p *Provider) PowerSet(ctx context.Context, state string) (ok bool, err err // PowerStateGet gets the power state of a BMC machine. func (p *Provider) PowerStateGet(ctx context.Context) (state string, err error) { rp := RequestPayload{ - ID: int64(time.Now().UnixNano()), + ID: time.Now().UnixNano(), Host: p.Host, Method: PowerGetMethod, } diff --git a/providers/rpc/rpc_test.go b/providers/rpc/rpc_test.go index 448f42c9..78abf556 100644 --- a/providers/rpc/rpc_test.go +++ b/providers/rpc/rpc_test.go @@ -114,7 +114,6 @@ func TestPowerSet(t *testing.T) { if err != nil && !tc.shouldErr { t.Fatal(err) } - }) } }