-
Notifications
You must be signed in to change notification settings - Fork 1.7k
code optimization #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code optimization #1386
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,3 +22,5 @@ _testmain.go | |
| *.exe | ||
|
|
||
| .DS_Store | ||
|
|
||
| .idea/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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+_`) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better: |
||
| assert.True(t, isArgsEqual(expected, arr)) | ||
| } | ||
|
|
||
|
|
@@ -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]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
|
@@ -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") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import ( | |
| "bytes" | ||
| "errors" | ||
| "flag" | ||
| "io/ioutil" | ||
| "io" | ||
| "math/rand" | ||
| "os" | ||
| "os/exec" | ||
|
|
@@ -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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change requires Go 1.16. |
||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.