Skip to content

Commit

Permalink
all: get rid of testify package (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
igungor authored Jul 2, 2023
1 parent 9005f76 commit 168781a
Show file tree
Hide file tree
Showing 84 changed files with 1,618 additions and 21,080 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ jobs:
go-version: ${{ matrix.go-version }}

- run: make check-fmt
- run: go install github.com/golang/mock/[email protected]
- run: make check-codegen
- run: make vet
- run: go install honnef.co/go/tools/cmd/[email protected]
- run: make staticcheck
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ test_without_race:
@S5CMD_BUILD_BINARY_WITHOUT_RACE_FLAG=1 go test -mod=vendor -count=1 ./...

.PHONY: check
check: vet staticcheck unparam check-fmt
check: vet staticcheck unparam check-fmt check-codegen

.PHONY: staticcheck
staticcheck:
@staticcheck -checks 'all,-U1000,-ST1000,-ST1003' ./...
@staticcheck -checks 'all,-ST1000' ./...

.PHONY: unparam
unparam:
Expand All @@ -49,9 +49,13 @@ check-fmt:
exit 1;\
fi

.PHONY: mock
mock:
@mockery -inpkg -dir=storage -name=Storage -case=underscore
.PHONY: check-codegen
check-codegen: gogenerate ## Check generated code is up-to-date
@git diff --exit-code --

.PHONY: gogenerate
gogenerate:
@go generate -mod vendor ./...

.PHONY: clean
clean:
Expand Down
2 changes: 1 addition & 1 deletion command/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
)

func TestGuessContentType(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion command/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func expandSource(
}

ch := make(chan *storage.Object, 1)
if storage.ShouldProcessUrl(srcurl, followSymlinks) {
if storage.ShouldProcessURL(srcurl, followSymlinks) {
ch <- &storage.Object{URL: srcurl}
}
close(ch)
Expand Down
44 changes: 22 additions & 22 deletions command/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"sort"
"testing"

"github.com/stretchr/testify/assert"
"github.com/golang/mock/gomock"
"gotest.tools/v3/assert"
"gotest.tools/v3/fs"

"github.com/stretchr/testify/mock"

"github.com/peak/s5cmd/v2/storage"
"github.com/peak/s5cmd/v2/storage/url"
)
Expand Down Expand Up @@ -138,7 +137,8 @@ func TestExpandSources(t *testing.T) {
return
}

client := &storage.MockStorage{}
ctrl := gomock.NewController(t)
client := storage.NewMockStorage(ctrl)

for src, objects := range tc.src {
srcurl, err := url.New(src)
Expand All @@ -150,7 +150,7 @@ func TestExpandSources(t *testing.T) {
ch := generateObjects(objects)

if src != "s3://bucket/key" {
client.On("List", mock.Anything, srcurl, mock.Anything).Once().Return(ch)
client.EXPECT().List(gomock.Any(), srcurl, gomock.Any()).Times(1).Return(ch)
}
}

Expand All @@ -171,8 +171,6 @@ func TestExpandSources(t *testing.T) {
if !reflect.DeepEqual(objects, tc.wantObjects) {
t.Errorf("got = %v, want %v", objects, tc.wantObjects)
}

client.AssertExpectations(t)
})
}
}
Expand All @@ -193,16 +191,17 @@ func TestExpandSource_Follow_Link_To_Single_File(t *testing.T) {
defer workdir.Remove()

ctx := context.Background()
workdirUrl, _ := url.New(workdir.Join("b/my_link"))
workdirURL, _ := url.New(workdir.Join("b/my_link"))

//follow symbolic links
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), true, workdirUrl)
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), true, workdirURL)
var expected []string
for obj := range ch {
expected = append(expected, obj.URL.Absolute())
}
workdirJoin := filepath.ToSlash(workdir.Join("b/my_link"))
assert.Equal(t, []string{workdirJoin}, expected)

assert.DeepEqual(t, []string{workdirJoin}, expected)
}

func TestExpandSource_Do_Not_Follow_Link_To_Single_File(t *testing.T) {
Expand All @@ -221,15 +220,15 @@ func TestExpandSource_Do_Not_Follow_Link_To_Single_File(t *testing.T) {
defer workdir.Remove()

ctx := context.Background()
workdirUrl, _ := url.New(workdir.Join("b/my_link"))
workdirURL, _ := url.New(workdir.Join("b/my_link"))

//do not follow symbolic links
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), false, workdirUrl)
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), false, workdirURL)
var expected []string
for obj := range ch {
expected = append(expected, obj.URL.Absolute())
}
assert.Empty(t, expected)
assert.Assert(t, len(expected) == 0)
}

