forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from suyuan32/mg
Merge latest codes
- Loading branch information
Showing
9 changed files
with
164 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package stat | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
func TestBToMb(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
bytes uint64 | ||
expected float32 | ||
}{ | ||
{ | ||
name: "Test 1: Convert 0 bytes to MB", | ||
bytes: 0, | ||
expected: 0, | ||
}, | ||
{ | ||
name: "Test 2: Convert 1048576 bytes to MB", | ||
bytes: 1048576, | ||
expected: 1, | ||
}, | ||
{ | ||
name: "Test 3: Convert 2097152 bytes to MB", | ||
bytes: 2097152, | ||
expected: 2, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
result := bToMb(test.bytes) | ||
assert.Equal(t, test.expected, result) | ||
}) | ||
} | ||
} | ||
|
||
func TestPrintUsage(t *testing.T) { | ||
var buf bytes.Buffer | ||
writer := logx.NewWriter(&buf) | ||
old := logx.Reset() | ||
logx.SetWriter(writer) | ||
defer logx.SetWriter(old) | ||
|
||
printUsage() | ||
|
||
output := buf.String() | ||
assert.Contains(t, output, "CPU:") | ||
assert.Contains(t, output, "MEMORY:") | ||
assert.Contains(t, output, "Alloc=") | ||
assert.Contains(t, output, "TotalAlloc=") | ||
assert.Contains(t, output, "Sys=") | ||
assert.Contains(t, output, "NumGC=") | ||
|
||
lines := strings.Split(output, "\n") | ||
assert.Len(t, lines, 2) | ||
fields := strings.Split(lines[0], ", ") | ||
assert.Len(t, fields, 5) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package validation | ||
|
||
// Validator represents a validator. | ||
type Validator interface { | ||
// Validate validates the value. | ||
Validate() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters