Skip to content

Commit b99c318

Browse files
committed
Lint fixes for audit event packages
1 parent e02f4bb commit b99c318

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

internal/command/gitauditevent/audit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package gitauditevent handles Git audit events for GitLab.
12
package gitauditevent
23

34
import (

internal/command/gitauditevent/audit_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"testing"
99

10+
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
1213
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/commandargs"
@@ -30,13 +31,13 @@ func TestGitAudit(t *testing.T) {
3031
called = true
3132

3233
body, err := io.ReadAll(r.Body)
33-
require.NoError(t, err)
34+
assert.NoError(t, err)
3435
defer r.Body.Close()
3536

3637
var request *gitauditevent.Request
37-
require.NoError(t, json.Unmarshal(body, &request))
38-
require.Equal(t, testUsername, request.Username)
39-
require.Equal(t, testRepo, request.Repo)
38+
assert.NoError(t, json.Unmarshal(body, &request))
39+
assert.Equal(t, testUsername, request.Username)
40+
assert.Equal(t, testRepo, request.Repo)
4041

4142
w.WriteHeader(http.StatusOK)
4243
},

internal/gitlabnet/gitauditevent/client.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package gitauditevent handles Git audit events for GitLab.
12
package gitauditevent
23

34
import (
@@ -13,11 +14,13 @@ import (
1314

1415
const uri = "/api/v4/internal/shellhorse/git_audit_event"
1516

17+
// Client handles communication with the GitLab audit event API.
1618
type Client struct {
1719
config *config.Config
1820
client *client.GitlabNetClient
1921
}
2022

23+
// NewClient creates a new Client for sending audit events.
2124
func NewClient(config *config.Config) (*Client, error) {
2225
client, err := gitlabnet.GetClient(config)
2326
if err != nil {
@@ -27,6 +30,7 @@ func NewClient(config *config.Config) (*Client, error) {
2730
return &Client{config: config, client: client}, nil
2831
}
2932

33+
// Request represents the data for a Git audit event.
3034
type Request struct {
3135
Action commandargs.CommandType `json:"action"`
3236
Protocol string `json:"protocol"`
@@ -35,6 +39,7 @@ type Request struct {
3539
PackfileStats *pb.PackfileNegotiationStatistics `json:"packfile_stats,omitempty"`
3640
}
3741

42+
// Audit sends an audit event to the GitLab API.
3843
func (c *Client) Audit(ctx context.Context, username string, action commandargs.CommandType, repo string, packfileStats *pb.PackfileNegotiationStatistics) error {
3944
request := &Request{
4045
Action: action,
@@ -48,6 +53,10 @@ func (c *Client) Audit(ctx context.Context, username string, action commandargs.
4853
if err != nil {
4954
return err
5055
}
51-
defer response.Body.Close()
56+
defer func() {
57+
if err := response.Body.Close(); err != nil {
58+
_ = fmt.Errorf("unable to close response body: %v", err)
59+
}
60+
}()
5261
return nil
5362
}

internal/gitlabnet/gitauditevent/client_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"testing"
99

10+
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
pb "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
1213
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
@@ -48,17 +49,17 @@ func setup(t *testing.T, responseStatus int) *Client {
4849
Path: uri,
4950
Handler: func(w http.ResponseWriter, r *http.Request) {
5051
body, err := io.ReadAll(r.Body)
51-
require.NoError(t, err)
52+
assert.NoError(t, err)
5253
defer r.Body.Close()
5354

5455
var request *Request
55-
require.NoError(t, json.Unmarshal(body, &request))
56-
require.Equal(t, testUsername, request.Username)
57-
require.Equal(t, testAction, request.Action)
58-
require.Equal(t, testRepo, request.Repo)
59-
require.Equal(t, "ssh", request.Protocol)
60-
require.Equal(t, testPackfileWants, request.PackfileStats.Wants)
61-
require.Equal(t, testPackfileHaves, request.PackfileStats.Haves)
56+
assert.NoError(t, json.Unmarshal(body, &request))
57+
assert.Equal(t, testUsername, request.Username)
58+
assert.Equal(t, testAction, request.Action)
59+
assert.Equal(t, testRepo, request.Repo)
60+
assert.Equal(t, "ssh", request.Protocol)
61+
assert.Equal(t, testPackfileWants, request.PackfileStats.Wants)
62+
assert.Equal(t, testPackfileHaves, request.PackfileStats.Haves)
6263

6364
w.WriteHeader(responseStatus)
6465
},

0 commit comments

Comments
 (0)