func TestExpandSource_Follow_Link_To_Directory(t *testing.T) {
Expand All @@ -251,16 +250,16 @@ func TestExpandSource_Follow_Link_To_Directory(t *testing.T) {
defer workdir.Remove()

ctx := context.Background()
workdirUrl, _ := url.New(workdir.Join("c/my_link"))
workdirURL, _ := url.New(workdir.Join("c/my_link"))

//follow symbolic links
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), true, workdirUrl)
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), true, workdirURL)
var expected []string
for obj := range ch {
expected = append(expected, obj.URL.Absolute())
}
sort.Strings(expected)
assert.Equal(t, []string{
assert.DeepEqual(t, []string{
filepath.ToSlash(workdir.Join("c/my_link/b/f3.txt")),
filepath.ToSlash(workdir.Join("c/my_link/f1.txt")),
filepath.ToSlash(workdir.Join("c/my_link/f2.txt")),
Expand All @@ -286,15 +285,16 @@ func TestExpandSource_Do_Not_Follow_Link_To_Directory(t *testing.T) {
defer workdir.Remove()

ctx := context.Background()
workdirUrl, _ := url.New(workdir.Join("c/my_link"))
workdirURL, _ := url.New(workdir.Join("c/my_link"))

//do not follow symbolic links
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), false, workdirUrl)
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), false, workdirURL)
var expected []string
for obj := range ch {
expected = append(expected, obj.URL.Absolute())
}
assert.Empty(t, expected)

assert.Assert(t, len(expected) == 0)
}

func TestExpandSource_Do_Not_Follow_Symlinks(t *testing.T) {
Expand All @@ -314,16 +314,16 @@ func TestExpandSource_Do_Not_Follow_Symlinks(t *testing.T) {
workdir := fs.NewDir(t, t.Name(), folderLayout...)
defer workdir.Remove()

workdirUrl, _ := url.New(workdir.Path())
workdirURL, _ := url.New(workdir.Path())

//do not follow symbolic links
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), false, workdirUrl)
ch, _ := expandSource(ctx, storage.NewLocalClient(storage.Options{}), false, workdirURL)
var expected []string
for obj := range ch {
expected = append(expected, obj.URL.Absolute())
}
workdirJoin := filepath.ToSlash(workdir.Join("a/f1.txt"))
assert.Equal(t, []string{workdirJoin}, expected)
assert.DeepEqual(t, []string{workdirJoin}, expected)
}

