Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ linters:
- staticcheck
- unconvert
- unused
- usetesting
- wastedassign
- whitespace
settings:
Expand Down Expand Up @@ -88,6 +89,9 @@ linters:
require-explanation: true
require-specific: true
allow-unused: false
usetesting:
context-background: true
context-todo: true
exclusions:
generated: lax
presets:
Expand Down
3 changes: 1 addition & 2 deletions cmd/buf/buf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -1356,7 +1355,7 @@ func TestCheckLsBreakingRulesFromConfigExceptDeprecated(t *testing.T) {
// Do not need any custom lint/breaking plugins here.
client, err := bufcheck.NewClient(slogtestext.NewLogger(t))
require.NoError(t, err)
allRules, err := client.AllRules(context.Background(), check.RuleTypeBreaking, version)
allRules, err := client.AllRules(t.Context(), check.RuleTypeBreaking, version)
require.NoError(t, err)
allPackageIDs := make([]string, 0, len(allRules))
for _, rule := range allRules {
Expand Down
11 changes: 5 additions & 6 deletions cmd/buf/internal/command/alpha/protoc/protoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package protoc

import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -222,7 +221,7 @@ func testInsertionPointMixedPathsSuccess(t *testing.T, receiverOut string, write
fmt.Sprintf("--%s_out=%s", "insertion-point-writer", writerOut),
}
err := prototesting.RunProtoc(
context.Background(),
t.Context(),
[]string{dirPath},
filePaths,
false,
Expand Down Expand Up @@ -338,7 +337,7 @@ func testCompareGeneratedStubs(
)
require.NoError(t, err)
diff, err := storage.DiffBytes(
context.Background(),
t.Context(),
actualReadWriteBucket,
bufReadWriteBucket,
)
Expand Down Expand Up @@ -418,7 +417,7 @@ func testCompareGeneratedStubsArchive(
require.NoError(t, err)
actualReadWriteBucket := storagemem.NewReadWriteBucket()
err = storagearchive.Unzip(
context.Background(),
t.Context(),
bytes.NewReader(actualData),
int64(len(actualData)),
actualReadWriteBucket,
Expand All @@ -428,14 +427,14 @@ func testCompareGeneratedStubsArchive(
require.NoError(t, err)
bufReadWriteBucket := storagemem.NewReadWriteBucket()
err = storagearchive.Unzip(
context.Background(),
t.Context(),
bytes.NewReader(bufData),
int64(len(bufData)),
bufReadWriteBucket,
)
require.NoError(t, err)
diff, err := storage.DiffBytes(
context.Background(),
t.Context(),
actualReadWriteBucket,
bufReadWriteBucket,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package configmigrate

import (
"bytes"
"context"
"path/filepath"
"testing"

Expand Down Expand Up @@ -54,7 +53,7 @@ func testCompareConfigMigrate(t *testing.T, dir string, expectCode int, expectSt
tempDir := t.TempDir()
tempBucket, err := storageosProvider.NewReadWriteBucket(tempDir)
require.NoError(t, err)
ctx := context.Background()
ctx := t.Context()
_, err = storage.Copy(ctx, inputBucket, tempBucket)
require.NoError(t, err)
var outputBucket storage.ReadWriteBucket
Expand Down
18 changes: 9 additions & 9 deletions cmd/buf/internal/command/generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestGenerateV2LocalPluginBasic(t *testing.T) {
actual, err := storageos.NewProvider().NewReadWriteBucket(tempDirPath)
require.NoError(t, err)

diff, err := storage.DiffBytes(context.Background(), expected, actual)
diff, err := storage.DiffBytes(t.Context(), expected, actual)
require.NoError(t, err)
require.Empty(t, string(diff))
}
Expand All @@ -188,7 +188,7 @@ func TestGenerateV2LocalPluginTypes(t *testing.T) {
actual, err := storageos.NewProvider().NewReadWriteBucket(tempDirPath)
require.NoError(t, err)

diff, err := storage.DiffBytes(context.Background(), expected, actual)
diff, err := storage.DiffBytes(t.Context(), expected, actual)
require.NoError(t, err)
require.Empty(t, string(diff))
}
Expand Down Expand Up @@ -657,7 +657,7 @@ func testGenerateInsertionPoint(
) {
storageosProvider := storageos.NewProvider()
tempDir, readWriteBucket := internaltesting.CopyReadBucketToTempDir(
context.Background(),
t.Context(),
t,
storageosProvider,
storagemem.NewReadWriteBucket(),
Expand All @@ -672,7 +672,7 @@ func testGenerateInsertionPoint(
)
expectedOutput, err := storageosProvider.NewReadWriteBucket(expectedOutputPath)
require.NoError(t, err)
diff, err := storage.DiffBytes(context.Background(), expectedOutput, readWriteBucket)
diff, err := storage.DiffBytes(t.Context(), expectedOutput, readWriteBucket)
require.NoError(t, err)
require.Empty(t, string(diff))
}
Expand Down Expand Up @@ -802,7 +802,7 @@ func testCompareGeneratedStubs(
)
require.NoError(t, err)
diff, err := storage.DiffBytes(
context.Background(),
t.Context(),
actualReadWriteBucket,
bufReadWriteBucket,
transformGolangProtocVersionToUnknown(t),
Expand Down Expand Up @@ -864,7 +864,7 @@ func testCompareGeneratedStubsArchive(
require.NoError(t, err)
actualReadWriteBucket := storagemem.NewReadWriteBucket()
err = storagearchive.Unzip(
context.Background(),
t.Context(),
bytes.NewReader(actualData),
int64(len(actualData)),
actualReadWriteBucket,
Expand All @@ -874,14 +874,14 @@ func testCompareGeneratedStubsArchive(
require.NoError(t, err)
bufReadWriteBucket := storagemem.NewReadWriteBucket()
err = storagearchive.Unzip(
context.Background(),
t.Context(),
bytes.NewReader(bufData),
int64(len(bufData)),
bufReadWriteBucket,
)
require.NoError(t, err)
diff, err := storage.DiffBytes(
context.Background(),
t.Context(),
actualReadWriteBucket,
bufReadWriteBucket,
transformGolangProtocVersionToUnknown(t),
Expand Down Expand Up @@ -938,7 +938,7 @@ func testGenerateDeleteOutsWithArgAndConfig(
},
)
}
ctx := context.Background()
ctx := t.Context()
tmpDirPath := t.TempDir()
storageBucket, err := storageos.NewProvider().NewReadWriteBucket(tmpDirPath)
require.NoError(t, err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/buf/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -1716,7 +1715,7 @@ func createZipFromDir(t *testing.T, rootPath string, archiveName string) string

buffer := bytes.NewBuffer(nil)
require.NoError(t, storagearchive.Zip(
context.Background(),
t.Context(),
testdataBucket,
buffer,
true,
Expand All @@ -1728,7 +1727,7 @@ func createZipFromDir(t *testing.T, rootPath string, archiveName string) string
)
require.NoError(t, err)
require.NoError(t, storage.PutPath(
context.Background(),
t.Context(),
zipBucket,
archiveName,
buffer.Bytes(),
Expand Down
4 changes: 2 additions & 2 deletions cmd/protoc-gen-buf-lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func testRunHandlerFunc(

exitCode := app.GetExitCode(
protoplugin.Run(
context.Background(),
t.Context(),
protoplugin.Env{
Args: nil,
Stdin: stdin,
Expand Down Expand Up @@ -331,7 +331,7 @@ func testBuildRequest(
fileToGenerate []string,
) protoplugin.Request {
fileDescriptorSet, err := prototesting.GetProtocFileDescriptorSet(
context.Background(),
t.Context(),
[]string{root},
realFilePaths,
true,
Expand Down
3 changes: 1 addition & 2 deletions private/buf/bufcurl/invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package bufcurl

import (
"context"
"os"
"testing"

Expand All @@ -32,7 +31,7 @@ func TestCountUnrecognized(t *testing.T) {
Resolver: &protocompile.SourceResolver{
ImportPaths: []string{"./testdata"},
},
}).Compile(context.Background(), "test.proto")
}).Compile(t.Context(), "test.proto")
require.NoError(t, err)
msgType, err := descriptors.AsResolver().FindMessageByName("foo.bar.Message")
require.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions private/buf/buffetch/buffetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package buffetch

import (
"context"
"io"
"log/slog"
"path/filepath"
Expand Down Expand Up @@ -106,7 +105,7 @@ func testRoundTripLocalFile(
reader := testNewFetchReader(logger)
writer := testNewFetchWriter(logger)

ctx := context.Background()
ctx := t.Context()
container := app.NewContainer(nil, nil, nil, nil)

tmpDir := t.TempDir()
Expand Down
30 changes: 15 additions & 15 deletions private/buf/buffetch/internal/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func TestGetReadBucketCloserForBucketNoTerminateFileName(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
inputBucket, err := storageos.NewProvider().NewReadWriteBucket("testdata/bufyaml/one/two")
require.NoError(t, err)
readBucketCloser, bucketTargeting, err := getReadBucketCloserForBucket(
Expand All @@ -50,7 +50,7 @@ func TestGetReadBucketCloserForBucketNoTerminateFileName(t *testing.T) {

func TestGetReadBucketCloserTerminateFileName(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
inputBucket, err := storageos.NewProvider().NewReadWriteBucket("testdata/bufyaml/one/two")
require.NoError(t, err)
readBucketCloser, bucketTargeting, err := getReadBucketCloserForBucket(
Expand All @@ -72,7 +72,7 @@ func TestGetReadBucketCloserTerminateFileName(t *testing.T) {

func TestGetReadBucketCloserForBucketNoSubDirPath(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
inputBucket, err := storageos.NewProvider().NewReadWriteBucket("testdata/bufyaml/one/two/three/four/five")
require.NoError(t, err)
readBucketCloser, bucketTargeting, err := getReadBucketCloserForBucket(
Expand All @@ -94,7 +94,7 @@ func TestGetReadBucketCloserForBucketNoSubDirPath(t *testing.T) {

func TestGetReadBucketCloserForBucketAbs(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
absDirPath, err := filepath.Abs(".")
require.NoError(t, err)
inputBucket, err := storageos.NewProvider().NewReadWriteBucket(normalpath.Join(absDirPath, "testdata/bufyaml/one/two"))
Expand All @@ -118,7 +118,7 @@ func TestGetReadBucketCloserForBucketAbs(t *testing.T) {

func TestGetReadWriteBucketForOSNoTerminateFileName(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
readWriteBucket, bucketTargeting, err := getReadWriteBucketForOS(
ctx,
slogtestext.NewLogger(t),
Expand All @@ -138,7 +138,7 @@ func TestGetReadWriteBucketForOSNoTerminateFileName(t *testing.T) {

func TestGetReadWriteBucketForOSTerminateFileName(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
readWriteBucket, bucketTargeting, err := getReadWriteBucketForOS(
ctx,
slogtestext.NewLogger(t),
Expand All @@ -162,7 +162,7 @@ func TestGetReadWriteBucketForOSTerminateFileName(t *testing.T) {
func TestGetReadWriteBucketForOSParentPwd(t *testing.T) {
// Cannot be parallel since we chdir.

ctx := context.Background()
ctx := t.Context()
pwd, err := osext.Getwd()
require.NoError(t, err)
require.NoError(t, osext.Chdir(normalpath.Unnormalize(normalpath.Join(pwd, "testdata/bufyaml/one/two/three/four"))))
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestGetReadWriteBucketForOSParentPwd(t *testing.T) {
func TestGetReadWriteBucketForOSAbsPwd(t *testing.T) {
// Cannot be parallel since we chdir.

ctx := context.Background()
ctx := t.Context()
absDirPath, err := filepath.Abs(".")
require.NoError(t, err)
pwd, err := osext.Getwd()
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestGetReadWriteBucketForOSAbsPwd(t *testing.T) {

func TestGetReadBucketCloserForOSProtoFileNoWorkspaceTerminateFileName(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
readBucketCloser, bucketTargeting, err := getReadBucketCloserForOSProtoFile(
ctx,
slogtestext.NewLogger(t),
Expand All @@ -252,7 +252,7 @@ func TestGetReadBucketCloserForOSProtoFileNoWorkspaceTerminateFileName(t *testin

func TestGetReadBucketCloserForOSProtoFileTerminateFileName(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
readBucketCloser, bucketTargeting, err := getReadBucketCloserForOSProtoFile(
ctx,
slogtestext.NewLogger(t),
Expand All @@ -277,7 +277,7 @@ func TestGetReadBucketCloserForOSProtoFileTerminateFileName(t *testing.T) {
func TestGetReadBucketCloserForOSProtoFileParentPwd(t *testing.T) {
// Cannot be parallel since we chdir.

ctx := context.Background()
ctx := t.Context()
pwd, err := osext.Getwd()
require.NoError(t, err)
require.NoError(t, osext.Chdir(normalpath.Unnormalize(normalpath.Join(pwd, "testdata/bufyaml/one/two/three/four"))))
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestGetReadBucketCloserForOSProtoFileParentPwd(t *testing.T) {
func TestGetReadBucketCloserForOSProtoFileAbsPwd(t *testing.T) {
// Cannot be parallel since we chdir.

ctx := context.Background()
ctx := t.Context()
absDirPath, err := filepath.Abs(".")
require.NoError(t, err)
pwd, err := osext.Getwd()
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestGetReadBucketCloserForOSProtoFileAbsPwd(t *testing.T) {

func TestGetReadBucketCloserForOSProtoFileNoBufYAMLTerminateFileName(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
readBucketCloser, bucketTargeting, err := getReadBucketCloserForOSProtoFile(
ctx,
slogtestext.NewLogger(t),
Expand All @@ -370,7 +370,7 @@ func TestGetReadBucketCloserForOSProtoFileNoBufYAMLTerminateFileName(t *testing.
func TestGetReadBucketCloserForOSProtoFileNoBufYAMLParentPwd(t *testing.T) {
// Cannot be parallel since we chdir.

ctx := context.Background()
ctx := t.Context()
pwd, err := osext.Getwd()
require.NoError(t, err)
require.NoError(t, osext.Chdir(normalpath.Unnormalize(normalpath.Join(pwd, "testdata/nobufyaml/one/two/three/four"))))
Expand Down Expand Up @@ -406,7 +406,7 @@ func TestGetReadBucketCloserForOSProtoFileNoBufYAMLAbsPwd(t *testing.T) {
// Cannot be parallel since we chdir.
t.Skip()

ctx := context.Background()
ctx := t.Context()
absDirPath, err := filepath.Abs(".")
require.NoError(t, err)
pwd, err := osext.Getwd()
Expand Down
Loading