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
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Inline test case structs for consistency.
- Use the correct assertion format overload.
- Always use testing `Setenv` with automatic cleanup.
- Makefile target for unit testing all modules.
- Various assertion consistency improvements.
- Use context from `testing.T` introduced in Go 1.24.
- Define more sentinel errors for more ergonomic error checking.

### Tests
- Use typed expectations consistently for added type safety.
### Style
### Fixed
- Use walrus assignment where possible.
- Use the `any` keyword where possible.

Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ lint/%:
@echo "Running golangci-lint in $*/"
@cd $* && golangci-lint run --build-tags=vfsintegration

.PHONY: test
test: $(addprefix test/,$(MODULES))
test/%:
@echo "Running tests in $*/"
@cd $* && go test ./...

.PHONY: install-go-test-coverage
install-go-test-coverage:
go install github.com/vladopajic/go-test-coverage/v2@latest
Expand Down
12 changes: 6 additions & 6 deletions backend/azure/client_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//go:build vfsintegration
// +build vfsintegration

package azure

import (
"context"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -38,23 +36,25 @@ func (s *ClientIntegrationTestSuite) SetupSuite() {
s.Require().NoError(err)
s.containerClient = cli

_, err = s.containerClient.Create(context.Background(), nil)
ctx := s.T().Context()

_, err = s.containerClient.Create(ctx, nil)
s.Require().NoError(err)

// The create function claims to be synchronous but for some reason it does not exist for a little bit so
// we need to wait for it to be there.
_, err = s.containerClient.GetProperties(context.Background(), nil)
_, err = s.containerClient.GetProperties(ctx, nil)
for {
time.Sleep(2 * time.Second)
if err == nil || !bloberror.HasCode(err, bloberror.BlobNotFound) {
break
}
_, err = s.containerClient.GetProperties(context.Background(), nil)
_, err = s.containerClient.GetProperties(ctx, nil)
}
}

func (s *ClientIntegrationTestSuite) TearDownSuite() {
_, err := s.containerClient.Delete(context.Background(), nil)
_, err := s.containerClient.Delete(s.T().Context(), nil)
s.Require().NoError(err)
}

Expand Down
2 changes: 1 addition & 1 deletion backend/azure/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (f *File) Delete(opts ...options.DeleteOption) error {
var allVersions bool
for _, o := range opts {
switch o.(type) {
case delete.AllVersions, delete.DeleteAllVersions:
case delete.AllVersions, delete.DeleteAllVersions: //nolint:staticcheck // TODO: remove when delete.DeleteAllVersions is removed
allVersions = true
default:
}
Expand Down
2 changes: 1 addition & 1 deletion backend/azure/fileSystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"errors"
"testing"

"github.com/c2fo/vfs/v7/utils"
"github.com/stretchr/testify/suite"

"github.com/c2fo/vfs/v7"
"github.com/c2fo/vfs/v7/backend/azure/mocks"
"github.com/c2fo/vfs/v7/utils"
)

type FileSystemTestSuite struct {
Expand Down
2 changes: 1 addition & 1 deletion backend/azure/location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"regexp"
"testing"

"github.com/c2fo/vfs/v7/utils"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"

"github.com/c2fo/vfs/v7"
"github.com/c2fo/vfs/v7/backend/azure/mocks"
"github.com/c2fo/vfs/v7/utils"
)

type LocationTestSuite struct {
Expand Down
20 changes: 10 additions & 10 deletions backend/ftp/dataconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *dataConnSuite) TestGetDataConn_alreadyExists() {
mode: types.OpenRead,
}
dc, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand All @@ -70,7 +70,7 @@ func (s *dataConnSuite) TestGetDataConn_openForRead() {
Return(&_ftp.Response{}, nil).
Once()
dc, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand All @@ -85,7 +85,7 @@ func (s *dataConnSuite) TestGetDataConn_errorClientSetup() {
defaultClientGetter = clientGetterReturnsError
s.ftpFile.Location().FileSystem().(*FileSystem).ftpclient = nil
dc, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand All @@ -108,7 +108,7 @@ func (s *dataConnSuite) TestGetDataConn_ReadError() {
Return(nil, someErr).
Once()
dc, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand All @@ -134,7 +134,7 @@ func (s *dataConnSuite) TestGetDataConn_WriteLocationNotExists() {
Return(nil).
Once()
_, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand All @@ -158,7 +158,7 @@ func (s *dataConnSuite) TestGetDataConn_WriteLocationNotExistsFails() {
Return(someerr).
Once()
_, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand Down Expand Up @@ -187,7 +187,7 @@ func (s *dataConnSuite) TestGetDataConn_errorWriting() {
Return(someErr).
Once()
dc, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand Down Expand Up @@ -215,7 +215,7 @@ func (s *dataConnSuite) TestGetDataConn_writeSuccess() {
Return(nil).
Once()
dc, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand All @@ -235,7 +235,7 @@ func (s *dataConnSuite) TestGetDataConn_readAfterWriteError() {
fakedconn.AssertCloseErr(closeErr)
s.ftpFile.Location().FileSystem().(*FileSystem).dataconn = fakedconn
dc, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand Down Expand Up @@ -265,7 +265,7 @@ func (s *dataConnSuite) TestGetDataConn_writeAfterReadSuccess() {
Return(nil).
Once()
dc, err := getDataConn(
context.Background(),
s.T().Context(),
authority.Authority{},
s.ftpFile.Location().FileSystem().(*FileSystem),
s.ftpFile,
Expand Down
3 changes: 1 addition & 2 deletions backend/ftp/fileSystem_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ftp

import (
"context"
"testing"

"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -128,7 +127,7 @@ func (ts *fileSystemTestSuite) TestWithOptions() {

func (ts *fileSystemTestSuite) TestClient() {
// client already set
client, err := ts.ftpfs.Client(context.Background(), authority.Authority{})
client, err := ts.ftpfs.Client(ts.T().Context(), authority.Authority{})
ts.Require().NoError(err, "no error")
ts.Equal(ts.ftpfs.ftpclient, client, "client was already set")
}
Expand Down
21 changes: 7 additions & 14 deletions backend/ftp/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ftp

import (
"bytes"
"context"
"crypto/tls"
"os"
"testing"
Expand Down Expand Up @@ -68,8 +67,7 @@ func (s *optionsSuite) TestFetchUsername() {
for _, test := range tests {
s.Run(test.description, func() {
if test.envVar != nil {
err := os.Setenv(envUsername, *test.envVar)
s.Require().NoError(err, test.description)
s.T().Setenv(envUsername, *test.envVar)
}

auth, err := authority.NewAuthority(test.authority)
Expand Down Expand Up @@ -120,8 +118,7 @@ func (s *optionsSuite) TestFetchPassword() {
for _, test := range tests { //nolint:gocritic //rangeValCopy but changing breaks ide integration for table-driven tests
s.Run(test.description, func() {
if test.envVar != nil {
err := os.Setenv(envPassword, *test.envVar)
s.Require().NoError(err, test.description)
s.T().Setenv(envPassword, *test.envVar)
}

password := fetchPassword(test.options)
Expand Down Expand Up @@ -155,8 +152,7 @@ func (s *optionsSuite) TestFetchHostPortString() {
s.Require().NoError(err, test.description)

if test.envVar != nil {
err := os.Setenv(envPassword, *test.envVar)
s.Require().NoError(err, test.description)
s.T().Setenv(envPassword, *test.envVar)
}

hostPortString := fetchHostPortString(auth)
Expand Down Expand Up @@ -238,8 +234,7 @@ func (s *optionsSuite) TestIsDisableEPSV() {
for _, test := range tests { //nolint:gocritic //rangeValCopy but changing breaks ide integration for table-driven tests
s.Run(test.description, func() {
if test.envVar != nil {
err := os.Setenv(envDisableEPSV, *test.envVar)
s.Require().NoError(err, test.description)
s.T().Setenv(envDisableEPSV, *test.envVar)
}

disabled := isDisableOption(test.options)
Expand Down Expand Up @@ -383,8 +378,7 @@ func (s *optionsSuite) TestFetchProtocol() {
s.Run(test.description, func() {
s.Require().NoError(os.Unsetenv(envProtocol))
if test.envVar != nil {
err := os.Setenv(envProtocol, *test.envVar)
s.Require().NoError(err, test.description)
s.T().Setenv(envProtocol, *test.envVar)
}

protocol := fetchProtocol(test.options)
Expand Down Expand Up @@ -471,14 +465,13 @@ func (s *optionsSuite) TestFetchDialOptions() {
for _, test := range tests {
s.Run(test.description, func() {
if test.envVar != nil {
err := os.Setenv(envProtocol, *test.envVar)
s.Require().NoError(err, test.description)
s.T().Setenv(envProtocol, *test.envVar)
}

auth, err := authority.NewAuthority(test.authority)
s.Require().NoError(err, test.description)

dialOpts := fetchDialOptions(context.Background(), auth, test.options)
dialOpts := fetchDialOptions(s.T().Context(), auth, test.options)
s.Len(dialOpts, test.expected, test.description)
})
}
Expand Down
2 changes: 1 addition & 1 deletion backend/gs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (f *File) Delete(opts ...options.DeleteOption) error {
var allVersions bool
for _, o := range opts {
switch o.(type) {
case delete.AllVersions, delete.DeleteAllVersions:
case delete.AllVersions, delete.DeleteAllVersions: //nolint:staticcheck // TODO: remove when delete.DeleteAllVersions is removed
allVersions = true
default:
}
Expand Down
Loading
Loading