Skip to content

Commit

Permalink
ci(lint): enable usetesting (#574)
Browse files Browse the repository at this point in the history
This commit enables the `usetesting` linter in the golangci.yml file
and fixes issues found by it.
  • Loading branch information
abhinav authored Feb 17, 2025
1 parent 04c3f63 commit c698fc1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ linters:
- gofumpt
- nolintlint
- revive
- usetesting

# With Go 1.22 for loop semantics,
# no need to copy loop variables.
Expand Down
11 changes: 1 addition & 10 deletions internal/fixturetest/fixturetest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@ package fixturetest_test

import (
"math/rand"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.abhg.dev/gs/internal/fixturetest"
)

func TestFixture(t *testing.T) {
cwd, err := os.Getwd()
require.NoError(t, err)

dir := t.TempDir()
require.NoError(t, os.Chdir(dir))
t.Cleanup(func() {
assert.NoError(t, os.Chdir(cwd))
})
t.Chdir(t.TempDir())

cfg := fixturetest.Config{Update: new(bool)}
fixture := fixturetest.New(cfg, "number", rand.Int)
Expand Down
16 changes: 10 additions & 6 deletions internal/forge/github/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func TestIntegration_Repository_SubmitEditChange(t *testing.T) {
t.Cleanup(func() {
t.Logf("Deleting remote branch: %s", branchName)
assert.NoError(t,
gitRepo.Push(context.Background(), git.PushOptions{
gitRepo.Push(context.WithoutCancel(ctx), git.PushOptions{
Remote: "origin",
Refspec: git.Refspec(":" + branchName),
}), "error deleting branch")
Expand Down Expand Up @@ -331,8 +331,9 @@ func TestIntegration_Repository_SubmitEditChange(t *testing.T) {

t.Cleanup(func() {
t.Logf("Deleting remote branch: %s", newBase)
ctx := context.WithoutCancel(t.Context())
require.NoError(t,
gitRepo.Push(context.Background(), git.PushOptions{
gitRepo.Push(ctx, git.PushOptions{
Remote: "origin",
Refspec: git.Refspec(":" + newBase),
}), "error deleting branch")
Expand All @@ -346,8 +347,9 @@ func TestIntegration_Repository_SubmitEditChange(t *testing.T) {
}), "could not update base branch for PR")
t.Cleanup(func() {
t.Logf("Changing base back to: main")
ctx := context.WithoutCancel(t.Context())
require.NoError(t,
repo.EditChange(context.Background(), changeID, forge.EditChangeOptions{
repo.EditChange(ctx, changeID, forge.EditChangeOptions{
Base: "main",
}), "error restoring base branch")
})
Expand All @@ -367,10 +369,11 @@ func TestIntegration_Repository_SubmitEditChange(t *testing.T) {
Draft: &draft,
}), "could not update draft status for PR")
t.Cleanup(func() {
ctx := context.WithoutCancel(t.Context())
t.Logf("Changing to ready for review")
draft = false
require.NoError(t,
repo.EditChange(context.Background(), changeID, forge.EditChangeOptions{
repo.EditChange(ctx, changeID, forge.EditChangeOptions{
Draft: &draft,
}), "error restoring draft status")
})
Expand Down Expand Up @@ -398,10 +401,11 @@ func TestIntegration_Repository_comments(t *testing.T) {
}, commentBody)
require.NoError(t, err, "could not post comment")
t.Cleanup(func() {
ctx := context.WithoutCancel(t.Context())
t.Logf("Deleting comment: %s", commentID)

require.NoError(t,
repo.DeleteChangeComment(context.Background(), commentID),
repo.DeleteChangeComment(ctx, commentID),
"could not delete comment")
})

Expand Down Expand Up @@ -482,7 +486,7 @@ func TestIntegration_Repository_ListChangeComments_paginated(t *testing.T) {

var commentIDs []forge.ChangeCommentID
t.Cleanup(func() {
ctx := context.Background()
ctx := context.WithoutCancel(t.Context())
for _, commentID := range commentIDs {
t.Logf("Deleting comment: %s", commentID)

Expand Down
18 changes: 12 additions & 6 deletions internal/forge/gitlab/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,10 @@ func TestIntegration_Repository_SubmitEditChange(t *testing.T) {
}), "error pushing branch")

t.Cleanup(func() {
ctx := context.WithoutCancel(t.Context())
t.Logf("Deleting remote branch: %s", branchName)
assert.NoError(t,
gitRepo.Push(context.Background(), git.PushOptions{
gitRepo.Push(ctx, git.PushOptions{
Remote: "origin",
Refspec: git.Refspec(":" + branchName),
}), "error deleting branch")
Expand Down Expand Up @@ -342,9 +343,10 @@ func TestIntegration_Repository_SubmitEditChange(t *testing.T) {
}), "could not push base branch")

t.Cleanup(func() {
ctx := context.WithoutCancel(t.Context())
t.Logf("Deleting remote branch: %s", newBase)
require.NoError(t,
gitRepo.Push(context.Background(), git.PushOptions{
gitRepo.Push(ctx, git.PushOptions{
Remote: "origin",
Refspec: git.Refspec(":" + newBase),
}), "error deleting branch")
Expand All @@ -357,9 +359,10 @@ func TestIntegration_Repository_SubmitEditChange(t *testing.T) {
Base: newBase,
}), "could not update base branch for PR")
t.Cleanup(func() {
ctx := context.WithoutCancel(t.Context())
t.Logf("Changing base back to: main")
require.NoError(t,
repo.EditChange(context.Background(), changeID, forge.EditChangeOptions{
repo.EditChange(ctx, changeID, forge.EditChangeOptions{
Base: "main",
}), "error restoring base branch")
})
Expand All @@ -380,10 +383,11 @@ func TestIntegration_Repository_SubmitEditChange(t *testing.T) {
Draft: &draft,
}), "could not update draft status for PR")
t.Cleanup(func() {
ctx := context.WithoutCancel(t.Context())
t.Logf("Changing to ready for review")
draft = false
require.NoError(t,
repo.EditChange(context.Background(), changeID, forge.EditChangeOptions{
repo.EditChange(ctx, changeID, forge.EditChangeOptions{
Draft: &draft,
}), "error restoring draft status")
})
Expand Down Expand Up @@ -413,8 +417,9 @@ func TestIntegration_Repository_comments(t *testing.T) {
t.Cleanup(func() {
t.Logf("Deleting comment: %s", commentID)

ctx := context.WithoutCancel(t.Context())
require.NoError(t,
repo.DeleteChangeComment(context.Background(), commentID),
repo.DeleteChangeComment(ctx, commentID),
"could not delete comment")
})

Expand Down Expand Up @@ -495,11 +500,12 @@ func TestIntegration_Repository_ListChangeComments_paginated(t *testing.T) {

var commentIDs []forge.ChangeCommentID
t.Cleanup(func() {
ctx := context.WithoutCancel(t.Context())
for _, commentID := range commentIDs {
t.Logf("Deleting comment: %s", commentID)

assert.NoError(t,
repo.DeleteChangeComment(context.Background(), commentID),
repo.DeleteChangeComment(ctx, commentID),
"could not delete comment")
}
})
Expand Down
4 changes: 2 additions & 2 deletions mise.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c698fc1

Please sign in to comment.