mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-08-03 05:31:07 -04:00
* stat show json refactor
> will show {} since scripts should expect it, its the json style of blank value
* combine statistics commands to one
* code optimize
* fix runtime flag
* remove json indent
* change overridden to override
* api bi -json
* convert stdin support
code optimize
* writeRow() code optimize
add stats tittle
revert back to restartlogger
* api log -restart
* follow log
* codeql
* move -json to shared flags
* flags optimize
* update flag descriptions
* change "-v" of "api bo" to duration
* change "-expire" of "tls cert" to days
* cmds short description optimize
* fix multiple log followers
* Format loader refactor
* "infra/conf/merge" refactor
* "LoadConfig" refactor
* add "infra/conf/mergers"
* contribute to it will benifit `v2ray run`,`v2ray test`,`v2ray convert`
* easily add new formats, by just adding a converter like json.FromTOML
* default format auto, to all cmds above
* auto detect input format
* mixed formats support
* better stdin behavior
* don't wait if no content
* don't use 'stdin:' placeholder
* `v2ray test` now behaves exactly the same with `v2ray run`, including stdin reading
* api ado, adi, rmo, rmi refactor
* support folders to files resolving, mixed formats
* remove remaining 'stdin:' placeholders
* fix tests
* os.Stdin.Stat() behaves different in platforms, removed
* code optimize
Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
67 lines
1.2 KiB
Go
67 lines
1.2 KiB
Go
package units_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/units"
|
|
)
|
|
|
|
func TestByteSizes(t *testing.T) {
|
|
size := units.ByteSize(0)
|
|
assertSizeString(t, size, "0")
|
|
size++
|
|
assertSizeValue(t,
|
|
assertSizeString(t, size, "1.00B"),
|
|
size,
|
|
)
|
|
size <<= 10
|
|
assertSizeValue(t,
|
|
assertSizeString(t, size, "1.00KB"),
|
|
size,
|
|
)
|
|
size <<= 10
|
|
assertSizeValue(t,
|
|
assertSizeString(t, size, "1.00MB"),
|
|
size,
|
|
)
|
|
size <<= 10
|
|
assertSizeValue(t,
|
|
assertSizeString(t, size, "1.00GB"),
|
|
size,
|
|
)
|
|
size <<= 10
|
|
assertSizeValue(t,
|
|
assertSizeString(t, size, "1.00TB"),
|
|
size,
|
|
)
|
|
size <<= 10
|
|
assertSizeValue(t,
|
|
assertSizeString(t, size, "1.00PB"),
|
|
size,
|
|
)
|
|
size <<= 10
|
|
assertSizeValue(t,
|
|
assertSizeString(t, size, "1.00EB"),
|
|
size,
|
|
)
|
|
}
|
|
|
|
func assertSizeValue(t *testing.T, size string, expected units.ByteSize) {
|
|
actual := units.ByteSize(0)
|
|
err := actual.Parse(size)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if actual != expected {
|
|
t.Errorf("expect %s, but got %s", expected, actual)
|
|
}
|
|
}
|
|
|
|
func assertSizeString(t *testing.T, size units.ByteSize, expected string) string {
|
|
actual := size.String()
|
|
if actual != expected {
|
|
t.Errorf("expect %s, but got %s", expected, actual)
|
|
}
|
|
return expected
|
|
}
|