Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ _testmain.go
*.exe

.DS_Store

.idea/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not related. Please remove this change.

2 changes: 1 addition & 1 deletion mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func (m *Mock) Called(arguments ...interface{}) Arguments {
// For Ex: github_com_docker_libkv_store_mock.WatchTree.pN39_github_com_docker_libkv_store_mock.Mock
// uses interface information unlike golang github.com/docker/libkv/store/mock.(*Mock).WatchTree
// With GCCGO we need to remove interface information starting from pN<dd>.
re := regexp.MustCompile("\\.pN\\d+_")
re := regexp.MustCompile(`\.pN\d+_`)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not needed. This is just a quotes changes. While I agree that it improves redability, it has nothing to do in a MR that claims "code optimization". Please make a separate MR.

if re.MatchString(functionPath) {
functionPath = re.Split(functionPath, -1)[0]
}
Expand Down
16 changes: 7 additions & 9 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1624,9 +1624,7 @@ func TestIsArgsEqual(t *testing.T) {
assert.False(t, isArgsEqual(expected, args))

var arr = make([]interface{}, 6)
for i := 0; i < len(expected); i++ {
arr[i] = expected[i]
}
copy(arr, expected)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better:

// Clone expected into arr
arr := append(([]interface{})(nil), expected)

assert.True(t, isArgsEqual(expected, arr))
}

Expand Down Expand Up @@ -1939,20 +1937,20 @@ func TestLoggingAssertExpectations(t *testing.T) {
AssertExpectationsForObjects(tcl, m, new(TestExampleImplementation))

require.Equal(t, 1, len(tcl.errs))
assert.Regexp(t, regexp.MustCompile("(?s)FAIL: 0 out of 1 expectation\\(s\\) were met.*The code you are testing needs to make 1 more call\\(s\\).*"), tcl.errs[0])
assert.Regexp(t, regexp.MustCompile(`(?s)FAIL: 0 out of 1 expectation\(s\) were met.*The code you are testing needs to make 1 more call\(s\).*`), tcl.errs[0])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes quoting. This is an unrelated change.

require.Equal(t, 2, len(tcl.logs))
assert.Regexp(t, regexp.MustCompile("(?s)FAIL:\tGetTime\\(int\\).*"), tcl.logs[0])
assert.Regexp(t, regexp.MustCompile(`(?s)FAIL:\tGetTime\(int\).*`), tcl.logs[0])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes quoting. This is an unrelated change.

require.Equal(t, "Expectations didn't match for Mock: *mock.timer", tcl.logs[1])
}

func TestAfterTotalWaitTimeWhileExecution(t *testing.T) {
waitDuration := 1
total, waitMs := 5, time.Millisecond*time.Duration(waitDuration)
total, wait := 5, time.Millisecond*time.Duration(waitDuration)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes a variable name. This is an unrelated change. Remove it.

aTimer := new(timer)
for i := 0; i < total; i++ {
aTimer.On("GetTime", i).After(waitMs).Return(fmt.Sprintf("Time%d", i)).Once()
aTimer.On("GetTime", i).After(wait).Return(fmt.Sprintf("Time%d", i)).Once()
}
time.Sleep(waitMs)
time.Sleep(wait)
start := time.Now()
var results []string

Expand All @@ -1962,7 +1960,7 @@ func TestAfterTotalWaitTimeWhileExecution(t *testing.T) {

end := time.Now()
elapsedTime := end.Sub(start)
assert.True(t, elapsedTime > waitMs, fmt.Sprintf("Total elapsed time:%v should be atleast greater than %v", elapsedTime, waitMs))
assert.True(t, elapsedTime > wait, fmt.Sprintf("Total elapsed time:%v should be atleast greater than %v", elapsedTime, wait))
assert.Equal(t, total, len(results))
for i := range results {
assert.Equal(t, fmt.Sprintf("Time%d", i), results[i], "Return value of method should be same")
Expand Down
4 changes: 2 additions & 2 deletions suite/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"errors"
"flag"
"io/ioutil"
"io"
"math/rand"
"os"
"os/exec"
Expand Down Expand Up @@ -429,7 +429,7 @@ func (sc *StdoutCapture) StopCapture() (string, error) {
}
os.Stdout.Close()
os.Stdout = sc.oldStdout
bytes, err := ioutil.ReadAll(sc.readPipe)
bytes, err := io.ReadAll(sc.readPipe)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change requires Go 1.16. testify is used in a wide range of project. This is not a good thing to force users to upgrade Go while it is not necessary (io/ioutil will stay forever).

if err != nil {
return "", err
}
Expand Down