func keys(urls map[string][]*storage.Object) []string {
Expand Down
14 changes: 7 additions & 7 deletions e2e/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestAppProxy(t *testing.T) {
const expectedReqs = 1

proxy := httpProxy{}
pxyUrl := setupProxy(t, &proxy)
pxyURL := setupProxy(t, &proxy)

// set endpoint scheme to 'http'
if os.Getenv(s5cmdTestEndpointEnv) != "" {
Expand All @@ -173,7 +173,7 @@ func TestAppProxy(t *testing.T) {
}()
}

os.Setenv("http_proxy", pxyUrl)
os.Setenv("http_proxy", pxyURL)

_, s5cmd := setup(t, withProxy())

Expand Down Expand Up @@ -265,25 +265,25 @@ func TestAppEndpointShouldHaveScheme(t *testing.T) {

testcases := []struct {
name string
endpointUrl string
endpointURL string
expectedError error
expectedExitCode int
}{
{
name: "endpoint_with_http_scheme",
endpointUrl: "http://storage.googleapis.com",
endpointURL: "http://storage.googleapis.com",
expectedError: nil,
expectedExitCode: 0,
},
{
name: "endpoint_with_https_scheme",
endpointUrl: "https://storage.googleapis.com",
endpointURL: "https://storage.googleapis.com",
expectedError: nil,
expectedExitCode: 0,
},
{
name: "endpoint_with_no_scheme",
endpointUrl: "storage.googleapis.com",
endpointURL: "storage.googleapis.com",
expectedError: fmt.Errorf(`ERROR bad value for --endpoint-url storage.googleapis.com: scheme is missing. Must be of the form http://<hostname>/ or https://<hostname>/`),
expectedExitCode: 1,
},
Expand All @@ -296,7 +296,7 @@ func TestAppEndpointShouldHaveScheme(t *testing.T) {

_, s5cmd := setup(t)

cmd := s5cmd("--endpoint-url", tc.endpointUrl)
cmd := s5cmd("--endpoint-url", tc.endpointURL)
result := icmd.RunCmd(cmd)

result.Assert(t, icmd.Expected{ExitCode: tc.expectedExitCode})
Expand Down
4 changes: 2 additions & 2 deletions e2e/s3_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ func s3ServerEndpoint(t *testing.T, testdir *fs.Dir, loglvl, backend string, tim
})

if enableProxy {
parsedUrl, err := url.Parse(s3srv.URL)
parsedURL, err := url.Parse(s3srv.URL)
if err != nil {
t.Fatal(err)
}
proxyEnabledURL := "http://localhost.:" + parsedUrl.Port()
proxyEnabledURL := "http://localhost.:" + parsedURL.Port()
return proxyEnabledURL
}
return s3srv.URL
Expand Down
8 changes: 4 additions & 4 deletions e2e/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
// Don't use "race" flag in the build arguments.
testDisableRaceFlagKey = "S5CMD_BUILD_BINARY_WITHOUT_RACE_FLAG"
testDisableRaceFlagVal = "1"
s5cmdTestIdEnv = "S5CMD_ACCESS_KEY_ID"
s5cmdTestIDEnv = "S5CMD_ACCESS_KEY_ID"
s5cmdTestSecretEnv = "S5CMD_SECRET_ACCESS_KEY"
s5cmdTestEndpointEnv = "S5CMD_ENDPOINT_URL"
s5cmdTestIsVirtualHost = "S5CMD_IS_VIRTUAL_HOST"
Expand Down Expand Up @@ -189,7 +189,7 @@ func s3client(t *testing.T, options storage.Options) *s3.S3 {
// get environment variables and use external endpoint url.
// this can be used to test s3 sources such as GCS, amazon, wasabi etc.
if isEndpointFromEnv() {
id = os.Getenv(s5cmdTestIdEnv)
id = os.Getenv(s5cmdTestIDEnv)
key = os.Getenv(s5cmdTestSecretEnv)
endpoint = os.Getenv(s5cmdTestEndpointEnv)
region = os.Getenv(s5cmdTestRegionEnv)
Expand Down Expand Up @@ -249,7 +249,7 @@ func (c *slowDownRetryer) ShouldRetry(req *request.Request) bool {
}

func isEndpointFromEnv() bool {
return os.Getenv(s5cmdTestIdEnv) != "" &&
return os.Getenv(s5cmdTestIDEnv) != "" &&
os.Getenv(s5cmdTestSecretEnv) != "" &&
os.Getenv(s5cmdTestEndpointEnv) != "" &&
os.Getenv(s5cmdTestRegionEnv) != "" &&
Expand Down Expand Up @@ -281,7 +281,7 @@ func s5cmd(workdir, endpoint string) func(args ...string) icmd.Cmd {
secret := defaultSecretAccessKey

if isEndpointFromEnv() {
id = os.Getenv(s5cmdTestIdEnv)
id = os.Getenv(s5cmdTestIDEnv)
secret = os.Getenv(s5cmdTestSecretEnv)
env = append(
env,
Expand Down
9 changes: 3 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ go 1.17

require (
github.com/aws/aws-sdk-go v1.40.25
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.4.0
github.com/hashicorp/go-multierror v1.0.0
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/igungor/gofakes3 v0.0.13
github.com/karrick/godirwalk v1.15.3
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/lanrat/extsort v1.0.0
github.com/stretchr/testify v1.4.0
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae
github.com/urfave/cli/v2 v2.11.2
gotest.tools/v3 v3.0.2
Expand All @@ -24,18 +24,15 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect
github.com/shabbyrobe/gocovmerge v0.0.0-20180507124511-f6ea450bfb63 // indirect
github.com/stretchr/objx v0.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461 // indirect
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
golang.org/x/tools v0.1.1 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
Loading

0 comments on commit 168781a

Please sign in to comment.