From 02cc357b034b52f15778a7feb2ff42cf25ac1a75 Mon Sep 17 00:00:00 2001 From: k7a-tomohiro <83070078+k7a-tomohiro@users.noreply.github.com> Date: Tue, 21 Apr 2026 07:14:28 +0900 Subject: [PATCH 1/3] fix assert func args --- zcmp/cmp_test.go | 20 +- zcrypto/internal/copy_test.go | 14 +- zcrypto/internal/padding_test.go | 52 +- zcrypto/zaes/aes_test.go | 28 +- zcrypto/zaes/cbc_test.go | 48 +- zcrypto/zaes/cfb_test.go | 48 +- zcrypto/zaes/ctr_test.go | 60 +-- zcrypto/zaes/ecb_test.go | 48 +- zcrypto/zaes/gcm_test.go | 48 +- zcrypto/zaes/ofb_test.go | 60 +-- zcrypto/zargon2/argon2_test.go | 92 ++-- zcrypto/zbcrypt/bcrypt_test.go | 24 +- zcrypto/zblake2b/blake2b_test.go | 12 +- zcrypto/zblake2s/blake2s_test.go | 12 +- zcrypto/zchacha20/chacha20_test.go | 42 +- zcrypto/zdes/cbc_test.go | 48 +- zcrypto/zdes/cfb_test.go | 48 +- zcrypto/zdes/ctr_test.go | 72 +-- zcrypto/zdes/des_test.go | 30 +- zcrypto/zdes/ecb_test.go | 48 +- zcrypto/zdes/ofb_test.go | 72 +-- zcrypto/zhmac/hmac_test.go | 14 +- zcrypto/zmd4/md4_test.go | 12 +- zcrypto/zmd5/md5_test.go | 12 +- zcrypto/zpbkdf2/pbkdf2_test.go | 46 +- zcrypto/zrc4/rc4_test.go | 42 +- zcrypto/zripemd160/ripemd160_test.go | 12 +- zcrypto/zscrypt/scrypt_test.go | 50 +- zcrypto/zsha1/sha1_test.go | 12 +- zcrypto/zsha256/sha256_test.go | 12 +- zcrypto/zsha3/sha3_test.go | 12 +- zcrypto/zsha512/sha512_test.go | 12 +- zencoding/zxml/badgerfish_decode_test.go | 40 +- zencoding/zxml/badgerfish_encode_test.go | 38 +- zencoding/zxml/badgerfish_test.go | 4 +- zencoding/zxml/rayfish_decode_test.go | 42 +- zencoding/zxml/rayfish_encode_test.go | 56 +-- zencoding/zxml/rayfish_test.go | 4 +- zencoding/zxml/simple_decode_test.go | 44 +- zencoding/zxml/simple_encode_test.go | 38 +- zencoding/zxml/simple_test.go | 8 +- zencoding/zxml/tokenutil_test.go | 26 +- zerrors/err_test.go | 14 +- zerrors/error_test.go | 142 +++--- zerrors/frame_test.go | 10 +- zerrors/trace_test.go | 4 +- zerrors/util_test.go | 14 +- zhash/hash_test.go | 36 +- zhash/zcrc32/crc32_test.go | 12 +- zhash/zcrc64/crc64_test.go | 10 +- zhash/zfnv/fnv_test.go | 18 +- zio/copy_test.go | 24 +- zio/limit_test.go | 84 ++-- zio/reader_test.go | 80 +-- zlog/logicalfile_test.go | 78 +-- zlog/manager_test.go | 112 ++--- zlog/zslog/attr_test.go | 34 +- zlog/zslog/buildlog_test.go | 6 +- zlog/zslog/context_test.go | 38 +- zlog/zslog/logger_test.go | 72 +-- zmaps/maps_test.go | 4 +- zmath/set_internal_test.go | 6 +- zmath/set_test.go | 36 +- znet/allow_test.go | 16 +- znet/internal/server_test.go | 14 +- znet/internal/store_test.go | 26 +- znet/listener_test.go | 50 +- znet/net_test.go | 4 +- znet/resolver_test.go | 38 +- znet/zhttp/cookie_test.go | 58 +-- znet/zhttp/error_test.go | 36 +- znet/zhttp/header_test.go | 110 ++--- znet/zhttp/middleware_test.go | 28 +- znet/zhttp/proxy_test.go | 134 +++--- znet/zhttp/request_test.go | 76 +-- znet/zhttp/response_test.go | 40 +- znet/zhttp/runner_test.go | 14 +- znet/ztcp/proxy_test.go | 56 +-- znet/ztcp/runner_test.go | 14 +- znet/ztcp/server_test.go | 136 +++--- znet/zudp/conn_test.go | 44 +- znet/zudp/proxy_test.go | 60 +-- znet/zudp/runner_test.go | 14 +- znet/zudp/server_test.go | 128 ++--- zos/env_test.go | 44 +- zos/file_test.go | 94 ++-- zos/load_test.go | 112 ++--- zos/resolver_test.go | 116 ++--- zplugin/plugin_test.go | 50 +- zruntime/frame_test.go | 52 +- zruntime/report_test.go | 4 +- zruntime/zdebug/debug_internal_test.go | 12 +- zruntime/zdebug/debug_test.go | 14 +- zstrconv/strconv_internal_test.go | 4 +- zstrconv/strconv_test.go | 114 ++--- zstrings/counte_test.go | 4 +- zstrings/match_test.go | 18 +- zstrings/strings_test.go | 24 +- zsync/runner_test.go | 232 ++++----- zsync/store_test.go | 588 +++++++++++------------ zsyscall/sockopt_linux_test.go | 478 +++++++++--------- zsyscall/sockopt_others_test.go | 10 +- zsyscall/sockopt_test.go | 48 +- zsyscall/sockopt_windows_test.go | 118 ++--- ztesting/assert.go | 20 +- ztesting/assert_test.go | 36 +- ztesting/replace_test.go | 24 +- ztesting/ziotest/reader.go | 12 +- ztesting/ziotest/reader_test.go | 66 +-- ztesting/ziotest/writer_test.go | 48 +- ztext/template_test.go | 50 +- ztime/zbackoff/backoff_test.go | 89 ++-- ztime/zcron/cron_test.go | 34 +- ztime/zcron/crontab_test.go | 61 ++- ztime/zrate/bucket_test.go | 106 ++-- ztime/zrate/concurrent_test.go | 46 +- ztime/zrate/leaky_test.go | 50 +- ztime/zrate/rate_test.go | 20 +- ztime/zrate/sliding_test.go | 30 +- zx/zlb/basic_test.go | 56 +-- zx/zlb/direct_test.go | 12 +- zx/zlb/jump_test.go | 6 +- zx/zlb/lb_test.go | 100 ++-- zx/zlb/maglev_internal_test.go | 5 +- zx/zlb/maglev_test.go | 38 +- zx/zlb/priority_test.go | 16 +- zx/zlb/random_test.go | 8 +- zx/zlb/rendezvous_test.go | 30 +- zx/zlb/ring_test.go | 44 +- zx/zlb/roundrobin_test.go | 32 +- zx/ztext/ztransform/transform_test.go | 20 +- zx/zuid/context_test.go | 14 +- zx/zuid/uid_test.go | 22 +- 133 files changed, 3308 insertions(+), 3315 deletions(-) diff --git a/zcmp/cmp_test.go b/zcmp/cmp_test.go index 0451946..61d97f9 100644 --- a/zcmp/cmp_test.go +++ b/zcmp/cmp_test.go @@ -13,11 +13,11 @@ func TestTrue(t *testing.T) { t.Run("test int", func(t *testing.T) { t.Run("true", func(t *testing.T) { v := zcmp.True(true, 1, 2) - ztesting.AssertEqual(t, "invalid response value.", 1, v) + ztesting.AssertEqual(t, 1, v) }) t.Run("false", func(t *testing.T) { v := zcmp.True(false, 1, 2) - ztesting.AssertEqual(t, "invalid response value.", 2, v) + ztesting.AssertEqual(t, 2, v) }) }) @@ -25,12 +25,12 @@ func TestTrue(t *testing.T) { t.Run("true", func(t *testing.T) { var np *struct{} v := zcmp.True(true, nil, np) - ztesting.AssertEqual(t, "invalid response value.", nil, v) + ztesting.AssertEqual(t, nil, v) }) t.Run("false", func(t *testing.T) { var np *struct{} v := zcmp.True(false, nil, np) - ztesting.AssertEqual(t, "invalid response value.", np, v) + ztesting.AssertEqual(t, np, v) }) }) } @@ -41,11 +41,11 @@ func TestFalse(t *testing.T) { t.Run("test int", func(t *testing.T) { t.Run("false", func(t *testing.T) { v := zcmp.False(false, 1, 2) - ztesting.AssertEqual(t, "invalid response value.", 1, v) + ztesting.AssertEqual(t, 1, v) }) t.Run("true", func(t *testing.T) { v := zcmp.False(true, 1, 2) - ztesting.AssertEqual(t, "invalid response value.", 2, v) + ztesting.AssertEqual(t, 2, v) }) }) @@ -53,12 +53,12 @@ func TestFalse(t *testing.T) { t.Run("false", func(t *testing.T) { var np *struct{} v := zcmp.False(false, nil, np) - ztesting.AssertEqual(t, "invalid response value.", nil, v) + ztesting.AssertEqual(t, nil, v) }) t.Run("true", func(t *testing.T) { var np *struct{} v := zcmp.False(true, nil, np) - ztesting.AssertEqual(t, "invalid response value.", np, v) + ztesting.AssertEqual(t, np, v) }) }) } @@ -93,7 +93,7 @@ func TestOrSlice(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { v := zcmp.OrSlice(tc.vals...) - ztesting.AssertEqual(t, "wrong element returned.", tc.want, v) + ztesting.AssertEqual(t, tc.want, v) }) } } @@ -128,7 +128,7 @@ func TestOrMap(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { v := zcmp.OrMap(tc.vals...) - ztesting.AssertEqual(t, "wrong element returned.", tc.want, v) + ztesting.AssertEqual(t, tc.want, v) }) } } diff --git a/zcrypto/internal/copy_test.go b/zcrypto/internal/copy_test.go index 53d1af2..dc28cf5 100644 --- a/zcrypto/internal/copy_test.go +++ b/zcrypto/internal/copy_test.go @@ -23,11 +23,11 @@ func TestCopy(t *testing.T) { s := cipher.NewCTR(c, iv) var w, ww bytes.Buffer err := internal.Copy(s, &w, strings.NewReader("test")) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "message unexpectedly match", false, w.String() == "test") + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, false, w.String() == "test") err = zaes.CopyOFB(key, iv, &ww, strings.NewReader(w.String())) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "message not match", "test", ww.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "test", ww.String()) }) t.Run("read error", func(t *testing.T) { key := []byte("1234567890123456") @@ -36,7 +36,7 @@ func TestCopy(t *testing.T) { s := cipher.NewCTR(c, iv) var w bytes.Buffer err := internal.Copy(s, &w, ziotest.ErrReader(strings.NewReader("test"), 3)) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, err) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, err) }) t.Run("write error", func(t *testing.T) { key := []byte("1234567890123456") @@ -45,7 +45,7 @@ func TestCopy(t *testing.T) { s := cipher.NewCTR(c, iv) var w bytes.Buffer err := internal.Copy(s, ziotest.ErrWriter(&w, 3), strings.NewReader("test")) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, err) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, err) }) t.Run("short write error", func(t *testing.T) { key := []byte("1234567890123456") @@ -54,6 +54,6 @@ func TestCopy(t *testing.T) { s := cipher.NewCTR(c, iv) var w bytes.Buffer err := internal.Copy(s, ziotest.ShortWriter(&w, 3), strings.NewReader("test")) - ztesting.AssertEqualErr(t, "error not match", io.ErrShortWrite, err) + ztesting.AssertEqualErr(t, io.ErrShortWrite, err) }) } diff --git a/zcrypto/internal/padding_test.go b/zcrypto/internal/padding_test.go index e4587dd..892d2a0 100644 --- a/zcrypto/internal/padding_test.go +++ b/zcrypto/internal/padding_test.go @@ -93,12 +93,12 @@ func TestPadPKCS7(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { b, err := internal.PadPKCS7(tc.blockSize, tc.data) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) - ztesting.AssertEqual(t, "data not match", tc.want, b) + ztesting.AssertEqualErr(t, tc.err, err) + ztesting.AssertEqual(t, tc.want, b) if len(b) > 0 { bb, err := internal.UnpadPKCS7(tc.blockSize, b) - ztesting.AssertEqualErr(t, "non nil error", nil, err) - ztesting.AssertEqual(t, "data not match", tc.data, bb) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.data, bb) } }) } @@ -182,12 +182,12 @@ func TestUnpadPKCS7(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { b, err := internal.UnpadPKCS7(tc.blockSize, tc.data) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) - ztesting.AssertEqual(t, "data not match", tc.want, b) + ztesting.AssertEqualErr(t, tc.err, err) + ztesting.AssertEqual(t, tc.want, b) if tc.err == nil { bb, err := internal.PadPKCS7(tc.blockSize, b) - ztesting.AssertEqualErr(t, "non nil error", nil, err) - ztesting.AssertEqual(t, "data not match", tc.data, bb) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.data, bb) } }) } @@ -268,12 +268,12 @@ func TestPadISO7816(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { b, err := internal.PadISO7816(tc.blockSize, tc.data) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) - ztesting.AssertEqual(t, "data not match", tc.want, b) + ztesting.AssertEqualErr(t, tc.err, err) + ztesting.AssertEqual(t, tc.want, b) if len(b) > 0 { bb, err := internal.UnpadISO7816(tc.blockSize, b) - ztesting.AssertEqualErr(t, "non nil error", nil, err) - ztesting.AssertEqual(t, "data not match", tc.data, bb) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.data, bb) } }) } @@ -357,12 +357,12 @@ func TestUnpadISO7816(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { b, err := internal.UnpadISO7816(tc.blockSize, tc.data) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) - ztesting.AssertEqual(t, "data not match", tc.want, b) + ztesting.AssertEqualErr(t, tc.err, err) + ztesting.AssertEqual(t, tc.want, b) if tc.err == nil { bb, err := internal.PadISO7816(tc.blockSize, b) - ztesting.AssertEqualErr(t, "non nil error", nil, err) - ztesting.AssertEqual(t, "data not match", tc.data, bb) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.data, bb) } }) } @@ -444,12 +444,12 @@ func TestPadISO10126(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { b, err := internal.PadISO10126(tc.blockSize, tc.data) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) - ztesting.AssertEqual(t, "data not match", tc.want, b) + ztesting.AssertEqualErr(t, tc.err, err) + ztesting.AssertEqual(t, tc.want, b) if len(b) > 0 { bb, err := internal.UnpadISO10126(tc.blockSize, b) - ztesting.AssertEqualErr(t, "non nil error", nil, err) - ztesting.AssertEqual(t, "data not match", tc.data, bb) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.data, bb) } }) } @@ -459,8 +459,8 @@ func TestPadISO10126_ReadError(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("1")) defer done() b, err := internal.PadISO10126(10, []byte("12345")) - ztesting.AssertEqualErr(t, "error not match", io.ErrUnexpectedEOF, err) - ztesting.AssertEqual(t, "data not match", nil, b) + ztesting.AssertEqualErr(t, io.ErrUnexpectedEOF, err) + ztesting.AssertEqual(t, nil, b) } func TestUnpadISO10126(t *testing.T) { @@ -541,12 +541,12 @@ func TestUnpadISO10126(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { b, err := internal.UnpadISO10126(tc.blockSize, tc.data) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) - ztesting.AssertEqual(t, "data not match", tc.want, b) + ztesting.AssertEqualErr(t, tc.err, err) + ztesting.AssertEqual(t, tc.want, b) if tc.err == nil { bb, err := internal.PadISO10126(tc.blockSize, b) - ztesting.AssertEqualErr(t, "non nil error", nil, err) - ztesting.AssertEqual(t, "data not match", tc.data, bb) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.data, bb) } }) } diff --git a/zcrypto/zaes/aes_test.go b/zcrypto/zaes/aes_test.go index 64524d9..38db5ef 100644 --- a/zcrypto/zaes/aes_test.go +++ b/zcrypto/zaes/aes_test.go @@ -13,31 +13,31 @@ import ( func TestErrCipherLength(t *testing.T) { t.Parallel() e := ErrCipherLength(1) - ztesting.AssertEqual(t, "message not match", "zaes: incorrect ciphertext length. got:1", e.Error()) + ztesting.AssertEqual(t, "zaes: incorrect ciphertext length. got:1", e.Error()) } func TestNewAES(t *testing.T) { t.Parallel() t.Run("invalid key", func(t *testing.T) { cb, iv, err := newAES([]byte("short")) - ztesting.AssertEqualErr(t, "unexpected error", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "non nil cipher block returned", nil, cb) - ztesting.AssertEqual(t, "non empty iv returned", nil, iv) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, cb) + ztesting.AssertEqual(t, nil, iv) }) t.Run("16 bytes key", func(t *testing.T) { _, iv, err := newAES([]byte("1234567890123456")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) - ztesting.AssertEqual(t, "iv length invalid", 16, len(iv)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 16, len(iv)) }) t.Run("24 bytes key", func(t *testing.T) { _, iv, err := newAES([]byte("123456789012345678901234")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) - ztesting.AssertEqual(t, "iv length invalid", 16, len(iv)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 16, len(iv)) }) t.Run("32 bytes key", func(t *testing.T) { _, iv, err := newAES([]byte("12345678901234567890123456789012")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) - ztesting.AssertEqual(t, "iv length invalid", 16, len(iv)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 16, len(iv)) }) } @@ -77,14 +77,14 @@ func TestEncryptDecrypt(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("abcdefghijklmnop")) defer done() ciphertext, err := tc.enc([]byte(tc.key), []byte(tc.plain)) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "ciphertext not match", tc.cipher, hex.EncodeToString(ciphertext)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.cipher, hex.EncodeToString(ciphertext)) }) t.Run(tc.name+"_decrypt", func(t *testing.T) { cipher, _ := hex.DecodeString(tc.cipher) plain, err := tc.dec([]byte(tc.key), cipher) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "plaintext not match", tc.plain, string(plain)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.plain, string(plain)) }) } } diff --git a/zcrypto/zaes/cbc_test.go b/zcrypto/zaes/cbc_test.go index a3d9d20..8528000 100644 --- a/zcrypto/zaes/cbc_test.go +++ b/zcrypto/zaes/cbc_test.go @@ -13,70 +13,70 @@ func TestCBC(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zaes.EncryptCBC(key, nil) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zaes.DecryptCBC(key, []byte("1234567890123456")) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("1234567890123456") plaintext, err := zaes.DecryptCBC(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zaes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zaes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("AES128: encrypt-decrypt empty", func(t *testing.T) { key := []byte("1234567890123456") ciphertext, err := zaes.EncryptCBC(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCBC(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES128: encrypt-decrypt", func(t *testing.T) { key := []byte("1234567890123456") msg := []byte("test message") ciphertext, err := zaes.EncryptCBC(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCBC(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES192: encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456789012345678901234") ciphertext, err := zaes.EncryptCBC(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCBC(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES192: encrypt-decrypt", func(t *testing.T) { key := []byte("123456789012345678901234") msg := []byte("test message") ciphertext, err := zaes.EncryptCBC(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCBC(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES256: encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678901234567890123456789012") ciphertext, err := zaes.EncryptCBC(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCBC(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES256: encrypt-decrypt", func(t *testing.T) { key := []byte("12345678901234567890123456789012") msg := []byte("test message") ciphertext, err := zaes.EncryptCBC(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCBC(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } diff --git a/zcrypto/zaes/cfb_test.go b/zcrypto/zaes/cfb_test.go index 326c0a2..f76e93a 100644 --- a/zcrypto/zaes/cfb_test.go +++ b/zcrypto/zaes/cfb_test.go @@ -13,70 +13,70 @@ func TestCFB(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zaes.EncryptCFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zaes.DecryptCFB(key, []byte("1234567890123456")) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("1234567890123456") plaintext, err := zaes.DecryptCFB(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zaes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zaes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("AES128: encrypt-decrypt empty", func(t *testing.T) { key := []byte("1234567890123456") ciphertext, err := zaes.EncryptCFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES128: encrypt-decrypt", func(t *testing.T) { key := []byte("1234567890123456") msg := []byte("test message") ciphertext, err := zaes.EncryptCFB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES192: encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456789012345678901234") ciphertext, err := zaes.EncryptCFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES192: encrypt-decrypt", func(t *testing.T) { key := []byte("123456789012345678901234") msg := []byte("test message") ciphertext, err := zaes.EncryptCFB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES256: encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678901234567890123456789012") ciphertext, err := zaes.EncryptCFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES256: encrypt-decrypt", func(t *testing.T) { key := []byte("12345678901234567890123456789012") msg := []byte("test message") ciphertext, err := zaes.EncryptCFB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } diff --git a/zcrypto/zaes/ctr_test.go b/zcrypto/zaes/ctr_test.go index 8102d63..93353d1 100644 --- a/zcrypto/zaes/ctr_test.go +++ b/zcrypto/zaes/ctr_test.go @@ -15,71 +15,71 @@ func TestCTR(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zaes.EncryptCTR(key, nil) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zaes.DecryptCTR(key, []byte("1234567890123456")) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("1234567890123456") plaintext, err := zaes.DecryptCTR(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zaes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zaes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("AES128: encrypt-decrypt empty", func(t *testing.T) { key := []byte("1234567890123456") ciphertext, err := zaes.EncryptCTR(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCTR(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES128: encrypt-decrypt", func(t *testing.T) { key := []byte("1234567890123456") msg := []byte("test message") ciphertext, err := zaes.EncryptCTR(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCTR(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES192: encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456789012345678901234") ciphertext, err := zaes.EncryptCTR(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCTR(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES192: encrypt-decrypt", func(t *testing.T) { key := []byte("123456789012345678901234") msg := []byte("test message") ciphertext, err := zaes.EncryptCTR(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCTR(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES256: encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678901234567890123456789012") ciphertext, err := zaes.EncryptCTR(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCTR(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES256: encrypt-decrypt", func(t *testing.T) { key := []byte("12345678901234567890123456789012") msg := []byte("test message") ciphertext, err := zaes.EncryptCTR(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptCTR(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } @@ -89,7 +89,7 @@ func TestCopyCTR(t *testing.T) { key := []byte("short") iv := []byte("1234567890123456") err := zaes.CopyCTR(key, iv, nil, nil) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("1234567890123456") @@ -97,11 +97,11 @@ func TestCopyCTR(t *testing.T) { msg := "test message" var w, ww bytes.Buffer err := zaes.CopyCTR(key, iv, &w, strings.NewReader(msg)) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "length not match", len(msg), w.Len()) - ztesting.AssertEqual(t, "message unexpectedly match", false, msg == w.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, len(msg), w.Len()) + ztesting.AssertEqual(t, false, msg == w.String()) err = zaes.CopyCTR(key, iv, &ww, strings.NewReader(w.String())) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "message not match", msg, ww.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, ww.String()) }) } diff --git a/zcrypto/zaes/ecb_test.go b/zcrypto/zaes/ecb_test.go index c89e460..3670d61 100644 --- a/zcrypto/zaes/ecb_test.go +++ b/zcrypto/zaes/ecb_test.go @@ -13,70 +13,70 @@ func TestECB(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zaes.EncryptECB(key, nil) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zaes.DecryptECB(key, []byte("1234567890123456")) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("1234567890123456") plaintext, err := zaes.DecryptECB(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zaes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zaes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("AES128: encrypt-decrypt empty", func(t *testing.T) { key := []byte("1234567890123456") ciphertext, err := zaes.EncryptECB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptECB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES128: encrypt-decrypt", func(t *testing.T) { key := []byte("1234567890123456") msg := []byte("test message") ciphertext, err := zaes.EncryptECB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptECB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES192: encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456789012345678901234") ciphertext, err := zaes.EncryptECB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptECB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES192: encrypt-decrypt", func(t *testing.T) { key := []byte("123456789012345678901234") msg := []byte("test message") ciphertext, err := zaes.EncryptECB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptECB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES256: encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678901234567890123456789012") ciphertext, err := zaes.EncryptECB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptECB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES256: encrypt-decrypt", func(t *testing.T) { key := []byte("12345678901234567890123456789012") msg := []byte("test message") ciphertext, err := zaes.EncryptECB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptECB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } diff --git a/zcrypto/zaes/gcm_test.go b/zcrypto/zaes/gcm_test.go index b3ef669..1f85f28 100644 --- a/zcrypto/zaes/gcm_test.go +++ b/zcrypto/zaes/gcm_test.go @@ -13,70 +13,70 @@ func TestGCM(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zaes.EncryptGCM(key, nil) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zaes.DecryptGCM(key, []byte("1234567890123456")) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("1234567890123456") plaintext, err := zaes.DecryptGCM(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zaes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zaes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("AES128: encrypt-decrypt empty", func(t *testing.T) { key := []byte("1234567890123456") ciphertext, err := zaes.EncryptGCM(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptGCM(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", nil, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("AES128: encrypt-decrypt", func(t *testing.T) { key := []byte("1234567890123456") msg := []byte("test message") ciphertext, err := zaes.EncryptGCM(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptGCM(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES192: encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456789012345678901234") ciphertext, err := zaes.EncryptGCM(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptGCM(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", nil, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("AES192: encrypt-decrypt", func(t *testing.T) { key := []byte("123456789012345678901234") msg := []byte("test message") ciphertext, err := zaes.EncryptGCM(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptGCM(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES256: encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678901234567890123456789012") ciphertext, err := zaes.EncryptGCM(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptGCM(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", nil, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("AES256: encrypt-decrypt", func(t *testing.T) { key := []byte("12345678901234567890123456789012") msg := []byte("test message") ciphertext, err := zaes.EncryptGCM(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptGCM(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } diff --git a/zcrypto/zaes/ofb_test.go b/zcrypto/zaes/ofb_test.go index 11027cb..e95c9c8 100644 --- a/zcrypto/zaes/ofb_test.go +++ b/zcrypto/zaes/ofb_test.go @@ -15,71 +15,71 @@ func TestOFB(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zaes.EncryptOFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zaes.DecryptOFB(key, []byte("1234567890123456")) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("1234567890123456") plaintext, err := zaes.DecryptOFB(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zaes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zaes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("AES128: encrypt-decrypt empty", func(t *testing.T) { key := []byte("1234567890123456") ciphertext, err := zaes.EncryptOFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptOFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES128: encrypt-decrypt", func(t *testing.T) { key := []byte("1234567890123456") msg := []byte("test message") ciphertext, err := zaes.EncryptOFB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptOFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES192: encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456789012345678901234") ciphertext, err := zaes.EncryptOFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptOFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES192: encrypt-decrypt", func(t *testing.T) { key := []byte("123456789012345678901234") msg := []byte("test message") ciphertext, err := zaes.EncryptOFB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptOFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) t.Run("AES256: encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678901234567890123456789012") ciphertext, err := zaes.EncryptOFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptOFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("AES256: encrypt-decrypt", func(t *testing.T) { key := []byte("12345678901234567890123456789012") msg := []byte("test message") ciphertext, err := zaes.EncryptOFB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zaes.DecryptOFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } @@ -89,7 +89,7 @@ func TestCopyOFB(t *testing.T) { key := []byte("short") iv := []byte("1234567890123456") err := zaes.CopyOFB(key, iv, nil, nil) - ztesting.AssertEqualErr(t, "error not match", aes.KeySizeError(5), err) + ztesting.AssertEqualErr(t, aes.KeySizeError(5), err) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("1234567890123456") @@ -97,11 +97,11 @@ func TestCopyOFB(t *testing.T) { msg := "test message" var w, ww bytes.Buffer err := zaes.CopyOFB(key, iv, &w, strings.NewReader(msg)) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "length not match", len(msg), w.Len()) - ztesting.AssertEqual(t, "message unexpectedly match", false, msg == w.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, len(msg), w.Len()) + ztesting.AssertEqual(t, false, msg == w.String()) err = zaes.CopyOFB(key, iv, &ww, strings.NewReader(w.String())) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "message not match", msg, ww.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, ww.String()) }) } diff --git a/zcrypto/zargon2/argon2_test.go b/zcrypto/zargon2/argon2_test.go index a2d325c..e55c15f 100644 --- a/zcrypto/zargon2/argon2_test.go +++ b/zcrypto/zargon2/argon2_test.go @@ -15,14 +15,14 @@ func TestNewArgon2i(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zargon2.NewArgon2i(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "hash not match", "31323334353637383930b73fc562d7f71262bb4099efad0d836c5e0496788c840c33cef2d90ef992e060", hex.EncodeToString(h)) + ztesting.AssertEqual(t, "31323334353637383930b73fc562d7f71262bb4099efad0d836c5e0496788c840c33cef2d90ef992e060", hex.EncodeToString(h)) }) t.Run("invalid param", func(t *testing.T) { b, err := zargon2.NewArgon2i(10, 0, 64*1024, 4, 32) - ztesting.AssertEqual(t, "non nil hasher returned", nil, b) - ztesting.AssertEqualErr(t, "nil error returned", errors.New("zargon2: invalid hash parameter [argon2: number of rounds too small]"), err) + ztesting.AssertEqual(t, nil, b) + ztesting.AssertEqualErr(t, errors.New("zargon2: invalid hash parameter [argon2: number of rounds too small]"), err) }) } @@ -31,48 +31,48 @@ func TestNewArgon2id(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zargon2.NewArgon2id(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "hash not match", "3132333435363738393046a3090e30874ea4dd680f04ee9bbb3ab0a01421de4fbe845649db192db746b3", hex.EncodeToString(h)) + ztesting.AssertEqual(t, "3132333435363738393046a3090e30874ea4dd680f04ee9bbb3ab0a01421de4fbe845649db192db746b3", hex.EncodeToString(h)) }) t.Run("invalid param", func(t *testing.T) { b, err := zargon2.NewArgon2id(10, 0, 64*1024, 4, 32) - ztesting.AssertEqual(t, "non nil hasher returned", nil, b) - ztesting.AssertEqualErr(t, "nil error returned", errors.New("zargon2: invalid hash parameter [argon2: number of rounds too small]"), err) + ztesting.AssertEqual(t, nil, b) + ztesting.AssertEqualErr(t, errors.New("zargon2: invalid hash parameter [argon2: number of rounds too small]"), err) }) } func TestArgon2i_Split(t *testing.T) { t.Run("short hash", func(t *testing.T) { b, err := zargon2.NewArgon2i(32, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) _, _, err = b.Split([]byte("short hash")) - ztesting.AssertEqualErr(t, "error not returned", zargon2.ErrShortHash, err) + ztesting.AssertEqualErr(t, zargon2.ErrShortHash, err) }) t.Run("split hash", func(t *testing.T) { b, err := zargon2.NewArgon2i(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) salt, hash, err := b.Split([]byte("1234567890abcdefghijklmnopqrstuvwxyz")) - ztesting.AssertEqualErr(t, "non-nil error returned", nil, err) - ztesting.AssertEqual(t, "incorrect salt", "1234567890", string(salt)) - ztesting.AssertEqual(t, "incorrect hash", "abcdefghijklmnopqrstuvwxyz", string(hash)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "1234567890", string(salt)) + ztesting.AssertEqual(t, "abcdefghijklmnopqrstuvwxyz", string(hash)) }) } func TestArgon2id_Split(t *testing.T) { t.Run("short hash", func(t *testing.T) { b, err := zargon2.NewArgon2id(32, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) _, _, err = b.Split([]byte("short hash")) - ztesting.AssertEqualErr(t, "error not returned", zargon2.ErrShortHash, err) + ztesting.AssertEqualErr(t, zargon2.ErrShortHash, err) }) t.Run("split hash", func(t *testing.T) { b, err := zargon2.NewArgon2id(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) salt, hash, err := b.Split([]byte("1234567890abcdefghijklmnopqrstuvwxyz")) - ztesting.AssertEqualErr(t, "non-nil error returned", nil, err) - ztesting.AssertEqual(t, "incorrect salt", "1234567890", string(salt)) - ztesting.AssertEqual(t, "incorrect hash", "abcdefghijklmnopqrstuvwxyz", string(hash)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "1234567890", string(salt)) + ztesting.AssertEqual(t, "abcdefghijklmnopqrstuvwxyz", string(hash)) }) } @@ -83,9 +83,9 @@ func TestArgon2i_Sum(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zargon2.NewArgon2i(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "hash not match", "31323334353637383930b73fc562d7f71262bb4099efad0d836c5e0496788c840c33cef2d90ef992e060", hex.EncodeToString(h)) + ztesting.AssertEqual(t, "31323334353637383930b73fc562d7f71262bb4099efad0d836c5e0496788c840c33cef2d90ef992e060", hex.EncodeToString(h)) }) } @@ -96,9 +96,9 @@ func TestArgon2id_Sum(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zargon2.NewArgon2id(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "hash not match", "3132333435363738393046a3090e30874ea4dd680f04ee9bbb3ab0a01421de4fbe845649db192db746b3", hex.EncodeToString(h)) + ztesting.AssertEqual(t, "3132333435363738393046a3090e30874ea4dd680f04ee9bbb3ab0a01421de4fbe845649db192db746b3", hex.EncodeToString(h)) }) } @@ -107,10 +107,10 @@ func TestArgon2i_Equal(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zargon2.NewArgon2i(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "incorrect equal result", true, b.Equal(h, []byte("test"))) - ztesting.AssertEqual(t, "incorrect equal result", false, b.Equal(h, []byte("wrong"))) + ztesting.AssertEqual(t, true, b.Equal(h, []byte("test"))) + ztesting.AssertEqual(t, false, b.Equal(h, []byte("wrong"))) }) } @@ -119,59 +119,59 @@ func TestArgon2id_Equal(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zargon2.NewArgon2id(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "incorrect equal result", true, b.Equal(h, []byte("test"))) - ztesting.AssertEqual(t, "incorrect equal result", false, b.Equal(h, []byte("wrong"))) + ztesting.AssertEqual(t, true, b.Equal(h, []byte("test"))) + ztesting.AssertEqual(t, false, b.Equal(h, []byte("wrong"))) }) } func TestArgon2i_Compare(t *testing.T) { t.Run("short hash", func(t *testing.T) { b, err := zargon2.NewArgon2i(32, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare([]byte("short hash"), []byte("test")) - ztesting.AssertEqualErr(t, "error not returned", zargon2.ErrShortHash, err) + ztesting.AssertEqualErr(t, zargon2.ErrShortHash, err) }) t.Run("pw not match", func(t *testing.T) { b, err := zargon2.NewArgon2i(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, err := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare(h, []byte("wrong")) - ztesting.AssertEqualErr(t, "error not matched", zargon2.ErrNotMatch, err) + ztesting.AssertEqualErr(t, zargon2.ErrNotMatch, err) }) t.Run("pw match", func(t *testing.T) { b, err := zargon2.NewArgon2i(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, err := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare(h, []byte("test")) - ztesting.AssertEqualErr(t, "error not matched", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) } func TestArgon2id_Compare(t *testing.T) { t.Run("short hash", func(t *testing.T) { b, err := zargon2.NewArgon2id(32, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare([]byte("short hash"), []byte("test")) - ztesting.AssertEqualErr(t, "error not returned", zargon2.ErrShortHash, err) + ztesting.AssertEqualErr(t, zargon2.ErrShortHash, err) }) t.Run("pw not match", func(t *testing.T) { b, err := zargon2.NewArgon2id(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, err := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare(h, []byte("wrong")) - ztesting.AssertEqualErr(t, "error not matched", zargon2.ErrNotMatch, err) + ztesting.AssertEqualErr(t, zargon2.ErrNotMatch, err) }) t.Run("pw match", func(t *testing.T) { b, err := zargon2.NewArgon2id(10, 1, 64*1024, 4, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, err := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare(h, []byte("test")) - ztesting.AssertEqualErr(t, "error not matched", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) } diff --git a/zcrypto/zbcrypt/bcrypt_test.go b/zcrypto/zbcrypt/bcrypt_test.go index dfa68b3..a4ac0d4 100644 --- a/zcrypto/zbcrypt/bcrypt_test.go +++ b/zcrypto/zbcrypt/bcrypt_test.go @@ -14,22 +14,22 @@ func TestNew(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("1234567890123456789012345678901234567890")) defer done() b, err := zbcrypt.New(10) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "hash not match", "$2a$10$Lxe3KBCwKxOzLha2MR.vKePt0LpiRJVu6NMWU/u7ddWJx0sm6kBb.", string(h)) + ztesting.AssertEqual(t, "$2a$10$Lxe3KBCwKxOzLha2MR.vKePt0LpiRJVu6NMWU/u7ddWJx0sm6kBb.", string(h)) }) t.Run("min cost", func(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("1234567890123456789012345678901234567890")) defer done() b, err := zbcrypt.New(4) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "hash not match", "$2a$04$Lxe3KBCwKxOzLha2MR.vKeIyr1H1Cb4ubhc770bjAQSAVlORxnG2S", string(h)) + ztesting.AssertEqual(t, "$2a$04$Lxe3KBCwKxOzLha2MR.vKeIyr1H1Cb4ubhc770bjAQSAVlORxnG2S", string(h)) }) t.Run("param invalid cost=32", func(t *testing.T) { b, err := zbcrypt.New(32) - ztesting.AssertEqual(t, "non nil hasher returned", nil, b) - ztesting.AssertEqualErr(t, "nil error returned", bcrypt.InvalidCostError(32), err) + ztesting.AssertEqual(t, nil, b) + ztesting.AssertEqualErr(t, bcrypt.InvalidCostError(32), err) }) } @@ -37,18 +37,18 @@ func TestEqual(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("1234567890123456789012345678901234567890")) defer done() b, err := zbcrypt.New(10) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "incorrect equal result", true, b.Equal(h, []byte("test"))) - ztesting.AssertEqual(t, "incorrect equal result", false, b.Equal(h, []byte("wrong"))) + ztesting.AssertEqual(t, true, b.Equal(h, []byte("test"))) + ztesting.AssertEqual(t, false, b.Equal(h, []byte("wrong"))) } func TestCompare(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("1234567890123456789012345678901234567890")) defer done() b, err := zbcrypt.New(10) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "incorrect compare result", nil, b.Compare(h, []byte("test"))) - ztesting.AssertEqualErr(t, "incorrect compare result", bcrypt.ErrMismatchedHashAndPassword, b.Compare(h, []byte("wrong"))) + ztesting.AssertEqualErr(t, nil, b.Compare(h, []byte("test"))) + ztesting.AssertEqualErr(t, bcrypt.ErrMismatchedHashAndPassword, b.Compare(h, []byte("wrong"))) } diff --git a/zcrypto/zblake2b/blake2b_test.go b/zcrypto/zblake2b/blake2b_test.go index 34dd7aa..f33793d 100644 --- a/zcrypto/zblake2b/blake2b_test.go +++ b/zcrypto/zblake2b/blake2b_test.go @@ -33,7 +33,7 @@ func TestSum(t *testing.T) { for _, tc := range hashSum { t.Run(tc.msg, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, "hash not match", tc.sum, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) } } @@ -44,10 +44,10 @@ func TestEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } @@ -88,7 +88,7 @@ func TestHMACSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum := tc.sf([]byte(tc.msg), []byte(tc.key)) got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, "invalid sum result", tc.sum, got) + ztesting.AssertEqual(t, tc.sum, got) }) } } @@ -99,10 +99,10 @@ func TestHMACEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } diff --git a/zcrypto/zblake2s/blake2s_test.go b/zcrypto/zblake2s/blake2s_test.go index 64c8aca..b7a9254 100644 --- a/zcrypto/zblake2s/blake2s_test.go +++ b/zcrypto/zblake2s/blake2s_test.go @@ -28,7 +28,7 @@ func TestSum(t *testing.T) { for _, tc := range hashSum { t.Run(tc.msg, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, "hash not match", tc.sum, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) } } @@ -39,10 +39,10 @@ func TestEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } @@ -71,7 +71,7 @@ func TestHMACSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum := tc.sf([]byte(tc.msg), []byte(tc.key)) got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, "invalid sum result", tc.sum, got) + ztesting.AssertEqual(t, tc.sum, got) }) } } @@ -82,10 +82,10 @@ func TestHMACEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } diff --git a/zcrypto/zchacha20/chacha20_test.go b/zcrypto/zchacha20/chacha20_test.go index 1e818bc..4a66e8c 100644 --- a/zcrypto/zchacha20/chacha20_test.go +++ b/zcrypto/zchacha20/chacha20_test.go @@ -23,22 +23,22 @@ func TestNewStreamReader(t *testing.T) { nonce := []byte("123456789012") t.Run("invalid key", func(t *testing.T) { _, err := zchacha20.NewStreamReader(nil, nonce, nil) - ztesting.AssertEqualErr(t, "error not match", errWrongKey, err) + ztesting.AssertEqualErr(t, errWrongKey, err) }) t.Run("encrypt", func(t *testing.T) { r, err := zchacha20.NewStreamReader(key, nonce, strings.NewReader("test")) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) buf := make([]byte, 100) n, _ := r.Read(buf) - ztesting.AssertEqual(t, "ciphertext not match", "3f416920", hex.EncodeToString(buf[:n])) + ztesting.AssertEqual(t, "3f416920", hex.EncodeToString(buf[:n])) }) t.Run("decrypt", func(t *testing.T) { c, _ := hex.DecodeString("3f416920") r, err := zchacha20.NewStreamReader(key, nonce, bytes.NewReader(c)) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) buf := make([]byte, 100) n, _ := r.Read(buf) - ztesting.AssertEqual(t, "plaintext not match", "test", string(buf[:n])) + ztesting.AssertEqual(t, "test", string(buf[:n])) }) } @@ -48,22 +48,22 @@ func TestNewStreamWriter(t *testing.T) { nonce := []byte("123456789012") t.Run("invalid key", func(t *testing.T) { _, err := zchacha20.NewStreamWriter(nil, nonce, nil) - ztesting.AssertEqualErr(t, "error not match", errWrongKey, err) + ztesting.AssertEqualErr(t, errWrongKey, err) }) t.Run("encrypt", func(t *testing.T) { var buf bytes.Buffer w, err := zchacha20.NewStreamWriter(key, nonce, &buf) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) w.Write([]byte("test")) - ztesting.AssertEqual(t, "ciphertext not match", "3f416920", hex.EncodeToString(buf.Bytes())) + ztesting.AssertEqual(t, "3f416920", hex.EncodeToString(buf.Bytes())) }) t.Run("decrypt", func(t *testing.T) { c, _ := hex.DecodeString("3f416920") var buf bytes.Buffer w, err := zchacha20.NewStreamWriter(key, nonce, &buf) w.Write(c) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext not match", "test", buf.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "test", buf.String()) }) } @@ -73,40 +73,40 @@ func TestCopy(t *testing.T) { nonce := []byte("123456789012") t.Run("invalid key", func(t *testing.T) { err := zchacha20.Copy(nil, nonce, nil, nil) - ztesting.AssertEqualErr(t, "error not match", errWrongKey, err) + ztesting.AssertEqualErr(t, errWrongKey, err) }) t.Run("encrypt", func(t *testing.T) { var buf bytes.Buffer err := zchacha20.Copy(key, nonce, &buf, strings.NewReader("test")) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "ciphertext not match", "3f416920", hex.EncodeToString(buf.Bytes())) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "3f416920", hex.EncodeToString(buf.Bytes())) }) t.Run("decrypt", func(t *testing.T) { c, _ := hex.DecodeString("3f416920") var buf bytes.Buffer err := zchacha20.Copy(key, nonce, &buf, bytes.NewReader(c)) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext not match", "test", buf.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "test", buf.String()) }) t.Run("read error", func(t *testing.T) { c, _ := hex.DecodeString("3f416920") var buf bytes.Buffer err := zchacha20.Copy(key, nonce, &buf, ziotest.ErrReader(bytes.NewReader(c), 3)) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "plaintext not match", "tes", buf.String()) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "tes", buf.String()) }) t.Run("write error", func(t *testing.T) { c, _ := hex.DecodeString("3f416920") var buf bytes.Buffer err := zchacha20.Copy(key, nonce, ziotest.ErrWriter(&buf, 3), bytes.NewReader(c)) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "plaintext not match", "tes", buf.String()) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "tes", buf.String()) }) t.Run("short write", func(t *testing.T) { c, _ := hex.DecodeString("3f416920") var buf bytes.Buffer err := zchacha20.Copy(key, nonce, ziotest.ErrWriterWith(&buf, 3, nil), bytes.NewReader(c)) - ztesting.AssertEqualErr(t, "error not match", io.ErrShortWrite, err) - ztesting.AssertEqual(t, "plaintext not match", "tes", buf.String()) + ztesting.AssertEqualErr(t, io.ErrShortWrite, err) + ztesting.AssertEqual(t, "tes", buf.String()) }) } diff --git a/zcrypto/zdes/cbc_test.go b/zcrypto/zdes/cbc_test.go index e38f753..a06370b 100644 --- a/zcrypto/zdes/cbc_test.go +++ b/zcrypto/zdes/cbc_test.go @@ -13,37 +13,37 @@ func TestCBC(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptCBC(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptCBC(key, []byte("1234567812345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("12345678") plaintext, err := zdes.DecryptCBC(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678") ciphertext, err := zdes.EncryptCBC(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCBC(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("12345678") msg := []byte("test message") ciphertext, err := zdes.EncryptCBC(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCBC(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } @@ -52,36 +52,36 @@ func TestCBC3(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptCBC3(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptCBC3(key, []byte("1234567812345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("123456781234567812345678") plaintext, err := zdes.DecryptCBC3(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456781234567812345678") ciphertext, err := zdes.EncryptCBC3(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCBC3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("123456781234567812345678") msg := []byte("test message") ciphertext, err := zdes.EncryptCBC3(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCBC3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } diff --git a/zcrypto/zdes/cfb_test.go b/zcrypto/zdes/cfb_test.go index 0ef5102..cd257cb 100644 --- a/zcrypto/zdes/cfb_test.go +++ b/zcrypto/zdes/cfb_test.go @@ -13,37 +13,37 @@ func TestCFB(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptCFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptCFB(key, []byte("12345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("12345678") plaintext, err := zdes.DecryptCFB(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678") ciphertext, err := zdes.EncryptCFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("12345678") msg := []byte("test message") ciphertext, err := zdes.EncryptCFB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } @@ -52,36 +52,36 @@ func TestCFB3(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptCFB3(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptCFB3(key, []byte("12345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("123456781234567812345678") plaintext, err := zdes.DecryptCFB3(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456781234567812345678") ciphertext, err := zdes.EncryptCFB3(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCFB3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("123456781234567812345678") msg := []byte("test message") ciphertext, err := zdes.EncryptCFB3(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCFB3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } diff --git a/zcrypto/zdes/ctr_test.go b/zcrypto/zdes/ctr_test.go index 2dcf9bf..346de85 100644 --- a/zcrypto/zdes/ctr_test.go +++ b/zcrypto/zdes/ctr_test.go @@ -15,37 +15,37 @@ func TestCTR(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptCTR(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptCTR(key, []byte("12345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("12345678") plaintext, err := zdes.DecryptCTR(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678") ciphertext, err := zdes.EncryptCTR(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCTR(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("12345678") msg := []byte("test message") ciphertext, err := zdes.EncryptCTR(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCTR(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } @@ -54,37 +54,37 @@ func TestCTR3(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptCTR3(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptCTR3(key, []byte("12345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("123456781234567812345678") plaintext, err := zdes.DecryptCTR3(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456781234567812345678") ciphertext, err := zdes.EncryptCTR3(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCTR3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("123456781234567812345678") msg := []byte("test message") ciphertext, err := zdes.EncryptCTR3(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptCTR3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } @@ -94,7 +94,7 @@ func TestCopyCTR(t *testing.T) { key := []byte("short") iv := []byte("12345678") err := zdes.CopyCTR(key, iv, nil, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("12345678") @@ -102,12 +102,12 @@ func TestCopyCTR(t *testing.T) { msg := "test message" var w, ww bytes.Buffer err := zdes.CopyCTR(key, iv, &w, strings.NewReader(msg)) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "length not match", len(msg), w.Len()) - ztesting.AssertEqual(t, "message unexpectedly match", false, msg == w.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, len(msg), w.Len()) + ztesting.AssertEqual(t, false, msg == w.String()) err = zdes.CopyCTR(key, iv, &ww, strings.NewReader(w.String())) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "message not match", msg, ww.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, ww.String()) }) } @@ -117,7 +117,7 @@ func TestCopyCTR3(t *testing.T) { key := []byte("short") iv := []byte("12345678") err := zdes.CopyCTR3(key, iv, nil, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("123456781234567812345678") @@ -125,11 +125,11 @@ func TestCopyCTR3(t *testing.T) { msg := "test message" var w, ww bytes.Buffer err := zdes.CopyCTR3(key, iv, &w, strings.NewReader(msg)) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "length not match", len(msg), w.Len()) - ztesting.AssertEqual(t, "message unexpectedly match", false, msg == w.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, len(msg), w.Len()) + ztesting.AssertEqual(t, false, msg == w.String()) err = zdes.CopyCTR3(key, iv, &ww, strings.NewReader(w.String())) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "message not match", msg, ww.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, ww.String()) }) } diff --git a/zcrypto/zdes/des_test.go b/zcrypto/zdes/des_test.go index 71b5f13..8e66bfa 100644 --- a/zcrypto/zdes/des_test.go +++ b/zcrypto/zdes/des_test.go @@ -13,21 +13,21 @@ import ( func TestErrCipherLength(t *testing.T) { t.Parallel() e := ErrCipherLength(1) - ztesting.AssertEqual(t, "message not match", "zdes: incorrect ciphertext length. got:1", e.Error()) + ztesting.AssertEqual(t, "zdes: incorrect ciphertext length. got:1", e.Error()) } func TestNewDES(t *testing.T) { t.Parallel() t.Run("invalid key", func(t *testing.T) { cb, iv, err := newDES([]byte("short")) - ztesting.AssertEqualErr(t, "unexpected error", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "non nil cipher block returned", nil, cb) - ztesting.AssertEqual(t, "non empty iv returned", nil, iv) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, cb) + ztesting.AssertEqual(t, nil, iv) }) t.Run("valid key", func(t *testing.T) { _, iv, err := newDES([]byte("12345678")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) - ztesting.AssertEqual(t, "iv length invalid", 8, len(iv)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 8, len(iv)) }) } @@ -35,14 +35,14 @@ func TestNew3DES(t *testing.T) { t.Parallel() t.Run("invalid key", func(t *testing.T) { cb, iv, err := new3DES([]byte("short")) - ztesting.AssertEqualErr(t, "unexpected error", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "non nil cipher block returned", nil, cb) - ztesting.AssertEqual(t, "non empty iv returned", nil, iv) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, cb) + ztesting.AssertEqual(t, nil, iv) }) t.Run("valid key", func(t *testing.T) { _, iv, err := new3DES([]byte("123456781234567812345678")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) - ztesting.AssertEqual(t, "iv length invalid", 8, len(iv)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 8, len(iv)) }) } @@ -95,14 +95,14 @@ func TestEncryptDecrypt(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("abcd1234")) defer done() ciphertext, err := tc.enc([]byte(tc.key), []byte(tc.plain)) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "ciphertext not match", tc.cipher, hex.EncodeToString(ciphertext)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.cipher, hex.EncodeToString(ciphertext)) }) t.Run(tc.name+"_decrypt", func(t *testing.T) { cipher, _ := hex.DecodeString(tc.cipher) plain, err := tc.dec([]byte(tc.key), cipher) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "plaintext not match", tc.plain, string(plain)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, tc.plain, string(plain)) }) } } diff --git a/zcrypto/zdes/ecb_test.go b/zcrypto/zdes/ecb_test.go index 2abb4ed..c4b9af0 100644 --- a/zcrypto/zdes/ecb_test.go +++ b/zcrypto/zdes/ecb_test.go @@ -13,37 +13,37 @@ func TestECB(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptECB(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptECB(key, []byte("12345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("12345678") plaintext, err := zdes.DecryptECB(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678") ciphertext, err := zdes.EncryptECB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptECB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("12345678") msg := []byte("test message") ciphertext, err := zdes.EncryptECB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptECB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } @@ -52,36 +52,36 @@ func TestECB3(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptECB3(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptECB3(key, []byte("12345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("123456781234567812345678") plaintext, err := zdes.DecryptECB3(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456781234567812345678") ciphertext, err := zdes.EncryptECB3(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptECB3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("123456781234567812345678") msg := []byte("test message") ciphertext, err := zdes.EncryptECB3(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptECB3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } diff --git a/zcrypto/zdes/ofb_test.go b/zcrypto/zdes/ofb_test.go index 86d6792..0c6c765 100644 --- a/zcrypto/zdes/ofb_test.go +++ b/zcrypto/zdes/ofb_test.go @@ -15,37 +15,37 @@ func TestOFB(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptOFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptOFB(key, []byte("12345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("12345678") plaintext, err := zdes.DecryptOFB(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("12345678") ciphertext, err := zdes.EncryptOFB(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptOFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("12345678") msg := []byte("test message") ciphertext, err := zdes.EncryptOFB(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptOFB(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } @@ -54,37 +54,37 @@ func TestOFB3(t *testing.T) { t.Run("encrypt key invalid", func(t *testing.T) { key := []byte("short") ciphertext, err := zdes.EncryptOFB3(key, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "ciphertext is not nil", nil, ciphertext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, ciphertext) }) t.Run("decrypt key invalid", func(t *testing.T) { key := []byte("short") plaintext, err := zdes.DecryptOFB3(key, []byte("12345678")) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("decrypt invalid ciphertext length", func(t *testing.T) { key := []byte("123456781234567812345678") plaintext, err := zdes.DecryptOFB3(key, []byte("short")) - ztesting.AssertEqualErr(t, "error not match", zdes.ErrCipherLength(5), err) - ztesting.AssertEqual(t, "plaintext is not nil", nil, plaintext) + ztesting.AssertEqualErr(t, zdes.ErrCipherLength(5), err) + ztesting.AssertEqual(t, nil, plaintext) }) t.Run("encrypt-decrypt empty", func(t *testing.T) { key := []byte("123456781234567812345678") ciphertext, err := zdes.EncryptOFB3(key, nil) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptOFB3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", []byte{}, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []byte{}, plaintext) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("123456781234567812345678") msg := []byte("test message") ciphertext, err := zdes.EncryptOFB3(key, msg) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) plaintext, err := zdes.DecryptOFB3(key, ciphertext) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext does not match", msg, plaintext) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, plaintext) }) } @@ -94,7 +94,7 @@ func TestCopyOFB(t *testing.T) { key := []byte("short") iv := []byte("12345678") err := zdes.CopyOFB(key, iv, nil, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("12345678") @@ -102,12 +102,12 @@ func TestCopyOFB(t *testing.T) { msg := "test message" var w, ww bytes.Buffer err := zdes.CopyOFB(key, iv, &w, strings.NewReader(msg)) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "length not match", len(msg), w.Len()) - ztesting.AssertEqual(t, "message unexpectedly match", false, msg == w.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, len(msg), w.Len()) + ztesting.AssertEqual(t, false, msg == w.String()) err = zdes.CopyOFB(key, iv, &ww, strings.NewReader(w.String())) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "message not match", msg, ww.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, ww.String()) }) } @@ -117,7 +117,7 @@ func TestCopyOFB3(t *testing.T) { key := []byte("short") iv := []byte("12345678") err := zdes.CopyOFB3(key, iv, nil, nil) - ztesting.AssertEqualErr(t, "error not match", des.KeySizeError(5), err) + ztesting.AssertEqualErr(t, des.KeySizeError(5), err) }) t.Run("encrypt-decrypt", func(t *testing.T) { key := []byte("123456781234567812345678") @@ -125,11 +125,11 @@ func TestCopyOFB3(t *testing.T) { msg := "test message" var w, ww bytes.Buffer err := zdes.CopyOFB3(key, iv, &w, strings.NewReader(msg)) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "length not match", len(msg), w.Len()) - ztesting.AssertEqual(t, "message unexpectedly match", false, msg == w.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, len(msg), w.Len()) + ztesting.AssertEqual(t, false, msg == w.String()) err = zdes.CopyOFB3(key, iv, &ww, strings.NewReader(w.String())) - ztesting.AssertEqualErr(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "message not match", msg, ww.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, msg, ww.String()) }) } diff --git a/zcrypto/zhmac/hmac_test.go b/zcrypto/zhmac/hmac_test.go index 03dc5d8..02edcc7 100644 --- a/zcrypto/zhmac/hmac_test.go +++ b/zcrypto/zhmac/hmac_test.go @@ -15,13 +15,13 @@ func TestSum(t *testing.T) { t.Run("not available", func(t *testing.T) { defer func() { r := recover() - ztesting.AssertEqualErr(t, "error not match", zhmac.ErrNotAvailable, r.(error)) + ztesting.AssertEqualErr(t, zhmac.ErrNotAvailable, r.(error)) }() zhmac.Sum(crypto.Hash(999), nil, nil) }) t.Run("available", func(t *testing.T) { sum := zhmac.Sum(crypto.SHA256, []byte("test"), []byte("key")) - ztesting.AssertEqual(t, "invalid hash", "02afb56304902c656fcb737cdd03de6205bb6d401da2812efd9b2d36a08af159", hex.EncodeToString(sum)) + ztesting.AssertEqual(t, "02afb56304902c656fcb737cdd03de6205bb6d401da2812efd9b2d36a08af159", hex.EncodeToString(sum)) }) } @@ -30,12 +30,12 @@ func TestEqual(t *testing.T) { t.Run("match", func(t *testing.T) { sum, _ := hex.DecodeString("02afb56304902c656fcb737cdd03de6205bb6d401da2812efd9b2d36a08af159") equal := zhmac.Equal(crypto.SHA256, []byte("test"), []byte("key"), sum) - ztesting.AssertEqual(t, "incorrect comparison result", true, equal) + ztesting.AssertEqual(t, true, equal) }) t.Run("mismatch", func(t *testing.T) { sum, _ := hex.DecodeString("02afb56304902c656fcb737cdd03de6205bb6d401da2812efd9b2d36a08af159") equal := zhmac.Equal(crypto.SHA256, []byte("wrong"), []byte("key"), sum) - ztesting.AssertEqual(t, "incorrect comparison result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } @@ -44,16 +44,16 @@ func TestCompare(t *testing.T) { t.Run("hash unavailable", func(t *testing.T) { sum, _ := hex.DecodeString("02afb56304902c656fcb737cdd03de6205bb6d401da2812efd9b2d36a08af159") err := zhmac.Compare(crypto.Hash(999), []byte("test"), []byte("key"), sum) - ztesting.AssertEqualErr(t, "incorrect comparison result", zhmac.ErrNotAvailable, err) + ztesting.AssertEqualErr(t, zhmac.ErrNotAvailable, err) }) t.Run("match", func(t *testing.T) { sum, _ := hex.DecodeString("02afb56304902c656fcb737cdd03de6205bb6d401da2812efd9b2d36a08af159") err := zhmac.Compare(crypto.SHA256, []byte("test"), []byte("key"), sum) - ztesting.AssertEqualErr(t, "incorrect comparison result", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("mismatch", func(t *testing.T) { sum, _ := hex.DecodeString("02afb56304902c656fcb737cdd03de6205bb6d401da2812efd9b2d36a08af159") err := zhmac.Compare(crypto.SHA256, []byte("wrong"), []byte("key"), sum) - ztesting.AssertEqualErr(t, "incorrect comparison result", zhmac.ErrNotMatch, err) + ztesting.AssertEqualErr(t, zhmac.ErrNotMatch, err) }) } diff --git a/zcrypto/zmd4/md4_test.go b/zcrypto/zmd4/md4_test.go index 605df30..ff04b8a 100644 --- a/zcrypto/zmd4/md4_test.go +++ b/zcrypto/zmd4/md4_test.go @@ -28,7 +28,7 @@ func TestSum(t *testing.T) { for _, tc := range hashSum { t.Run(tc.msg, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, "hash not match", tc.sum, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) } } @@ -39,10 +39,10 @@ func TestEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } @@ -69,7 +69,7 @@ func TestHMACSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum := tc.sf([]byte(tc.msg), []byte(tc.key)) got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, "invalid sum result", tc.sum, got) + ztesting.AssertEqual(t, tc.sum, got) }) } } @@ -80,10 +80,10 @@ func TestHMACEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } diff --git a/zcrypto/zmd5/md5_test.go b/zcrypto/zmd5/md5_test.go index 47fa502..e24e5a9 100644 --- a/zcrypto/zmd5/md5_test.go +++ b/zcrypto/zmd5/md5_test.go @@ -28,7 +28,7 @@ func TestSum(t *testing.T) { for _, tc := range hashSum { t.Run(tc.msg, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, "hash not match", tc.sum, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) } } @@ -39,10 +39,10 @@ func TestEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } @@ -69,7 +69,7 @@ func TestHMACSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum := tc.sf([]byte(tc.msg), []byte(tc.key)) got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, "invalid sum result", tc.sum, got) + ztesting.AssertEqual(t, tc.sum, got) }) } } @@ -80,10 +80,10 @@ func TestHMACEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } diff --git a/zcrypto/zpbkdf2/pbkdf2_test.go b/zcrypto/zpbkdf2/pbkdf2_test.go index e8e2a87..02fd7ab 100644 --- a/zcrypto/zpbkdf2/pbkdf2_test.go +++ b/zcrypto/zpbkdf2/pbkdf2_test.go @@ -16,31 +16,31 @@ func TestNew(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zpbkdf2.New(10, 210000, 32, crypto.SHA256) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "hash not match", "313233343536373839306d94d84234ee7201fb39aff04ffd9d7bbc5339bb9553a3e47146c45bf0aece7d", hex.EncodeToString(h)) + ztesting.AssertEqual(t, "313233343536373839306d94d84234ee7201fb39aff04ffd9d7bbc5339bb9553a3e47146c45bf0aece7d", hex.EncodeToString(h)) }) t.Run("hash not available", func(t *testing.T) { b, err := zpbkdf2.New(10, 210000, 32, crypto.Hash(999)) - ztesting.AssertEqual(t, "non nil hasher returned", nil, b) - ztesting.AssertEqualErr(t, "nil error returned", zpbkdf2.ErrUnavailable, err) + ztesting.AssertEqual(t, nil, b) + ztesting.AssertEqualErr(t, zpbkdf2.ErrUnavailable, err) }) } func TestSplit(t *testing.T) { t.Run("short hash", func(t *testing.T) { b, err := zpbkdf2.New(32, 210000, 32, crypto.SHA256) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) _, _, err = b.Split([]byte("short hash")) - ztesting.AssertEqualErr(t, "error not returned", zpbkdf2.ErrShortHash, err) + ztesting.AssertEqualErr(t, zpbkdf2.ErrShortHash, err) }) t.Run("split hash", func(t *testing.T) { b, err := zpbkdf2.New(10, 210000, 32, crypto.SHA256) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) salt, hash, err := b.Split([]byte("1234567890abcdefghijklmnopqrstuvwxyz")) - ztesting.AssertEqualErr(t, "non-nil error returned", nil, err) - ztesting.AssertEqual(t, "incorrect salt", "1234567890", string(salt)) - ztesting.AssertEqual(t, "incorrect hash", "abcdefghijklmnopqrstuvwxyz", string(hash)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "1234567890", string(salt)) + ztesting.AssertEqual(t, "abcdefghijklmnopqrstuvwxyz", string(hash)) }) } @@ -52,9 +52,9 @@ func TestSum(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zpbkdf2.New(10, 210000, 32, crypto.SHA256) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "hash not match", "313233343536373839306d94d84234ee7201fb39aff04ffd9d7bbc5339bb9553a3e47146c45bf0aece7d", hex.EncodeToString(h)) + ztesting.AssertEqual(t, "313233343536373839306d94d84234ee7201fb39aff04ffd9d7bbc5339bb9553a3e47146c45bf0aece7d", hex.EncodeToString(h)) }) } @@ -63,34 +63,34 @@ func TestEqual(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("1234567890123456789012345678901234567890")) defer done() b, err := zpbkdf2.New(10, 210000, 32, crypto.SHA256) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "incorrect equal result", true, b.Equal(h, []byte("test"))) - ztesting.AssertEqual(t, "incorrect equal result", false, b.Equal(h, []byte("wrong"))) + ztesting.AssertEqual(t, true, b.Equal(h, []byte("test"))) + ztesting.AssertEqual(t, false, b.Equal(h, []byte("wrong"))) }) } func TestCompare(t *testing.T) { t.Run("short hash", func(t *testing.T) { b, err := zpbkdf2.New(32, 210000, 32, crypto.SHA256) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare([]byte("short hash"), []byte("test")) - ztesting.AssertEqualErr(t, "error not returned", zpbkdf2.ErrShortHash, err) + ztesting.AssertEqualErr(t, zpbkdf2.ErrShortHash, err) }) t.Run("pw not match", func(t *testing.T) { b, err := zpbkdf2.New(32, 210000, 32, crypto.SHA256) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, err := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare(h, []byte("wrong")) - ztesting.AssertEqualErr(t, "error not matched", zpbkdf2.ErrNotMatch, err) + ztesting.AssertEqualErr(t, zpbkdf2.ErrNotMatch, err) }) t.Run("pw match", func(t *testing.T) { b, err := zpbkdf2.New(32, 210000, 32, crypto.SHA256) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, err := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare(h, []byte("test")) - ztesting.AssertEqualErr(t, "error not matched", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) } diff --git a/zcrypto/zrc4/rc4_test.go b/zcrypto/zrc4/rc4_test.go index 819d2cf..88f8b32 100644 --- a/zcrypto/zrc4/rc4_test.go +++ b/zcrypto/zrc4/rc4_test.go @@ -20,22 +20,22 @@ func TestNewStreamReader(t *testing.T) { key := []byte("secret-key") t.Run("invalid key", func(t *testing.T) { _, err := zrc4.NewStreamReader(nil, nil) - ztesting.AssertEqualErr(t, "error not match", rc4.KeySizeError(0), err) + ztesting.AssertEqualErr(t, rc4.KeySizeError(0), err) }) t.Run("encrypt", func(t *testing.T) { r, err := zrc4.NewStreamReader(key, strings.NewReader("test")) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) buf := make([]byte, 100) n, _ := r.Read(buf) - ztesting.AssertEqual(t, "ciphertext not match", "c46d3def", hex.EncodeToString(buf[:n])) + ztesting.AssertEqual(t, "c46d3def", hex.EncodeToString(buf[:n])) }) t.Run("decrypt", func(t *testing.T) { c, _ := hex.DecodeString("c46d3def") r, err := zrc4.NewStreamReader(key, bytes.NewReader(c)) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) buf := make([]byte, 100) n, _ := r.Read(buf) - ztesting.AssertEqual(t, "plaintext not match", "test", string(buf[:n])) + ztesting.AssertEqual(t, "test", string(buf[:n])) }) } @@ -46,22 +46,22 @@ func TestNewStreamWriter(t *testing.T) { key := []byte("secret-key") t.Run("invalid key", func(t *testing.T) { _, err := zrc4.NewStreamWriter(nil, nil) - ztesting.AssertEqualErr(t, "error not match", rc4.KeySizeError(0), err) + ztesting.AssertEqualErr(t, rc4.KeySizeError(0), err) }) t.Run("encrypt", func(t *testing.T) { var buf bytes.Buffer w, err := zrc4.NewStreamWriter(key, &buf) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) w.Write([]byte("test")) - ztesting.AssertEqual(t, "ciphertext not match", "c46d3def", hex.EncodeToString(buf.Bytes())) + ztesting.AssertEqual(t, "c46d3def", hex.EncodeToString(buf.Bytes())) }) t.Run("decrypt", func(t *testing.T) { c, _ := hex.DecodeString("c46d3def") var buf bytes.Buffer w, err := zrc4.NewStreamWriter(key, &buf) w.Write(c) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext not match", "test", buf.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "test", buf.String()) }) } @@ -70,40 +70,40 @@ func TestCopy(t *testing.T) { key := []byte("secret-key") t.Run("invalid key", func(t *testing.T) { err := zrc4.Copy(nil, nil, nil) - ztesting.AssertEqualErr(t, "error not match", rc4.KeySizeError(0), err) + ztesting.AssertEqualErr(t, rc4.KeySizeError(0), err) }) t.Run("encrypt", func(t *testing.T) { var buf bytes.Buffer err := zrc4.Copy(key, &buf, strings.NewReader("test")) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "ciphertext not match", "c46d3def", hex.EncodeToString(buf.Bytes())) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "c46d3def", hex.EncodeToString(buf.Bytes())) }) t.Run("decrypt", func(t *testing.T) { c, _ := hex.DecodeString("c46d3def") var buf bytes.Buffer err := zrc4.Copy(key, &buf, bytes.NewReader(c)) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "plaintext not match", "test", buf.String()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "test", buf.String()) }) t.Run("read error", func(t *testing.T) { c, _ := hex.DecodeString("c46d3def") var buf bytes.Buffer err := zrc4.Copy(key, &buf, ziotest.ErrReader(bytes.NewReader(c), 3)) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "plaintext not match", "tes", buf.String()) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "tes", buf.String()) }) t.Run("write error", func(t *testing.T) { c, _ := hex.DecodeString("c46d3def") var buf bytes.Buffer err := zrc4.Copy(key, ziotest.ErrWriter(&buf, 3), bytes.NewReader(c)) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "plaintext not match", "tes", buf.String()) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "tes", buf.String()) }) t.Run("short write", func(t *testing.T) { c, _ := hex.DecodeString("c46d3def") var buf bytes.Buffer err := zrc4.Copy(key, ziotest.ErrWriterWith(&buf, 3, nil), bytes.NewReader(c)) - ztesting.AssertEqualErr(t, "error not match", io.ErrShortWrite, err) - ztesting.AssertEqual(t, "plaintext not match", "tes", buf.String()) + ztesting.AssertEqualErr(t, io.ErrShortWrite, err) + ztesting.AssertEqual(t, "tes", buf.String()) }) } diff --git a/zcrypto/zripemd160/ripemd160_test.go b/zcrypto/zripemd160/ripemd160_test.go index c9a1e5c..65d2c49 100644 --- a/zcrypto/zripemd160/ripemd160_test.go +++ b/zcrypto/zripemd160/ripemd160_test.go @@ -28,7 +28,7 @@ func TestSum(t *testing.T) { for _, tc := range hashSum { t.Run(tc.msg, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, "hash not match", tc.sum, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) } } @@ -39,10 +39,10 @@ func TestEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } @@ -69,7 +69,7 @@ func TestHMACSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum := tc.sf([]byte(tc.msg), []byte(tc.key)) got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, "invalid sum result", tc.sum, got) + ztesting.AssertEqual(t, tc.sum, got) }) } } @@ -80,10 +80,10 @@ func TestHMACEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } diff --git a/zcrypto/zscrypt/scrypt_test.go b/zcrypto/zscrypt/scrypt_test.go index 4cdc87c..9a2ea01 100644 --- a/zcrypto/zscrypt/scrypt_test.go +++ b/zcrypto/zscrypt/scrypt_test.go @@ -16,31 +16,31 @@ func TestNew(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zscrypt.New(10, 32768, 8, 1, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "hash not match", "31323334353637383930dac13eff06858ad01e3f90af26b7a3055233ebdfaa90674bada2a0fd0e3a316a", hex.EncodeToString(h)) + ztesting.AssertEqual(t, "31323334353637383930dac13eff06858ad01e3f90af26b7a3055233ebdfaa90674bada2a0fd0e3a316a", hex.EncodeToString(h)) }) t.Run("param invalid", func(t *testing.T) { b, err := zscrypt.New(10, 32768, math.MaxInt, 1, 32) - ztesting.AssertEqual(t, "non nil hasher returned", nil, b) - ztesting.AssertEqualErr(t, "nil error returned", errors.New("scrypt: parameters are too large"), err) + ztesting.AssertEqual(t, nil, b) + ztesting.AssertEqualErr(t, errors.New("scrypt: parameters are too large"), err) }) } func TestSplit(t *testing.T) { t.Run("short hash", func(t *testing.T) { b, err := zscrypt.New(32, 32768, 8, 1, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) _, _, err = b.Split([]byte("short hash")) - ztesting.AssertEqualErr(t, "error not returned", zscrypt.ErrShortHash, err) + ztesting.AssertEqualErr(t, zscrypt.ErrShortHash, err) }) t.Run("split hash", func(t *testing.T) { b, err := zscrypt.New(10, 32768, 8, 1, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) salt, hash, err := b.Split([]byte("1234567890abcdefghijklmnopqrstuvwxyz")) - ztesting.AssertEqualErr(t, "non-nil error returned", nil, err) - ztesting.AssertEqual(t, "incorrect salt", "1234567890", string(salt)) - ztesting.AssertEqual(t, "incorrect hash", "abcdefghijklmnopqrstuvwxyz", string(hash)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "1234567890", string(salt)) + ztesting.AssertEqual(t, "abcdefghijklmnopqrstuvwxyz", string(hash)) }) } @@ -52,10 +52,10 @@ func TestSum(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("12345678901234567890")) defer done() b, err := zscrypt.New(10, 32768, 8, 1, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, err := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) - ztesting.AssertEqual(t, "hash not match", "31323334353637383930dac13eff06858ad01e3f90af26b7a3055233ebdfaa90674bada2a0fd0e3a316a", hex.EncodeToString(h)) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "31323334353637383930dac13eff06858ad01e3f90af26b7a3055233ebdfaa90674bada2a0fd0e3a316a", hex.EncodeToString(h)) }) } @@ -64,39 +64,39 @@ func TestEqual(t *testing.T) { done := ztesting.ReplaceRandReader(strings.NewReader("1234567890123456789012345678901234567890")) defer done() b, err := zscrypt.New(10, 32768, 8, 1, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, _ := b.Sum([]byte("test")) - ztesting.AssertEqual(t, "incorrect equal result", true, b.Equal(h, []byte("test"))) - ztesting.AssertEqual(t, "incorrect equal result", false, b.Equal(h, []byte("wrong"))) + ztesting.AssertEqual(t, true, b.Equal(h, []byte("test"))) + ztesting.AssertEqual(t, false, b.Equal(h, []byte("wrong"))) }) } func TestCompare(t *testing.T) { t.Run("short hash", func(t *testing.T) { b, err := zscrypt.New(32, 32768, 8, 1, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare([]byte("short hash"), []byte("test")) - ztesting.AssertEqualErr(t, "error not returned", zscrypt.ErrShortHash, err) + ztesting.AssertEqualErr(t, zscrypt.ErrShortHash, err) }) t.Run("key generate error", func(t *testing.T) { b := &zscrypt.SCrypt{} err := b.Compare([]byte("short hash"), []byte("test")) - ztesting.AssertEqualErr(t, "error not returned", errors.New("scrypt: N must be > 1 and a power of 2"), err) + ztesting.AssertEqualErr(t, errors.New("scrypt: N must be > 1 and a power of 2"), err) }) t.Run("pw not match", func(t *testing.T) { b, err := zscrypt.New(32, 32768, 8, 1, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, err := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare(h, []byte("wrong")) - ztesting.AssertEqualErr(t, "error not matched", zscrypt.ErrNotMatch, err) + ztesting.AssertEqualErr(t, zscrypt.ErrNotMatch, err) }) t.Run("pw match", func(t *testing.T) { b, err := zscrypt.New(32, 32768, 8, 1, 32) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) h, err := b.Sum([]byte("test")) - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) err = b.Compare(h, []byte("test")) - ztesting.AssertEqualErr(t, "error not matched", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) } diff --git a/zcrypto/zsha1/sha1_test.go b/zcrypto/zsha1/sha1_test.go index c2351ac..42df839 100644 --- a/zcrypto/zsha1/sha1_test.go +++ b/zcrypto/zsha1/sha1_test.go @@ -28,7 +28,7 @@ func TestSum(t *testing.T) { for _, tc := range hashSum { t.Run(tc.msg, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, "hash not match", tc.sum, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) } } @@ -39,10 +39,10 @@ func TestEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } @@ -69,7 +69,7 @@ func TestHMACSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum := tc.sf([]byte(tc.msg), []byte(tc.key)) got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, "invalid sum result", tc.sum, got) + ztesting.AssertEqual(t, tc.sum, got) }) } } @@ -80,10 +80,10 @@ func TestHMACEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } diff --git a/zcrypto/zsha256/sha256_test.go b/zcrypto/zsha256/sha256_test.go index 85cdcbd..ffe4142 100644 --- a/zcrypto/zsha256/sha256_test.go +++ b/zcrypto/zsha256/sha256_test.go @@ -31,7 +31,7 @@ func TestSum(t *testing.T) { for _, tc := range hashSum { t.Run(tc.msg, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, "hash not match", tc.sum, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) } } @@ -42,10 +42,10 @@ func TestEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } @@ -77,7 +77,7 @@ func TestHMACSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum := tc.sf([]byte(tc.msg), []byte(tc.key)) got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, "invalid sum result", tc.sum, got) + ztesting.AssertEqual(t, tc.sum, got) }) } } @@ -88,10 +88,10 @@ func TestHMACEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } diff --git a/zcrypto/zsha3/sha3_test.go b/zcrypto/zsha3/sha3_test.go index 3c7a9d9..7b86139 100644 --- a/zcrypto/zsha3/sha3_test.go +++ b/zcrypto/zsha3/sha3_test.go @@ -43,7 +43,7 @@ func TestSum(t *testing.T) { for _, tc := range hashSum { t.Run(tc.msg, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, "hash not match", tc.sum, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) } } @@ -54,10 +54,10 @@ func TestEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } @@ -99,7 +99,7 @@ func TestHMACSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum := tc.sf([]byte(tc.msg), []byte(tc.key)) got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, "invalid sum result", tc.sum, got) + ztesting.AssertEqual(t, tc.sum, got) }) } } @@ -110,10 +110,10 @@ func TestHMACEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } diff --git a/zcrypto/zsha512/sha512_test.go b/zcrypto/zsha512/sha512_test.go index 7bbafb5..e55b455 100644 --- a/zcrypto/zsha512/sha512_test.go +++ b/zcrypto/zsha512/sha512_test.go @@ -37,7 +37,7 @@ func TestSum(t *testing.T) { for _, tc := range hashSum { t.Run(tc.msg, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, "hash not match", tc.sum, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) } } @@ -48,10 +48,10 @@ func TestEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, "invalid compare result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } @@ -93,7 +93,7 @@ func TestHMACSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum := tc.sf([]byte(tc.msg), []byte(tc.key)) got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, "invalid sum result", tc.sum, got) + ztesting.AssertEqual(t, tc.sum, got) }) } } @@ -104,10 +104,10 @@ func TestHMACEqualSum(t *testing.T) { t.Run(tc.name, func(t *testing.T) { sum, _ := hex.DecodeString(tc.sum) equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", true, equal) + ztesting.AssertEqual(t, true, equal) slices.Reverse(sum) // Make the sum wrong. equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, "invalid equal result", false, equal) + ztesting.AssertEqual(t, false, equal) }) } } diff --git a/zencoding/zxml/badgerfish_decode_test.go b/zencoding/zxml/badgerfish_decode_test.go index 6c89b89..b402474 100644 --- a/zencoding/zxml/badgerfish_decode_test.go +++ b/zencoding/zxml/badgerfish_decode_test.go @@ -23,55 +23,55 @@ func TestBadgerFish_Decode(t *testing.T) { s.TextKey = "#text" d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) want := map[string]any{"alice": map[string]any{"#text": "bob", "@charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("attr prefix", func(t *testing.T) { s := base s.AttrPrefix = "%" d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) want := map[string]any{"alice": map[string]any{"$": "bob", "%charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("namespace sep", func(t *testing.T) { s := base s.NamespaceSep = "_**_" d, _ := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) want := map[string]any{"alice": map[string]any{"$": "bob", "@foo_**_charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) }) t.Run("trim space", func(t *testing.T) { s := base s.TrimSpace = true d, err := s.Decode(xml.NewDecoder(strings.NewReader(` bob `))) want := map[string]any{"alice": map[string]any{"$": "bob", "@charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("json value", func(t *testing.T) { s := base s.JSONValue = func(s string, se xml.StartElement) (any, error) { return "value", nil } d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) want := map[string]any{"alice": map[string]any{"$": "value", "@charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("json value error", func(t *testing.T) { s := base e := errors.New("parse error") s.JSONValue = func(s string, se xml.StartElement) (any, error) { return nil, e } d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) - ztesting.AssertEqualErr(t, "error not match", e, err) - ztesting.AssertEqual(t, "map is not nil", true, reflect.DeepEqual(nil, d)) + ztesting.AssertEqualErr(t, e, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(nil, d)) }) t.Run("inner json value error", func(t *testing.T) { s := base e := errors.New("parse error") s.JSONValue = func(s string, se xml.StartElement) (any, error) { return nil, e } d, err := s.Decode(xml.NewDecoder(strings.NewReader(`charlie`))) - ztesting.AssertEqualErr(t, "error not match", e, err) - ztesting.AssertEqual(t, "map is not nil", true, reflect.DeepEqual(nil, d)) + ztesting.AssertEqualErr(t, e, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(nil, d)) }) } @@ -88,30 +88,30 @@ func TestBadgerFish_WithEmptyValue(t *testing.T) { s.WithEmptyValue(nil) d, err := s.Decode(xml.NewDecoder(strings.NewReader(``))) want := map[string]any{"alice": nil} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("string", func(t *testing.T) { s := base s.WithEmptyValue("") d, err := s.Decode(xml.NewDecoder(strings.NewReader(``))) want := map[string]any{"alice": ""} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("map", func(t *testing.T) { s := base s.WithEmptyValue(map[string]any{}) d, err := s.Decode(xml.NewDecoder(strings.NewReader(``))) want := map[string]any{"alice": map[string]any{}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("panic", func(t *testing.T) { s := base defer func() { r := recover() - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseEmptyVal}, r.(error)) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseEmptyVal}, r.(error)) }() s.WithEmptyValue(123) }) diff --git a/zencoding/zxml/badgerfish_encode_test.go b/zencoding/zxml/badgerfish_encode_test.go index 60c405a..37f0c38 100644 --- a/zencoding/zxml/badgerfish_encode_test.go +++ b/zencoding/zxml/badgerfish_encode_test.go @@ -24,9 +24,9 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("attr prefix", func(t *testing.T) { s := base @@ -35,9 +35,9 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("namespace sep", func(t *testing.T) { s := base @@ -46,9 +46,9 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("xml value", func(t *testing.T) { s := base @@ -59,9 +59,9 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `value` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("xml value error", func(t *testing.T) { s := base @@ -73,7 +73,7 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", e, err) + ztesting.AssertEqualErr(t, e, err) }) t.Run("slice value error", func(t *testing.T) { @@ -82,7 +82,7 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("invalid text", func(t *testing.T) { s := base @@ -90,7 +90,7 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("array value invalid", func(t *testing.T) { s := base @@ -98,7 +98,7 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("invalid attribute", func(t *testing.T) { s := base @@ -106,7 +106,7 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("nil attribute", func(t *testing.T) { s := base @@ -114,9 +114,9 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("empty start elem", func(t *testing.T) { s := base @@ -124,7 +124,7 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) t.Run("token encode error", func(t *testing.T) { s := base @@ -133,7 +133,7 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) t.Run("end token encode error", func(t *testing.T) { s := base @@ -144,7 +144,7 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) t.Run("child encode error", func(t *testing.T) { s := base @@ -153,6 +153,6 @@ func TestBadgerFish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) } diff --git a/zencoding/zxml/badgerfish_test.go b/zencoding/zxml/badgerfish_test.go index dd6aacb..8a3220f 100644 --- a/zencoding/zxml/badgerfish_test.go +++ b/zencoding/zxml/badgerfish_test.go @@ -63,7 +63,7 @@ func TestBadgerFish_Decode(t *testing.T) { xmlBytes, _ := os.ReadFile("./testdata/xml/" + tc.file + ".xml") jsonBytes, _ := os.ReadFile("./testdata/badgerfish/" + tc.file + ".json") b, err := c.XMLtoJSON(xmlBytes) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if tc.err != nil { return } @@ -128,7 +128,7 @@ func TestBadgerFish_Encode(t *testing.T) { xmlBytes, _ := os.ReadFile("./testdata/badgerfish/" + tc.file + ".xml") jsonBytes, _ := os.ReadFile("./testdata/badgerfish/" + tc.file + ".json") b, err := c.JSONtoXML(jsonBytes) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if tc.err != nil { return } diff --git a/zencoding/zxml/rayfish_decode_test.go b/zencoding/zxml/rayfish_decode_test.go index 1e698da..c0fc9cb 100644 --- a/zencoding/zxml/rayfish_decode_test.go +++ b/zencoding/zxml/rayfish_decode_test.go @@ -29,8 +29,8 @@ func TestRayFish_Decode(t *testing.T) { "#text": "bob", "#children": []map[string]any{{"$": "@charlie", "#text": "david", "#children": []map[string]any{}}}, } - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("text key", func(t *testing.T) { s := base @@ -41,8 +41,8 @@ func TestRayFish_Decode(t *testing.T) { "$": "bob", "#children": []map[string]any{{"#name": "@charlie", "$": "david", "#children": []map[string]any{}}}, } - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("attr prefix", func(t *testing.T) { s := base @@ -53,8 +53,8 @@ func TestRayFish_Decode(t *testing.T) { "#text": "bob", "#children": []map[string]any{{"#name": "%charlie", "#text": "david", "#children": []map[string]any{}}}, } - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("namespace sep", func(t *testing.T) { s := base @@ -65,8 +65,8 @@ func TestRayFish_Decode(t *testing.T) { "#text": "bob", "#children": []map[string]any{{"#name": "@foo_**_charlie", "#text": "david", "#children": []map[string]any{}}}, } - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("trim space", func(t *testing.T) { s := base @@ -77,8 +77,8 @@ func TestRayFish_Decode(t *testing.T) { "#text": "bob", "#children": []map[string]any{{"#name": "@charlie", "#text": "david", "#children": []map[string]any{}}}, } - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("json value", func(t *testing.T) { s := base @@ -89,24 +89,24 @@ func TestRayFish_Decode(t *testing.T) { "#text": "value", "#children": []map[string]any{{"#name": "@charlie", "#text": "david", "#children": []map[string]any{}}}, } - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("json value error", func(t *testing.T) { s := base e := errors.New("parse error") s.JSONValue = func(s string, se xml.StartElement) (any, error) { return nil, e } d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) - ztesting.AssertEqualErr(t, "error not match", e, err) - ztesting.AssertEqual(t, "map is not nil", true, reflect.DeepEqual(nil, d)) + ztesting.AssertEqualErr(t, e, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(nil, d)) }) t.Run("inner json value error", func(t *testing.T) { s := base e := errors.New("parse error") s.JSONValue = func(s string, se xml.StartElement) (any, error) { return nil, e } d, err := s.Decode(xml.NewDecoder(strings.NewReader(`charlie`))) - ztesting.AssertEqualErr(t, "error not match", e, err) - ztesting.AssertEqual(t, "map is not nil", true, reflect.DeepEqual(nil, d)) + ztesting.AssertEqualErr(t, e, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(nil, d)) }) } @@ -129,8 +129,8 @@ func TestRayFish_WithEmptyValue(t *testing.T) { "#text": nil, "#children": []map[string]any{}, } - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("string", func(t *testing.T) { s := base @@ -141,14 +141,14 @@ func TestRayFish_WithEmptyValue(t *testing.T) { "#text": "", "#children": []map[string]any{}, } - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("panic", func(t *testing.T) { s := base defer func() { r := recover() - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseEmptyVal}, r.(error)) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseEmptyVal}, r.(error)) }() s.WithEmptyValue(123) }) diff --git a/zencoding/zxml/rayfish_encode_test.go b/zencoding/zxml/rayfish_encode_test.go index e67ab67..3e78279 100644 --- a/zencoding/zxml/rayfish_encode_test.go +++ b/zencoding/zxml/rayfish_encode_test.go @@ -30,9 +30,9 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("text key", func(t *testing.T) { s := base @@ -45,9 +45,9 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("attr prefix", func(t *testing.T) { s := base @@ -60,9 +60,9 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("namespace sep", func(t *testing.T) { s := base @@ -75,9 +75,9 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("xml value", func(t *testing.T) { s := base @@ -92,9 +92,9 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `value` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("xml value error", func(t *testing.T) { s := base @@ -110,7 +110,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", e, err) + ztesting.AssertEqualErr(t, e, err) }) t.Run("name not found", func(t *testing.T) { @@ -123,7 +123,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseJSONStruct}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseJSONStruct}, err) }) t.Run("name not string", func(t *testing.T) { s := base @@ -135,7 +135,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("name type error", func(t *testing.T) { s := base @@ -147,7 +147,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("nil name", func(t *testing.T) { s := base @@ -159,7 +159,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("text type error", func(t *testing.T) { s := base @@ -171,7 +171,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("nil text", func(t *testing.T) { s := base @@ -183,9 +183,9 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("nil attribute", func(t *testing.T) { s := base @@ -197,9 +197,9 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("attribute type error", func(t *testing.T) { s := base @@ -211,7 +211,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("children type invalid", func(t *testing.T) { s := base @@ -223,7 +223,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("children type invalid", func(t *testing.T) { s := base @@ -235,7 +235,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("invalid key", func(t *testing.T) { s := base @@ -247,7 +247,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseJSONStruct}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseJSONStruct}, err) }) t.Run("empty start elem", func(t *testing.T) { s := base @@ -259,7 +259,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) t.Run("token encode error", func(t *testing.T) { s := base @@ -272,7 +272,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) t.Run("end token encode error", func(t *testing.T) { s := base @@ -287,7 +287,7 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) t.Run("child encode error", func(t *testing.T) { s := base @@ -305,6 +305,6 @@ func TestRayfish_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) } diff --git a/zencoding/zxml/rayfish_test.go b/zencoding/zxml/rayfish_test.go index 0b9ab4d..14d9b70 100644 --- a/zencoding/zxml/rayfish_test.go +++ b/zencoding/zxml/rayfish_test.go @@ -63,7 +63,7 @@ func TestRayFish_Decode(t *testing.T) { xmlBytes, _ := os.ReadFile("./testdata/xml/" + tc.file + ".xml") jsonBytes, _ := os.ReadFile("./testdata/rayfish/" + tc.file + ".json") b, err := c.XMLtoJSON(xmlBytes) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if tc.err != nil { return } @@ -128,7 +128,7 @@ func TestRayFish_Encode(t *testing.T) { xmlBytes, _ := os.ReadFile("./testdata/rayfish/" + tc.file + ".xml") jsonBytes, _ := os.ReadFile("./testdata/rayfish/" + tc.file + ".json") b, err := c.JSONtoXML(jsonBytes) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if tc.err != nil { return } diff --git a/zencoding/zxml/simple_decode_test.go b/zencoding/zxml/simple_decode_test.go index 71f5690..db6b2b6 100644 --- a/zencoding/zxml/simple_decode_test.go +++ b/zencoding/zxml/simple_decode_test.go @@ -23,56 +23,56 @@ func TestSimple_Decode(t *testing.T) { s.TextKey = "#text" d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) want := map[string]any{"alice": map[string]any{"#text": "bob", "@charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("attr prefix", func(t *testing.T) { s := base s.AttrPrefix = "%" d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) want := map[string]any{"alice": map[string]any{"$": "bob", "%charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("namespace sep", func(t *testing.T) { s := base s.NamespaceSep = "_**_" d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) want := map[string]any{"alice": map[string]any{"$": "bob", "@foo_**_charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("trim space", func(t *testing.T) { s := base s.TrimSpace = true d, err := s.Decode(xml.NewDecoder(strings.NewReader(` bob `))) want := map[string]any{"alice": map[string]any{"$": "bob", "@charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("json value", func(t *testing.T) { s := base s.JSONValue = func(s string, se xml.StartElement) (any, error) { return "value", nil } d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) want := map[string]any{"alice": map[string]any{"$": "value", "@charlie": "david"}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("json value error", func(t *testing.T) { s := base e := errors.New("parse error") s.JSONValue = func(s string, se xml.StartElement) (any, error) { return nil, e } d, err := s.Decode(xml.NewDecoder(strings.NewReader(`bob`))) - ztesting.AssertEqualErr(t, "error not match", e, err) - ztesting.AssertEqual(t, "map is not nil", true, reflect.DeepEqual(nil, d)) + ztesting.AssertEqualErr(t, e, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(nil, d)) }) t.Run("inner json value error", func(t *testing.T) { s := base e := errors.New("parse error") s.JSONValue = func(s string, se xml.StartElement) (any, error) { return nil, e } d, err := s.Decode(xml.NewDecoder(strings.NewReader(`charlie`))) - ztesting.AssertEqualErr(t, "error not match", e, err) - ztesting.AssertEqual(t, "map is not nil", true, reflect.DeepEqual(nil, d)) + ztesting.AssertEqualErr(t, e, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(nil, d)) }) } @@ -93,7 +93,7 @@ func TestMergeChildren(t *testing.T) { t.Run(name, func(t *testing.T) { mergeChildren(tc.target, tc.keys, tc.children) for k, v := range tc.want { - ztesting.AssertEqual(t, "value not match", true, reflect.DeepEqual(v, tc.target[k])) + ztesting.AssertEqual(t, true, reflect.DeepEqual(v, tc.target[k])) } }) } @@ -112,30 +112,30 @@ func TestSimple_WithEmptyValue(t *testing.T) { s.WithEmptyValue(nil) d, err := s.Decode(xml.NewDecoder(strings.NewReader(``))) want := map[string]any{"alice": map[string]any{}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("string", func(t *testing.T) { s := base s.WithEmptyValue("") d, err := s.Decode(xml.NewDecoder(strings.NewReader(``))) want := map[string]any{"alice": map[string]any{"$": ""}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("map", func(t *testing.T) { s := base s.WithEmptyValue(map[string]any{}) d, err := s.Decode(xml.NewDecoder(strings.NewReader(``))) want := map[string]any{"alice": map[string]any{"$": map[string]any{}}} - ztesting.AssertEqual(t, "map not match", true, reflect.DeepEqual(want, d)) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(want, d)) + ztesting.AssertEqual(t, nil, err) }) t.Run("panic", func(t *testing.T) { s := base defer func() { r := recover() - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseEmptyVal}, r.(error)) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseEmptyVal}, r.(error)) }() s.WithEmptyValue(123) }) diff --git a/zencoding/zxml/simple_encode_test.go b/zencoding/zxml/simple_encode_test.go index d6a9e08..e3a5663 100644 --- a/zencoding/zxml/simple_encode_test.go +++ b/zencoding/zxml/simple_encode_test.go @@ -24,9 +24,9 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("attr prefix", func(t *testing.T) { s := base @@ -35,9 +35,9 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("namespace sep", func(t *testing.T) { s := base @@ -46,9 +46,9 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("xml value", func(t *testing.T) { s := base @@ -59,9 +59,9 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `value` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("xml value error", func(t *testing.T) { s := base @@ -73,7 +73,7 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", e, err) + ztesting.AssertEqualErr(t, e, err) }) t.Run("slice value error", func(t *testing.T) { @@ -82,7 +82,7 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("invalid text", func(t *testing.T) { s := base @@ -90,7 +90,7 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("array value invalid", func(t *testing.T) { s := base @@ -98,7 +98,7 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("invalid attribute", func(t *testing.T) { s := base @@ -106,7 +106,7 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseDataType}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseDataType}, err) }) t.Run("nil attribute", func(t *testing.T) { s := base @@ -114,9 +114,9 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqual(t, "error is not nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := `bob` - ztesting.AssertEqual(t, "xml not match", want, buf.String()) + ztesting.AssertEqual(t, want, buf.String()) }) t.Run("empty start elem", func(t *testing.T) { s := base @@ -124,7 +124,7 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) t.Run("token encode error", func(t *testing.T) { s := base @@ -133,7 +133,7 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) t.Run("end token encode error", func(t *testing.T) { s := base @@ -144,7 +144,7 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) t.Run("child encode error", func(t *testing.T) { s := base @@ -153,6 +153,6 @@ func TestSimple_Encode(t *testing.T) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) err := s.Encode(enc, input) - ztesting.AssertEqualErr(t, "error not match", &XMLError{Cause: CauseXMLEncoder}, err) + ztesting.AssertEqualErr(t, &XMLError{Cause: CauseXMLEncoder}, err) }) } diff --git a/zencoding/zxml/simple_test.go b/zencoding/zxml/simple_test.go index 6eb7951..10b1d9e 100644 --- a/zencoding/zxml/simple_test.go +++ b/zencoding/zxml/simple_test.go @@ -65,7 +65,7 @@ func TestSimple_Decode(t *testing.T) { xmlBytes, _ := os.ReadFile("./testdata/xml/" + tc.file + ".xml") jsonBytes, _ := os.ReadFile("./testdata/simple/" + tc.file + ".json") b, err := c.XMLtoJSON(xmlBytes) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if tc.err != nil { return } @@ -91,7 +91,7 @@ func TestSimple_Decode_short(t *testing.T) { xmlBytes, _ := os.ReadFile("./testdata/xml/" + tc.file + ".xml") jsonBytes, _ := os.ReadFile("./testdata/simple/" + tc.file + "_short.json") b, err := c.XMLtoJSON(xmlBytes) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if tc.err != nil { return } @@ -158,7 +158,7 @@ func TestSimple_Encode(t *testing.T) { xmlBytes, _ := os.ReadFile("./testdata/simple/" + tc.file + ".xml") jsonBytes, _ := os.ReadFile("./testdata/simple/" + tc.file + ".json") b, err := c.JSONtoXML(jsonBytes) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if tc.err != nil { return } @@ -184,7 +184,7 @@ func TestSimple_Encode_short(t *testing.T) { xmlBytes, _ := os.ReadFile("./testdata/simple/" + tc.file + ".xml") jsonBytes, _ := os.ReadFile("./testdata/simple/" + tc.file + "_short.json") b, err := c.JSONtoXML(jsonBytes) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if tc.err != nil { return } diff --git a/zencoding/zxml/tokenutil_test.go b/zencoding/zxml/tokenutil_test.go index 55f33c2..879259e 100644 --- a/zencoding/zxml/tokenutil_test.go +++ b/zencoding/zxml/tokenutil_test.go @@ -19,7 +19,7 @@ func TestXMLError_Error(t *testing.T) { Detail: "detail", } msg := err.Error() - ztesting.AssertEqual(t, "error message not match", "zxml: cause detail", msg) + ztesting.AssertEqual(t, "zxml: cause detail", msg) }) t.Run("with inner error", func(t *testing.T) { err := &XMLError{ @@ -28,7 +28,7 @@ func TestXMLError_Error(t *testing.T) { Detail: "detail", } msg := err.Error() - ztesting.AssertEqual(t, "error message not match", "zxml: cause detail [EOF]", msg) + ztesting.AssertEqual(t, "zxml: cause detail [EOF]", msg) }) } @@ -36,7 +36,7 @@ func TestXMLError_Unwrap(t *testing.T) { t.Parallel() err := &XMLError{Err: io.EOF, Cause: "cause"} inner := err.Unwrap() - ztesting.AssertEqualErr(t, "errors not match", io.EOF, inner) + ztesting.AssertEqualErr(t, io.EOF, inner) } func TestXMLError_Is(t *testing.T) { @@ -45,31 +45,31 @@ func TestXMLError_Is(t *testing.T) { err1 := &XMLError{Cause: "cause"} err2 := &XMLError{Cause: "cause"} same := err1.Is(err2) - ztesting.AssertEqual(t, "errors should be the same", true, same) + ztesting.AssertEqual(t, true, same) }) t.Run("same after unwrap", func(t *testing.T) { err1 := &XMLError{Cause: "cause"} err2 := fmt.Errorf("outer error [%w]", &XMLError{Cause: "cause"}) same := err1.Is(err2) - ztesting.AssertEqual(t, "errors should be the same", true, same) + ztesting.AssertEqual(t, true, same) }) t.Run("not same", func(t *testing.T) { err1 := &XMLError{Cause: "cause"} err2 := io.EOF same := err1.Is(err2) - ztesting.AssertEqual(t, "errors should not be the same", false, same) + ztesting.AssertEqual(t, false, same) }) t.Run("different cause", func(t *testing.T) { err1 := &XMLError{Cause: "cause1"} err2 := &XMLError{Cause: "cause2"} same := err1.Is(err2) - ztesting.AssertEqual(t, "errors should not be the same", false, same) + ztesting.AssertEqual(t, false, same) }) t.Run("nil", func(t *testing.T) { err1 := &XMLError{Cause: "cause"} err2 := error(nil) same := err1.Is(err2) - ztesting.AssertEqual(t, "errors should not be the same", false, same) + ztesting.AssertEqual(t, false, same) }) } @@ -88,7 +88,7 @@ func TestAttrName(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { out := attrName(tc.name, tc.prefix, tc.sep) - ztesting.AssertEqual(t, "result not match", tc.out, out) + ztesting.AssertEqual(t, tc.out, out) }) } } @@ -108,7 +108,7 @@ func TestTokenName(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { out := tokenName(tc.name, tc.sep) - ztesting.AssertEqual(t, "result not match", tc.out, out) + ztesting.AssertEqual(t, tc.out, out) }) } } @@ -136,7 +136,7 @@ func TestRestoreNamespace(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { out := restoreNamespace(tc.sep, tc.key) - ztesting.AssertEqual(t, "output not match", tc.out, out) + ztesting.AssertEqual(t, tc.out, out) }) } } @@ -161,8 +161,8 @@ func TestJsonValueToToken(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { token, err := jsonValueToToken(tc.trim, tc.value) - ztesting.AssertEqual(t, "token not match", true, reflect.DeepEqual(tc.token, token)) - ztesting.AssertEqualErr(t, "error should be nil", tc.err, err) + ztesting.AssertEqual(t, true, reflect.DeepEqual(tc.token, token)) + ztesting.AssertEqualErr(t, tc.err, err) }) } } diff --git a/zerrors/err_test.go b/zerrors/err_test.go index 3f418d9..45f472a 100644 --- a/zerrors/err_test.go +++ b/zerrors/err_test.go @@ -14,7 +14,7 @@ func TestErr_Unwrap(t *testing.T) { t.Parallel() e := &zerrors.Err{Cause: io.EOF} u := e.Unwrap() - ztesting.AssertEqual(t, "unwrapped error is incorrect.", io.EOF, u) + ztesting.AssertEqual(t, io.EOF, u) } func TestErr_Error(t *testing.T) { @@ -51,7 +51,7 @@ func TestErr_Error(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := tc.err.Error() - ztesting.AssertEqual(t, "error string not match", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -107,7 +107,7 @@ func TestErr_Is(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { is := tc.use.Is(tc.target) - ztesting.AssertEqual(t, "incorrect error identification.", tc.same, is) + ztesting.AssertEqual(t, tc.same, is) }) } } @@ -121,7 +121,7 @@ func TestErr_Map(t *testing.T) { "message": "m", "detail": "d", } - ztesting.AssertEqual(t, "maps not matched", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("cause", func(t *testing.T) { e := &zerrors.Err{Cause: io.EOF} @@ -129,7 +129,7 @@ func TestErr_Map(t *testing.T) { want := map[string]any{ "message": "EOF", } - ztesting.AssertEqual(t, "maps not matched", want, got["cause"].(map[string]any)) + ztesting.AssertEqual(t, want, got["cause"].(map[string]any)) }) } @@ -142,7 +142,7 @@ func TestErr_SlogAttrs(t *testing.T) { slog.String("message", "m"), slog.String("detail", "d"), } - ztesting.AssertEqual(t, "attrs not matched", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("cause", func(t *testing.T) { e := &zerrors.Err{Cause: io.EOF} @@ -152,6 +152,6 @@ func TestErr_SlogAttrs(t *testing.T) { slog.String("detail", ""), slog.GroupAttrs("cause", slog.String("message", "EOF")), } - ztesting.AssertEqual(t, "attrs not matched", want, got) + ztesting.AssertEqual(t, want, got) }) } diff --git a/zerrors/error_test.go b/zerrors/error_test.go index dc857d4..6bdadf7 100644 --- a/zerrors/error_test.go +++ b/zerrors/error_test.go @@ -14,12 +14,12 @@ func TestToMap(t *testing.T) { t.Parallel() t.Run("nil", func(t *testing.T) { m := zerrors.ToMap(nil) - ztesting.AssertEqual(t, "returned map mismatch", nil, m) + ztesting.AssertEqual(t, nil, m) }) t.Run("primitive error", func(t *testing.T) { m := zerrors.ToMap(io.EOF) want := map[string]any{"message": "EOF"} - ztesting.AssertEqual(t, "returned map mismatch", want, m) + ztesting.AssertEqual(t, want, m) }) t.Run("wrapped error", func(t *testing.T) { err := fmt.Errorf("outer error [%w]", io.EOF) @@ -30,16 +30,16 @@ func TestToMap(t *testing.T) { "message": "EOF", }, } - ztesting.AssertEqual(t, "msg mismatch", want, m) + ztesting.AssertEqual(t, want, m) }) t.Run("interface", func(t *testing.T) { def := zerrors.NewDefinition("c", "k", "m", nil) err := def.NewStack(nil) m := zerrors.ToMap(err) - ztesting.AssertEqual(t, "code mismatch", "c", m["code"]) - ztesting.AssertEqual(t, "kind mismatch", "k", m["kind"]) - ztesting.AssertEqual(t, "message mismatch", "m", m["message"]) - ztesting.AssertEqual(t, "empty frame", true, len(m["frames"].([]string)) > 0) + ztesting.AssertEqual(t, "c", m["code"]) + ztesting.AssertEqual(t, "k", m["kind"]) + ztesting.AssertEqual(t, "m", m["message"]) + ztesting.AssertEqual(t, true, len(m["frames"].([]string)) > 0) }) } @@ -47,12 +47,12 @@ func TestToSlogAttrs(t *testing.T) { t.Parallel() t.Run("nil", func(t *testing.T) { m := zerrors.ToSlogAttrs(nil) - ztesting.AssertEqual(t, "attrs mismatch", nil, m) + ztesting.AssertEqual(t, nil, m) }) t.Run("primitive error", func(t *testing.T) { m := zerrors.ToSlogAttrs(io.EOF) want := []slog.Attr{slog.String("message", "EOF")} - ztesting.AssertEqual(t, "attrs mismatch", want, m) + ztesting.AssertEqual(t, want, m) }) t.Run("wrapped error", func(t *testing.T) { err := fmt.Errorf("outer error [%w]", io.EOF) @@ -61,7 +61,7 @@ func TestToSlogAttrs(t *testing.T) { slog.String("message", "outer error [EOF]"), slog.GroupAttrs("cause", slog.String("message", "EOF")), } - ztesting.AssertEqual(t, "attrs mismatch", want, m) + ztesting.AssertEqual(t, want, m) }) t.Run("interface", func(t *testing.T) { def := zerrors.NewDefinition("c", "k", "m", nil) @@ -72,7 +72,7 @@ func TestToSlogAttrs(t *testing.T) { slog.String("kind", "k"), slog.String("message", "m"), } - ztesting.AssertEqual(t, "attrs mismatch", want, m) + ztesting.AssertEqual(t, want, m) }) } @@ -80,7 +80,7 @@ func TestError_Unwrap(t *testing.T) { t.Parallel() e := &zerrors.Error{Cause: io.EOF} u := e.Unwrap() - ztesting.AssertEqual(t, "unwrapped error is incorrect.", io.EOF, u) + ztesting.AssertEqual(t, io.EOF, u) } func TestError_Error(t *testing.T) { @@ -121,7 +121,7 @@ func TestError_Error(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := tc.err.Error() - ztesting.AssertEqual(t, "error string not match", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -187,7 +187,7 @@ func TestError_Is(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { is := tc.use.Is(tc.target) - ztesting.AssertEqual(t, "incorrect error identification.", tc.same, is) + ztesting.AssertEqual(t, tc.same, is) }) } } @@ -202,7 +202,7 @@ func TestError_Map(t *testing.T) { "kind": "k", "message": "m", } - ztesting.AssertEqual(t, "maps not matched", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("cause", func(t *testing.T) { e := &zerrors.Error{Cause: io.EOF} @@ -210,7 +210,7 @@ func TestError_Map(t *testing.T) { want := map[string]any{ "message": "EOF", } - ztesting.AssertEqual(t, "maps not matched", want, got["cause"].(map[string]any)) + ztesting.AssertEqual(t, want, got["cause"].(map[string]any)) }) t.Run("attrs", func(t *testing.T) { e := &zerrors.Error{Attrs: map[string]string{"foo": "bar"}} @@ -218,13 +218,13 @@ func TestError_Map(t *testing.T) { want := map[string]string{ "foo": "bar", } - ztesting.AssertEqual(t, "maps not matched", want, got["attrs"].(map[string]string)) + ztesting.AssertEqual(t, want, got["attrs"].(map[string]string)) }) t.Run("frames", func(t *testing.T) { def := zerrors.NewDefinition("c", "k", "m", nil) e := def.NewStack(nil) got := e.Map() - ztesting.AssertEqual(t, "empty frame", true, len(got["frames"].([]string)) > 0) + ztesting.AssertEqual(t, true, len(got["frames"].([]string)) > 0) }) } @@ -238,7 +238,7 @@ func TestError_SlogAttrs(t *testing.T) { slog.String("kind", "k"), slog.String("message", "m"), } - ztesting.AssertEqual(t, "attrs not matched", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("cause", func(t *testing.T) { e := &zerrors.Error{Cause: io.EOF} @@ -249,7 +249,7 @@ func TestError_SlogAttrs(t *testing.T) { slog.String("message", ""), slog.GroupAttrs("cause", slog.String("message", "EOF")), } - ztesting.AssertEqual(t, "attrs not matched", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("attrs", func(t *testing.T) { e := &zerrors.Error{Attrs: map[string]string{"foo": "bar"}} @@ -260,7 +260,7 @@ func TestError_SlogAttrs(t *testing.T) { slog.String("message", ""), slog.GroupAttrs("attrs", slog.String("foo", "bar")), } - ztesting.AssertEqual(t, "attrs not matched", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("frames", func(t *testing.T) { def := zerrors.NewDefinition("c", "k", "m", nil) @@ -268,7 +268,7 @@ func TestError_SlogAttrs(t *testing.T) { got := e.SlogAttrs() for _, a := range got { if a.Key == "frames" { - ztesting.AssertEqual(t, "empty frame", true, len(a.Value.Any().([]string)) > 0) + ztesting.AssertEqual(t, true, len(a.Value.Any().([]string)) > 0) return } } @@ -322,7 +322,7 @@ func TestDefinition_Is(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { is := tc.def.Is(tc.target) - ztesting.AssertEqual(t, "incorrect error identification.", tc.same, is) + ztesting.AssertEqual(t, tc.same, is) }) } } @@ -333,52 +333,52 @@ func TestDefinition_New(t *testing.T) { var ed zerrors.Definition e := ed.New(nil) w := zerrors.Error{} - ztesting.AssertEqual(t, "code mismatch.", w.Code, e.Code) - ztesting.AssertEqual(t, "kind mismatch.", w.Kind, e.Kind) - ztesting.AssertEqual(t, "message mismatch.", w.Message, e.Message) - ztesting.AssertEqual(t, "attrs mismatch.", w.Attrs, e.Attrs) - ztesting.AssertEqual(t, "unexpected frame length.", 0, len(e.Frames)) - ztesting.AssertEqual(t, "cause mismatch.", nil, e.Cause) + ztesting.AssertEqual(t, w.Code, e.Code) + ztesting.AssertEqual(t, w.Kind, e.Kind) + ztesting.AssertEqual(t, w.Message, e.Message) + ztesting.AssertEqual(t, w.Attrs, e.Attrs) + ztesting.AssertEqual(t, 0, len(e.Frames)) + ztesting.AssertEqual(t, nil, e.Cause) }) t.Run("non inner error", func(t *testing.T) { e := (&zerrors.Definition{Code: "c", Kind: "k", Message: "m"}).New(nil) w := zerrors.Error{Code: "c", Kind: "k", Message: "m"} - ztesting.AssertEqual(t, "code mismatch.", w.Code, e.Code) - ztesting.AssertEqual(t, "kind mismatch.", w.Kind, e.Kind) - ztesting.AssertEqual(t, "message mismatch.", w.Message, e.Message) - ztesting.AssertEqual(t, "attrs mismatch.", w.Attrs, e.Attrs) - ztesting.AssertEqual(t, "unexpected frame length.", 0, len(e.Frames)) - ztesting.AssertEqual(t, "cause mismatch.", nil, e.Cause) + ztesting.AssertEqual(t, w.Code, e.Code) + ztesting.AssertEqual(t, w.Kind, e.Kind) + ztesting.AssertEqual(t, w.Message, e.Message) + ztesting.AssertEqual(t, w.Attrs, e.Attrs) + ztesting.AssertEqual(t, 0, len(e.Frames)) + ztesting.AssertEqual(t, nil, e.Cause) }) t.Run("inner error", func(t *testing.T) { e := (&zerrors.Definition{Code: "c", Kind: "k", Message: "m"}).New(io.EOF) w := zerrors.Error{Code: "c", Kind: "k", Message: "m"} - ztesting.AssertEqual(t, "code mismatch.", w.Code, e.Code) - ztesting.AssertEqual(t, "kind mismatch.", w.Kind, e.Kind) - ztesting.AssertEqual(t, "message mismatch.", w.Message, e.Message) - ztesting.AssertEqual(t, "attrs mismatch.", w.Attrs, e.Attrs) - ztesting.AssertEqual(t, "unexpected frame length.", 0, len(e.Frames)) - ztesting.AssertEqual(t, "cause mismatch.", io.EOF, e.Cause) + ztesting.AssertEqual(t, w.Code, e.Code) + ztesting.AssertEqual(t, w.Kind, e.Kind) + ztesting.AssertEqual(t, w.Message, e.Message) + ztesting.AssertEqual(t, w.Attrs, e.Attrs) + ztesting.AssertEqual(t, 0, len(e.Frames)) + ztesting.AssertEqual(t, io.EOF, e.Cause) }) t.Run("attrs error", func(t *testing.T) { e := (&zerrors.Definition{Code: "c", Kind: "k", Message: "m", Attrs: map[string]string{"foo": "bar"}}).New(nil) w := zerrors.Error{Code: "c", Kind: "k", Message: "m", Attrs: map[string]string{"foo": "bar"}} - ztesting.AssertEqual(t, "code mismatch.", w.Code, e.Code) - ztesting.AssertEqual(t, "kind mismatch.", w.Kind, e.Kind) - ztesting.AssertEqual(t, "message mismatch.", w.Message, e.Message) - ztesting.AssertEqual(t, "attrs mismatch.", w.Attrs, e.Attrs) - ztesting.AssertEqual(t, "unexpected frame length.", 0, len(e.Frames)) - ztesting.AssertEqual(t, "cause mismatch.", nil, e.Cause) + ztesting.AssertEqual(t, w.Code, e.Code) + ztesting.AssertEqual(t, w.Kind, e.Kind) + ztesting.AssertEqual(t, w.Message, e.Message) + ztesting.AssertEqual(t, w.Attrs, e.Attrs) + ztesting.AssertEqual(t, 0, len(e.Frames)) + ztesting.AssertEqual(t, nil, e.Cause) }) t.Run("format message", func(t *testing.T) { e := (&zerrors.Definition{Code: "c", Kind: "k", Message: "foo=%s"}).New(nil, "xxx") w := zerrors.Error{Code: "c", Kind: "k", Message: "foo=xxx"} - ztesting.AssertEqual(t, "code mismatch.", w.Code, e.Code) - ztesting.AssertEqual(t, "kind mismatch.", w.Kind, e.Kind) - ztesting.AssertEqual(t, "message mismatch.", w.Message, e.Message) - ztesting.AssertEqual(t, "attrs mismatch.", w.Attrs, e.Attrs) - ztesting.AssertEqual(t, "unexpected frame length.", 0, len(e.Frames)) - ztesting.AssertEqual(t, "cause mismatch.", nil, e.Cause) + ztesting.AssertEqual(t, w.Code, e.Code) + ztesting.AssertEqual(t, w.Kind, e.Kind) + ztesting.AssertEqual(t, w.Message, e.Message) + ztesting.AssertEqual(t, w.Attrs, e.Attrs) + ztesting.AssertEqual(t, 0, len(e.Frames)) + ztesting.AssertEqual(t, nil, e.Cause) }) } @@ -388,32 +388,32 @@ func TestDefinition_NewStack(t *testing.T) { var ed zerrors.Definition e := ed.NewStack(nil) w := zerrors.Error{} - ztesting.AssertEqual(t, "code mismatch.", w.Code, e.Code) - ztesting.AssertEqual(t, "kind mismatch.", w.Kind, e.Kind) - ztesting.AssertEqual(t, "message mismatch.", w.Message, e.Message) - ztesting.AssertEqual(t, "attrs mismatch.", w.Attrs, e.Attrs) - ztesting.AssertEqual(t, "unexpected frame length.", true, len(e.Frames) > 0) - ztesting.AssertEqual(t, "cause mismatch.", nil, e.Cause) + ztesting.AssertEqual(t, w.Code, e.Code) + ztesting.AssertEqual(t, w.Kind, e.Kind) + ztesting.AssertEqual(t, w.Message, e.Message) + ztesting.AssertEqual(t, w.Attrs, e.Attrs) + ztesting.AssertEqual(t, true, len(e.Frames) > 0) + ztesting.AssertEqual(t, nil, e.Cause) }) t.Run("cause without stack", func(t *testing.T) { e := (&zerrors.Definition{Code: "c", Kind: "k", Message: "m", Attrs: map[string]string{"foo": "bar"}}).NewStack(io.EOF) w := zerrors.Error{Code: "c", Kind: "k", Message: "m", Attrs: map[string]string{"foo": "bar"}} - ztesting.AssertEqual(t, "code mismatch.", w.Code, e.Code) - ztesting.AssertEqual(t, "kind mismatch.", w.Kind, e.Kind) - ztesting.AssertEqual(t, "message mismatch.", w.Message, e.Message) - ztesting.AssertEqual(t, "attrs mismatch.", w.Attrs, e.Attrs) - ztesting.AssertEqual(t, "unexpected frame length.", true, len(e.Frames) > 0) - ztesting.AssertEqual(t, "cause mismatch.", io.EOF, e.Cause) + ztesting.AssertEqual(t, w.Code, e.Code) + ztesting.AssertEqual(t, w.Kind, e.Kind) + ztesting.AssertEqual(t, w.Message, e.Message) + ztesting.AssertEqual(t, w.Attrs, e.Attrs) + ztesting.AssertEqual(t, true, len(e.Frames) > 0) + ztesting.AssertEqual(t, io.EOF, e.Cause) }) t.Run("inner error with stack", func(t *testing.T) { inner := &zerrors.Error{Frames: []zerrors.Frame{{}, {}}} e := (&zerrors.Definition{Code: "c", Kind: "k", Message: "m", Attrs: map[string]string{"foo": "bar"}}).NewStack(inner) w := zerrors.Error{Code: "c", Kind: "k", Message: "m", Attrs: map[string]string{"foo": "bar"}} - ztesting.AssertEqual(t, "code mismatch.", w.Code, e.Code) - ztesting.AssertEqual(t, "kind mismatch.", w.Kind, e.Kind) - ztesting.AssertEqual(t, "message mismatch.", w.Message, e.Message) - ztesting.AssertEqual(t, "attrs mismatch.", w.Attrs, e.Attrs) - ztesting.AssertEqual(t, "unexpected frame length.", 0, len(e.Frames)) - ztesting.AssertEqual(t, "cause mismatch.", error(inner), e.Cause) + ztesting.AssertEqual(t, w.Code, e.Code) + ztesting.AssertEqual(t, w.Kind, e.Kind) + ztesting.AssertEqual(t, w.Message, e.Message) + ztesting.AssertEqual(t, w.Attrs, e.Attrs) + ztesting.AssertEqual(t, 0, len(e.Frames)) + ztesting.AssertEqual(t, error(inner), e.Cause) }) } diff --git a/zerrors/frame_test.go b/zerrors/frame_test.go index a2326d6..67bb2cc 100644 --- a/zerrors/frame_test.go +++ b/zerrors/frame_test.go @@ -10,22 +10,22 @@ func TestCallerFrames(t *testing.T) { t.Parallel() t.Run("skip=0", func(t *testing.T) { fs := callerFrames(0, 1) - ztesting.AssertEqual(t, "length not match", 1, len(fs)) + ztesting.AssertEqual(t, 1, len(fs)) }) t.Run("skip=-999", func(t *testing.T) { fs := callerFrames(-999, 1) - ztesting.AssertEqual(t, "length not match", 1, len(fs)) + ztesting.AssertEqual(t, 1, len(fs)) }) t.Run("skip=999", func(t *testing.T) { fs := callerFrames(999, 1) - ztesting.AssertEqual(t, "length not match", 0, len(fs)) + ztesting.AssertEqual(t, 0, len(fs)) }) t.Run("size=0", func(t *testing.T) { fs := callerFrames(0, 0) - ztesting.AssertEqual(t, "length not match", 0, len(fs)) + ztesting.AssertEqual(t, 0, len(fs)) }) t.Run("size=2", func(t *testing.T) { fs := callerFrames(0, 2) - ztesting.AssertEqual(t, "length not match", 2, len(fs)) + ztesting.AssertEqual(t, 2, len(fs)) }) } diff --git a/zerrors/trace_test.go b/zerrors/trace_test.go index d3e284f..bb7f39b 100644 --- a/zerrors/trace_test.go +++ b/zerrors/trace_test.go @@ -54,7 +54,7 @@ func TestInitTrace(t *testing.T) { initTrace(tc.writeTo, func(dir, pattern string) (*os.File, error) { return os.Stdin, nil }) - ztesting.AssertEqual(t, "writer not matched.", tc.wants, writer) + ztesting.AssertEqual(t, tc.wants, writer) }) } } @@ -146,7 +146,7 @@ func TestWriteWithPrefix(t *testing.T) { writeWithPrefix(&buf, v) } result := buf.String() - ztesting.AssertEqual(t, "written string does not match.", tc.wants, result) + ztesting.AssertEqual(t, tc.wants, result) }) } } diff --git a/zerrors/util_test.go b/zerrors/util_test.go index 5286c63..e37ae60 100644 --- a/zerrors/util_test.go +++ b/zerrors/util_test.go @@ -14,16 +14,16 @@ func TestUnwrapErr(t *testing.T) { t.Parallel() t.Run("nil", func(t *testing.T) { err := zerrors.UnwrapErr(nil) - ztesting.AssertEqual(t, "unexpected error returned.", nil, err) + ztesting.AssertEqual(t, nil, err) }) t.Run("has interface", func(t *testing.T) { err := fmt.Errorf("outer error [%w]", io.EOF) err = zerrors.UnwrapErr(err) - ztesting.AssertEqual(t, "unexpected error returned.", io.EOF, err) + ztesting.AssertEqual(t, io.EOF, err) }) t.Run("has no interface", func(t *testing.T) { err := zerrors.UnwrapErr(errors.Join(io.EOF, io.EOF)) // Implements interface{ Unwrap() []error } - ztesting.AssertEqual(t, "unexpected error returned.", nil, err) + ztesting.AssertEqual(t, nil, err) }) } @@ -31,17 +31,17 @@ func TestUnwrapErrs(t *testing.T) { t.Parallel() t.Run("nil", func(t *testing.T) { errs := zerrors.UnwrapErrs(nil) - ztesting.AssertEqual(t, "unexpected error returned.", nil, errs) + ztesting.AssertEqual(t, nil, errs) }) t.Run("has no interface", func(t *testing.T) { err := fmt.Errorf("outer error [%w]", io.EOF) errs := zerrors.UnwrapErrs(err) - ztesting.AssertEqual(t, "unexpected error returned.", nil, errs) + ztesting.AssertEqual(t, nil, errs) }) t.Run("has interface", func(t *testing.T) { errs := zerrors.UnwrapErrs(errors.Join(io.EOF, io.ErrUnexpectedEOF)) // Implements interface{ Unwrap() []error } - ztesting.AssertEqual(t, "wrong number of errors.", 2, len(errs)) - ztesting.AssertEqual(t, "wrong unwrapped error returned.", []error{io.EOF, io.ErrUnexpectedEOF}, errs) + ztesting.AssertEqual(t, 2, len(errs)) + ztesting.AssertEqual(t, []error{io.EOF, io.ErrUnexpectedEOF}, errs) }) } diff --git a/zhash/hash_test.go b/zhash/hash_test.go index d66366c..bbfaa34 100644 --- a/zhash/hash_test.go +++ b/zhash/hash_test.go @@ -18,12 +18,12 @@ func TestRegisterHash(t *testing.T) { got := FNV32.New() t.Log(h.Sum(nil)) t.Log(got.Sum(nil)) - ztesting.AssertEqual(t, "hash not match", true, slices.Equal(h.Sum(nil), got.Sum(nil))) + ztesting.AssertEqual(t, true, slices.Equal(h.Sum(nil), got.Sum(nil))) }) t.Run("failed", func(t *testing.T) { defer func() { r := recover() - ztesting.AssertEqualErr(t, "error not match", ErrUnknown, r.(error)) + ztesting.AssertEqualErr(t, ErrUnknown, r.(error)) }() RegisterHash(maxHash, nil) }) @@ -51,7 +51,7 @@ func TestHash_String(t *testing.T) { for name, tc := range testCase { t.Run(name, func(t *testing.T) { got := tc.h.String() - ztesting.AssertEqual(t, "name does not match", tc.s, got) + ztesting.AssertEqual(t, tc.s, got) }) } } @@ -61,7 +61,7 @@ func TestHash_Size(t *testing.T) { t.Run("panic unknown", func(t *testing.T) { defer func() { r := recover() - ztesting.AssertEqualErr(t, "error not match", ErrUnknown, r.(error)) + ztesting.AssertEqualErr(t, ErrUnknown, r.(error)) }() maxHash.Size() }) @@ -85,7 +85,7 @@ func TestHash_Size(t *testing.T) { for name, tc := range testCase { t.Run(name, func(t *testing.T) { got := tc.h.Size() - ztesting.AssertEqual(t, "size does not match", tc.s, got) + ztesting.AssertEqual(t, tc.s, got) }) } } @@ -94,12 +94,12 @@ func TestHash_Available(t *testing.T) { t.Parallel() t.Run("max hash", func(t *testing.T) { got := maxHash.Available() - ztesting.AssertEqual(t, "unknown alg is available", false, got) + ztesting.AssertEqual(t, false, got) }) t.Run("available", func(t *testing.T) { RegisterHash(FNV32, func() hash.Hash { return fnv.New32() }) got := FNV32.Available() - ztesting.AssertEqual(t, "unknown alg is available", true, got) + ztesting.AssertEqual(t, true, got) }) } @@ -108,7 +108,7 @@ func TestHash_New(t *testing.T) { t.Run("not available", func(t *testing.T) { defer func() { r := recover() - ztesting.AssertEqualErr(t, "error not match", ErrNotAvailable, r.(error)) + ztesting.AssertEqualErr(t, ErrNotAvailable, r.(error)) }() maxHash.New() }) @@ -116,7 +116,7 @@ func TestHash_New(t *testing.T) { RegisterHash(FNV32, func() hash.Hash { return fnv.New32() }) h := FNV32.New() h.Write([]byte("test")) - ztesting.AssertEqual(t, "invalid hash", "bc2c0be9", hex.EncodeToString(h.Sum(nil))) + ztesting.AssertEqual(t, "bc2c0be9", hex.EncodeToString(h.Sum(nil))) }) } @@ -125,7 +125,7 @@ func TestHash_NewFunc(t *testing.T) { t.Run("not available", func(t *testing.T) { defer func() { r := recover() - ztesting.AssertEqualErr(t, "error not match", ErrNotAvailable, r.(error)) + ztesting.AssertEqualErr(t, ErrNotAvailable, r.(error)) }() maxHash.NewFunc() }) @@ -134,7 +134,7 @@ func TestHash_NewFunc(t *testing.T) { f := FNV32.NewFunc() h := f() h.Write([]byte("test")) - ztesting.AssertEqual(t, "invalid hash", "bc2c0be9", hex.EncodeToString(h.Sum(nil))) + ztesting.AssertEqual(t, "bc2c0be9", hex.EncodeToString(h.Sum(nil))) }) } @@ -143,14 +143,14 @@ func TestHash_Sum(t *testing.T) { t.Run("not available", func(t *testing.T) { defer func() { r := recover() - ztesting.AssertEqualErr(t, "error not match", ErrNotAvailable, r.(error)) + ztesting.AssertEqualErr(t, ErrNotAvailable, r.(error)) }() maxHash.Sum([]byte("test")) }) t.Run("available", func(t *testing.T) { RegisterHash(FNV32, func() hash.Hash { return fnv.New32() }) got := FNV32.Sum([]byte("test")) - ztesting.AssertEqual(t, "invalid returned value", "bc2c0be9", hex.EncodeToString(got)) + ztesting.AssertEqual(t, "bc2c0be9", hex.EncodeToString(got)) }) } @@ -160,13 +160,13 @@ func TestHash_Equal(t *testing.T) { RegisterHash(FNV32, func() hash.Hash { return fnv.New32() }) b, _ := hex.DecodeString("bc2c0be9") got := FNV32.Equal(b, []byte("test")) - ztesting.AssertEqual(t, "invalid compare result", true, got) + ztesting.AssertEqual(t, true, got) }) t.Run("not equal", func(t *testing.T) { RegisterHash(FNV32, func() hash.Hash { return fnv.New32() }) b, _ := hex.DecodeString("bc2c0be9") got := FNV32.Equal(b, []byte("wrong")) - ztesting.AssertEqual(t, "invalid compare result", false, got) + ztesting.AssertEqual(t, false, got) }) } @@ -176,16 +176,16 @@ func TestHash_Compare(t *testing.T) { RegisterHash(FNV32, func() hash.Hash { return fnv.New32() }) b, _ := hex.DecodeString("bc2c0be9") got := FNV32.Compare(b, []byte("test")) - ztesting.AssertEqualErr(t, "invalid compare result", nil, got) + ztesting.AssertEqualErr(t, nil, got) }) t.Run("not equal", func(t *testing.T) { RegisterHash(FNV32, func() hash.Hash { return fnv.New32() }) b, _ := hex.DecodeString("bc2c0be9") got := FNV32.Compare(b, []byte("wrong")) - ztesting.AssertEqualErr(t, "invalid compare result", ErrNotMatch, got) + ztesting.AssertEqualErr(t, ErrNotMatch, got) }) t.Run("alg unknown", func(t *testing.T) { err := maxHash.Compare([]byte("xxx"), []byte("yyy")) - ztesting.AssertEqualErr(t, "error not match", ErrNotAvailable, err) + ztesting.AssertEqualErr(t, ErrNotAvailable, err) }) } diff --git a/zhash/zcrc32/crc32_test.go b/zhash/zcrc32/crc32_test.go index fc49019..e28ac1a 100644 --- a/zhash/zcrc32/crc32_test.go +++ b/zhash/zcrc32/crc32_test.go @@ -11,9 +11,9 @@ import ( func TestAvailable(t *testing.T) { t.Parallel() - ztesting.AssertEqual(t, "hash not available", true, zhash.CRC32IEEE.Available()) - ztesting.AssertEqual(t, "hash not available", true, zhash.CRC32Castagnoli.Available()) - ztesting.AssertEqual(t, "hash not available", true, zhash.CRC32Koopman.Available()) + ztesting.AssertEqual(t, true, zhash.CRC32IEEE.Available()) + ztesting.AssertEqual(t, true, zhash.CRC32Castagnoli.Available()) + ztesting.AssertEqual(t, true, zhash.CRC32Koopman.Available()) } func TestSum(t *testing.T) { @@ -38,7 +38,7 @@ func TestSum(t *testing.T) { for name, tc := range testCase { t.Run(name, func(t *testing.T) { got := tc.hf([]byte(tc.data)) - ztesting.AssertEqual(t, "hash not match", tc.want, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.want, hex.EncodeToString(got)) }) } } @@ -65,7 +65,7 @@ func TestEqualSum(t *testing.T) { t.Run(name, func(t *testing.T) { d, _ := hex.DecodeString(tc.sum) got := tc.cf([]byte(tc.data), d) - ztesting.AssertEqual(t, "invalid compare result", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -84,7 +84,7 @@ func TestHashSum(t *testing.T) { for name, tc := range testCase { t.Run(name, func(t *testing.T) { got := tc.h.Sum([]byte(tc.data)) - ztesting.AssertEqual(t, "hash not match", tc.want, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.want, hex.EncodeToString(got)) }) } } diff --git a/zhash/zcrc64/crc64_test.go b/zhash/zcrc64/crc64_test.go index d167c65..bfc2a42 100644 --- a/zhash/zcrc64/crc64_test.go +++ b/zhash/zcrc64/crc64_test.go @@ -11,8 +11,8 @@ import ( func TestAvailable(t *testing.T) { t.Parallel() - ztesting.AssertEqual(t, "hash not available", true, zhash.CRC64ISO.Available()) - ztesting.AssertEqual(t, "hash not available", true, zhash.CRC64ECMA.Available()) + ztesting.AssertEqual(t, true, zhash.CRC64ISO.Available()) + ztesting.AssertEqual(t, true, zhash.CRC64ECMA.Available()) } func TestSum(t *testing.T) { @@ -35,7 +35,7 @@ func TestSum(t *testing.T) { for name, tc := range testCase { t.Run(name, func(t *testing.T) { got := tc.hf([]byte(tc.data)) - ztesting.AssertEqual(t, "hash not match", tc.want, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.want, hex.EncodeToString(got)) }) } } @@ -59,7 +59,7 @@ func TestEqualSum(t *testing.T) { t.Run(name, func(t *testing.T) { d, _ := hex.DecodeString(tc.sum) got := tc.cf([]byte(tc.data), d) - ztesting.AssertEqual(t, "invalid compare result", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -77,7 +77,7 @@ func TestHashSum(t *testing.T) { for name, tc := range testCase { t.Run(name, func(t *testing.T) { got := tc.h.Sum([]byte(tc.data)) - ztesting.AssertEqual(t, "hash not match", tc.want, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.want, hex.EncodeToString(got)) }) } } diff --git a/zhash/zfnv/fnv_test.go b/zhash/zfnv/fnv_test.go index d7a2fcc..b17d8ea 100644 --- a/zhash/zfnv/fnv_test.go +++ b/zhash/zfnv/fnv_test.go @@ -11,12 +11,12 @@ import ( func TestAvailable(t *testing.T) { t.Parallel() - ztesting.AssertEqual(t, "hash not available", true, zhash.FNV32.Available()) - ztesting.AssertEqual(t, "hash not available", true, zhash.FNV32a.Available()) - ztesting.AssertEqual(t, "hash not available", true, zhash.FNV64.Available()) - ztesting.AssertEqual(t, "hash not available", true, zhash.FNV64a.Available()) - ztesting.AssertEqual(t, "hash not available", true, zhash.FNV128.Available()) - ztesting.AssertEqual(t, "hash not available", true, zhash.FNV128a.Available()) + ztesting.AssertEqual(t, true, zhash.FNV32.Available()) + ztesting.AssertEqual(t, true, zhash.FNV32a.Available()) + ztesting.AssertEqual(t, true, zhash.FNV64.Available()) + ztesting.AssertEqual(t, true, zhash.FNV64a.Available()) + ztesting.AssertEqual(t, true, zhash.FNV128.Available()) + ztesting.AssertEqual(t, true, zhash.FNV128a.Available()) } func TestSum(t *testing.T) { @@ -51,7 +51,7 @@ func TestSum(t *testing.T) { for name, tc := range testCase { t.Run(name, func(t *testing.T) { got := tc.hf([]byte(tc.data)) - ztesting.AssertEqual(t, "hash not match", tc.want, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.want, hex.EncodeToString(got)) }) } } @@ -87,7 +87,7 @@ func TestEqualSum(t *testing.T) { t.Run(name, func(t *testing.T) { d, _ := hex.DecodeString(tc.sum) got := tc.cf([]byte(tc.data), d) - ztesting.AssertEqual(t, "invalid compare result", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -109,7 +109,7 @@ func TestHashSum(t *testing.T) { for name, tc := range testCase { t.Run(name, func(t *testing.T) { got := tc.h.Sum([]byte(tc.data)) - ztesting.AssertEqual(t, "hash not match", tc.want, hex.EncodeToString(got)) + ztesting.AssertEqual(t, tc.want, hex.EncodeToString(got)) }) } } diff --git a/zio/copy_test.go b/zio/copy_test.go index e2ad463..3368ea7 100644 --- a/zio/copy_test.go +++ b/zio/copy_test.go @@ -18,47 +18,47 @@ func TestCopy(t *testing.T) { r := strings.NewReader("1234567890") w := bytes.NewBuffer(nil) written, err := zio.Copy(w, r) - ztesting.AssertEqual(t, "invalid written bytes", 10, written) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, 10, written) + ztesting.AssertEqual(t, nil, err) }) t.Run("reader EOF", func(t *testing.T) { r := ziotest.ErrReaderWith(strings.NewReader("1234567890"), 5, io.EOF) w := bytes.NewBuffer(nil) written, err := zio.Copy(w, r) - ztesting.AssertEqual(t, "invalid written bytes", 5, written) - ztesting.AssertEqual(t, "error not matched", nil, err) + ztesting.AssertEqual(t, 5, written) + ztesting.AssertEqual(t, nil, err) }) t.Run("reader UnexpectedEOF", func(t *testing.T) { r := ziotest.ErrReaderWith(strings.NewReader("1234567890"), 5, io.ErrUnexpectedEOF) w := bytes.NewBuffer(nil) written, err := zio.Copy(w, r) - ztesting.AssertEqual(t, "invalid written bytes", 5, written) - ztesting.AssertEqual(t, "error not matched", io.ErrUnexpectedEOF, err) + ztesting.AssertEqual(t, 5, written) + ztesting.AssertEqual(t, io.ErrUnexpectedEOF, err) }) t.Run("write error", func(t *testing.T) { r := strings.NewReader("1234567890") w := ziotest.ErrWriterWith(bytes.NewBuffer(nil), 5, io.ErrClosedPipe) written, err := zio.Copy(w, r) - ztesting.AssertEqual(t, "invalid written bytes", 5, written) - ztesting.AssertEqual(t, "error not matched", io.ErrClosedPipe, err) + ztesting.AssertEqual(t, 5, written) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) }) t.Run("read write error", func(t *testing.T) { r := ziotest.ErrReaderWith(strings.NewReader("1234567890"), 5, io.ErrUnexpectedEOF) w := ziotest.ErrWriterWith(bytes.NewBuffer(nil), 4, io.ErrClosedPipe) written, err := zio.Copy(w, r) - ztesting.AssertEqual(t, "invalid written bytes", 4, written) // Write error is returned. - ztesting.AssertEqual(t, "error not matched", io.ErrClosedPipe, err) + ztesting.AssertEqual(t, 4, written) // Write error is returned. + ztesting.AssertEqual(t, io.ErrClosedPipe, err) }) t.Run("nRead != nWrite", func(t *testing.T) { r := strings.NewReader("1234567890") w := ziotest.ShortWriter(bytes.NewBuffer(nil), 4) written, err := zio.Copy(w, r) - ztesting.AssertEqual(t, "invalid written bytes", 4, written) - ztesting.AssertEqual(t, "error not matched", io.ErrShortWrite, err) + ztesting.AssertEqual(t, 4, written) + ztesting.AssertEqual(t, io.ErrShortWrite, err) }) } diff --git a/zio/limit_test.go b/zio/limit_test.go index 201ef3b..0fa05cf 100644 --- a/zio/limit_test.go +++ b/zio/limit_test.go @@ -13,62 +13,62 @@ func TestLimitReader(t *testing.T) { t.Parallel() t.Run("nil reader", func(t *testing.T) { r := zio.LimitReader(nil, 10) - ztesting.AssertEqual(t, "non nil reader returned", nil, r) + ztesting.AssertEqual(t, nil, r) }) t.Run("limit=-5", func(t *testing.T) { r := zio.LimitReader(strings.NewReader("1234567890"), -5) buf := make([]byte, 10) n, err := r.Read(buf) - ztesting.AssertEqual(t, "read bytes not match", 0, n) - ztesting.AssertEqual(t, "error not match", zio.ErrReadLimit, err) - ztesting.AssertEqual(t, "read content invalid", make([]byte, 10), buf) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, zio.ErrReadLimit, err) + ztesting.AssertEqual(t, make([]byte, 10), buf) }) t.Run("limit=0", func(t *testing.T) { r := zio.LimitReader(strings.NewReader("1234567890"), 0) buf := make([]byte, 10) n, err := r.Read(buf) - ztesting.AssertEqual(t, "read bytes not match", 0, n) - ztesting.AssertEqual(t, "error not match", zio.ErrReadLimit, err) - ztesting.AssertEqual(t, "read content invalid", make([]byte, 10), buf) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, zio.ErrReadLimit, err) + ztesting.AssertEqual(t, make([]byte, 10), buf) }) t.Run("limit=1", func(t *testing.T) { r := zio.LimitReader(strings.NewReader("1234567890"), 1) buf := make([]byte, 10) n, err := r.Read(buf) - ztesting.AssertEqual(t, "read bytes not match", 1, n) - ztesting.AssertEqual(t, "error not match", zio.ErrReadLimit, err) - ztesting.AssertEqual(t, "read content invalid", []byte{'1', 0, 0, 0, 0, 0, 0, 0, 0, 0}, buf) + ztesting.AssertEqual(t, 1, n) + ztesting.AssertEqual(t, zio.ErrReadLimit, err) + ztesting.AssertEqual(t, []byte{'1', 0, 0, 0, 0, 0, 0, 0, 0, 0}, buf) }) t.Run("limit=5", func(t *testing.T) { r := zio.LimitReader(strings.NewReader("1234567890"), 5) buf := make([]byte, 10) n, err := r.Read(buf) - ztesting.AssertEqual(t, "read bytes not match", 5, n) - ztesting.AssertEqual(t, "error not match", zio.ErrReadLimit, err) - ztesting.AssertEqual(t, "read content invalid", []byte{'1', '2', '3', '4', '5', 0, 0, 0, 0, 0}, buf) + ztesting.AssertEqual(t, 5, n) + ztesting.AssertEqual(t, zio.ErrReadLimit, err) + ztesting.AssertEqual(t, []byte{'1', '2', '3', '4', '5', 0, 0, 0, 0, 0}, buf) }) t.Run("limit=10", func(t *testing.T) { r := zio.LimitReader(strings.NewReader("1234567890"), 10) buf := make([]byte, 10) n, err := r.Read(buf) - ztesting.AssertEqual(t, "read bytes not match", 10, n) - ztesting.AssertEqual(t, "error not match", nil, err) - ztesting.AssertEqual(t, "read content invalid", []byte("1234567890"), buf) + ztesting.AssertEqual(t, 10, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, []byte("1234567890"), buf) }) t.Run("read multiple times", func(t *testing.T) { r := zio.LimitReader(strings.NewReader("1234567890"), 5) n1, err1 := r.Read(make([]byte, 3)) - ztesting.AssertEqual(t, "read bytes not match", 3, n1) - ztesting.AssertEqual(t, "error not match", nil, err1) + ztesting.AssertEqual(t, 3, n1) + ztesting.AssertEqual(t, nil, err1) n2, err2 := r.Read(make([]byte, 3)) - ztesting.AssertEqual(t, "read bytes not match", 2, n2) - ztesting.AssertEqual(t, "error not match", zio.ErrReadLimit, err2) + ztesting.AssertEqual(t, 2, n2) + ztesting.AssertEqual(t, zio.ErrReadLimit, err2) }) } @@ -76,64 +76,64 @@ func TestLimitWriter(t *testing.T) { t.Parallel() t.Run("nil reader", func(t *testing.T) { w := zio.LimitWriter(nil, 10) - ztesting.AssertEqual(t, "non nil writer returned", nil, w) + ztesting.AssertEqual(t, nil, w) }) t.Run("limit=-5", func(t *testing.T) { buf := bytes.NewBuffer(nil) w := zio.LimitWriter(buf, -5) n, err := w.Write([]byte("1234567890")) - ztesting.AssertEqual(t, "written bytes not match", 0, n) - ztesting.AssertEqual(t, "error not match", zio.ErrWriteLimit, err) - ztesting.AssertEqual(t, "written content invalid", "", buf.String()) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, zio.ErrWriteLimit, err) + ztesting.AssertEqual(t, "", buf.String()) }) t.Run("limit=0", func(t *testing.T) { buf := bytes.NewBuffer(nil) w := zio.LimitWriter(buf, 0) n, err := w.Write([]byte("1234567890")) - ztesting.AssertEqual(t, "written bytes not match", 0, n) - ztesting.AssertEqual(t, "error not match", zio.ErrWriteLimit, err) - ztesting.AssertEqual(t, "written content invalid", "", buf.String()) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, zio.ErrWriteLimit, err) + ztesting.AssertEqual(t, "", buf.String()) }) t.Run("limit=1", func(t *testing.T) { buf := bytes.NewBuffer(nil) w := zio.LimitWriter(buf, 1) n, err := w.Write([]byte("1234567890")) - ztesting.AssertEqual(t, "written bytes not match", 1, n) - ztesting.AssertEqual(t, "error not match", zio.ErrWriteLimit, err) - ztesting.AssertEqual(t, "written content invalid", "1", buf.String()) + ztesting.AssertEqual(t, 1, n) + ztesting.AssertEqual(t, zio.ErrWriteLimit, err) + ztesting.AssertEqual(t, "1", buf.String()) }) t.Run("limit=5", func(t *testing.T) { buf := bytes.NewBuffer(nil) w := zio.LimitWriter(buf, 5) n, err := w.Write([]byte("1234567890")) - ztesting.AssertEqual(t, "written bytes not match", 5, n) - ztesting.AssertEqual(t, "error not match", zio.ErrWriteLimit, err) - ztesting.AssertEqual(t, "written content invalid", "12345", buf.String()) + ztesting.AssertEqual(t, 5, n) + ztesting.AssertEqual(t, zio.ErrWriteLimit, err) + ztesting.AssertEqual(t, "12345", buf.String()) }) t.Run("limit=10", func(t *testing.T) { buf := bytes.NewBuffer(nil) w := zio.LimitWriter(buf, 10) n, err := w.Write([]byte("1234567890")) - ztesting.AssertEqual(t, "written bytes not match", 10, n) - ztesting.AssertEqual(t, "error not match", nil, err) - ztesting.AssertEqual(t, "written content invalid", "1234567890", buf.String()) + ztesting.AssertEqual(t, 10, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "1234567890", buf.String()) }) t.Run("write multiple times", func(t *testing.T) { buf := bytes.NewBuffer(nil) w := zio.LimitWriter(buf, 5) n1, err1 := w.Write([]byte("123")) - ztesting.AssertEqual(t, "written bytes not match", 3, n1) - ztesting.AssertEqual(t, "error not match", nil, err1) - ztesting.AssertEqual(t, "written content invalid", "123", buf.String()) + ztesting.AssertEqual(t, 3, n1) + ztesting.AssertEqual(t, nil, err1) + ztesting.AssertEqual(t, "123", buf.String()) n2, err2 := w.Write([]byte("456")) - ztesting.AssertEqual(t, "written bytes not match", 2, n2) - ztesting.AssertEqual(t, "error not match", zio.ErrWriteLimit, err2) - ztesting.AssertEqual(t, "written content invalid", "12345", buf.String()) + ztesting.AssertEqual(t, 2, n2) + ztesting.AssertEqual(t, zio.ErrWriteLimit, err2) + ztesting.AssertEqual(t, "12345", buf.String()) }) } diff --git a/zio/reader_test.go b/zio/reader_test.go index 2266619..83c2349 100644 --- a/zio/reader_test.go +++ b/zio/reader_test.go @@ -18,13 +18,13 @@ func TestTeeReader(t *testing.T) { t.Run("nil reader", func(t *testing.T) { w := bytes.NewBuffer(nil) tr := zio.TeeReader(nil, w) - ztesting.AssertEqual(t, "reader does not match", nil, tr) + ztesting.AssertEqual(t, nil, tr) }) t.Run("nil writer", func(t *testing.T) { r := strings.NewReader("abc") tr := zio.TeeReader(r, nil) - ztesting.AssertEqual(t, "reader does not match", io.Reader(r), tr) + ztesting.AssertEqual(t, io.Reader(r), tr) }) t.Run("no error", func(t *testing.T) { @@ -33,10 +33,10 @@ func TestTeeReader(t *testing.T) { tr := zio.TeeReader(r, w) buf := make([]byte, 10) n, err := tr.Read(buf) - ztesting.AssertEqual(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "wrong read bytes", 3, n) - ztesting.AssertEqual(t, "wrong content written to writer", "abc", w.String()) - ztesting.AssertEqual(t, "wrong content read", "abc", string(buf[:n])) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, 3, n) + ztesting.AssertEqual(t, "abc", w.String()) + ztesting.AssertEqual(t, "abc", string(buf[:n])) }) t.Run("read error", func(t *testing.T) { @@ -45,10 +45,10 @@ func TestTeeReader(t *testing.T) { tr := zio.TeeReader(r, w) buf := make([]byte, 10) n, err := tr.Read(buf) - ztesting.AssertEqual(t, "error mismatch", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "wrong read bytes", 1, n) - ztesting.AssertEqual(t, "wrong content written to writer", "a", w.String()) - ztesting.AssertEqual(t, "wrong content read", "a", string(buf[:n])) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, 1, n) + ztesting.AssertEqual(t, "a", w.String()) + ztesting.AssertEqual(t, "a", string(buf[:n])) }) t.Run("write error", func(t *testing.T) { @@ -57,10 +57,10 @@ func TestTeeReader(t *testing.T) { tr := zio.TeeReader(r, ziotest.ErrWriter(w, 1)) buf := make([]byte, 10) n, err := tr.Read(buf) - ztesting.AssertEqual(t, "error mismatch", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "wrong read bytes", 1, n) - ztesting.AssertEqual(t, "wrong content written to writer", "a", w.String()) - ztesting.AssertEqual(t, "wrong content read", "a", string(buf[:n])) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, 1, n) + ztesting.AssertEqual(t, "a", w.String()) + ztesting.AssertEqual(t, "a", string(buf[:n])) }) t.Run("read write error", func(t *testing.T) { @@ -69,10 +69,10 @@ func TestTeeReader(t *testing.T) { tr := zio.TeeReader(r, ziotest.ErrWriter(w, 1)) buf := make([]byte, 10) n, err := tr.Read(buf) - ztesting.AssertEqual(t, "error mismatch", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "wrong read bytes", 1, n) - ztesting.AssertEqual(t, "wrong content written to writer", "a", w.String()) - ztesting.AssertEqual(t, "wrong content read", "a", string(buf[:n])) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, 1, n) + ztesting.AssertEqual(t, "a", w.String()) + ztesting.AssertEqual(t, "a", string(buf[:n])) }) } @@ -81,12 +81,12 @@ func TestTeeReadCloser(t *testing.T) { t.Run("nil reader", func(t *testing.T) { w := zio.NopWriteCloser(bytes.NewBuffer(nil)) tr := zio.TeeReadCloser(nil, w) - ztesting.AssertEqual(t, "reader does not match", nil, tr) + ztesting.AssertEqual(t, nil, tr) }) t.Run("nil writer", func(t *testing.T) { r := zio.NopReadCloser(strings.NewReader("abc")) tr := zio.TeeReadCloser(r, nil) - ztesting.AssertEqual(t, "reader does not match", io.ReadCloser(r), tr) + ztesting.AssertEqual(t, io.ReadCloser(r), tr) }) t.Run("no error", func(t *testing.T) { r := zio.NopReadCloser(strings.NewReader("abc")) @@ -94,10 +94,10 @@ func TestTeeReadCloser(t *testing.T) { tr := zio.TeeReadCloser(r, zio.NopWriteCloser(w)) buf := make([]byte, 10) n, err := tr.Read(buf) - ztesting.AssertEqual(t, "error is not nil", nil, err) - ztesting.AssertEqual(t, "wrong read bytes", 3, n) - ztesting.AssertEqual(t, "wrong content written to writer", "abc", w.String()) - ztesting.AssertEqual(t, "wrong content read", "abc", string(buf[:n])) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, 3, n) + ztesting.AssertEqual(t, "abc", w.String()) + ztesting.AssertEqual(t, "abc", string(buf[:n])) }) t.Run("read error", func(t *testing.T) { r := zio.NopReadCloser(ziotest.ErrReader(strings.NewReader("abc"), 1)) @@ -105,10 +105,10 @@ func TestTeeReadCloser(t *testing.T) { tr := zio.TeeReadCloser(r, zio.NopWriteCloser(w)) buf := make([]byte, 10) n, err := tr.Read(buf) - ztesting.AssertEqual(t, "error mismatch", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "wrong read bytes", 1, n) - ztesting.AssertEqual(t, "wrong content written to writer", "a", w.String()) - ztesting.AssertEqual(t, "wrong content read", "a", string(buf[:n])) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, 1, n) + ztesting.AssertEqual(t, "a", w.String()) + ztesting.AssertEqual(t, "a", string(buf[:n])) }) t.Run("write error", func(t *testing.T) { r := zio.NopReadCloser(strings.NewReader("abc")) @@ -116,10 +116,10 @@ func TestTeeReadCloser(t *testing.T) { tr := zio.TeeReadCloser(r, zio.NopWriteCloser(ziotest.ErrWriter(w, 1))) buf := make([]byte, 10) n, err := tr.Read(buf) - ztesting.AssertEqual(t, "error mismatch", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "wrong read bytes", 1, n) - ztesting.AssertEqual(t, "wrong content written to writer", "a", w.String()) - ztesting.AssertEqual(t, "wrong content read", "a", string(buf[:n])) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, 1, n) + ztesting.AssertEqual(t, "a", w.String()) + ztesting.AssertEqual(t, "a", string(buf[:n])) }) t.Run("read write error", func(t *testing.T) { r := zio.NopReadCloser(ziotest.ErrReader(strings.NewReader("abc"), 1)) @@ -127,38 +127,38 @@ func TestTeeReadCloser(t *testing.T) { tr := zio.TeeReadCloser(r, zio.NopWriteCloser(ziotest.ErrWriter(w, 1))) buf := make([]byte, 10) n, err := tr.Read(buf) - ztesting.AssertEqual(t, "error mismatch", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "wrong read bytes", 1, n) - ztesting.AssertEqual(t, "wrong content written to writer", "a", w.String()) - ztesting.AssertEqual(t, "wrong content read", "a", string(buf[:n])) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, 1, n) + ztesting.AssertEqual(t, "a", w.String()) + ztesting.AssertEqual(t, "a", string(buf[:n])) }) t.Run("no close error", func(t *testing.T) { r := zio.NopReadCloser(strings.NewReader("abc")) w := bytes.NewBuffer(nil) tr := zio.TeeReadCloser(r, zio.NopWriteCloser(w)) err := tr.Close() - ztesting.AssertEqualErr(t, "error mismatch", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("reader close error", func(t *testing.T) { r := &errReadCloser{Reader: strings.NewReader("abc"), err: os.ErrClosed} w := bytes.NewBuffer(nil) tr := zio.TeeReadCloser(r, zio.NopWriteCloser(w)) err := tr.Close() - ztesting.AssertEqualErr(t, "error mismatch", os.ErrClosed, err) + ztesting.AssertEqualErr(t, os.ErrClosed, err) }) t.Run("writer close error", func(t *testing.T) { r := zio.NopReadCloser(ziotest.ErrReader(strings.NewReader("abc"), 1)) w := bytes.NewBuffer(nil) tr := zio.TeeReadCloser(r, &errWriteCloser{Writer: w, err: os.ErrClosed}) err := tr.Close() - ztesting.AssertEqualErr(t, "error mismatch", os.ErrClosed, err) + ztesting.AssertEqualErr(t, os.ErrClosed, err) }) t.Run("reader writer close error", func(t *testing.T) { r := &errReadCloser{Reader: strings.NewReader("abc"), err: os.ErrPermission} w := bytes.NewBuffer(nil) tr := zio.TeeReadCloser(r, &errWriteCloser{Writer: w, err: os.ErrClosed}) err := tr.Close() - ztesting.AssertEqualErr(t, "error mismatch", errors.Join(os.ErrPermission, os.ErrClosed), err) + ztesting.AssertEqualErr(t, errors.Join(os.ErrPermission, os.ErrClosed), err) }) } diff --git a/zlog/logicalfile_test.go b/zlog/logicalfile_test.go index 96691e6..b1a70fe 100644 --- a/zlog/logicalfile_test.go +++ b/zlog/logicalfile_test.go @@ -16,7 +16,7 @@ func TestNewLogicalFile(t *testing.T) { Pattern: "invalid.%x.%y.%z.log", }, }) - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("success initialize", func(t *testing.T) { dir := t.TempDir() @@ -28,10 +28,10 @@ func TestNewLogicalFile(t *testing.T) { }, }) defer f.Close() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) info, err := os.Stat(dir + "/application.log") - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "files is not regular file", true, info.Mode().IsRegular()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, true, info.Mode().IsRegular()) }) } @@ -48,13 +48,13 @@ func TestLogicalFile_Write(t *testing.T) { RotateBytes: 0, FileName: "test.log", }) - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) defer f.Close() f.Write([]byte("line1\n")) f.Write([]byte("line2\n")) b, err := os.ReadFile(dir + "/test.log") - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "content not match", "line1\nline2\n", string(b)) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "line1\nline2\n", string(b)) }) t.Run("rotate", func(t *testing.T) { dir := t.TempDir() @@ -67,7 +67,7 @@ func TestLogicalFile_Write(t *testing.T) { RotateBytes: 5, FileName: "test.log", }) - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) defer f.Close() f.Write([]byte("12345")) // No rotate. f.Write([]byte("67890")) // Rotate before write. @@ -75,14 +75,14 @@ func TestLogicalFile_Write(t *testing.T) { f.Write([]byte("def")) // Rotate before write. f.Close() b, err := os.ReadFile(dir + "/test.1.log") - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "content not match", "12345", string(b)) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "12345", string(b)) b, err = os.ReadFile(dir + "/test.2.log") - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "content not match", "67890", string(b)) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "67890", string(b)) b, err = os.ReadFile(dir + "/test.3.log") - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "content not match", "abc", string(b)) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "abc", string(b)) }) } @@ -98,10 +98,10 @@ func TestLogicalFile_Close(t *testing.T) { }, FileName: "test.log", }) - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) f.curFile.Close() // Force close to make later call error. err = f.Close() - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("rename error", func(t *testing.T) { dir := t.TempDir() @@ -114,9 +114,9 @@ func TestLogicalFile_Close(t *testing.T) { FileName: "test.log", }) f.manager.srcDir += "/not-exist/" // Make srcDir invalid. - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) err = f.Close() - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) } @@ -133,19 +133,19 @@ func TestLogicalFile_Swap(t *testing.T) { FileName: "test.log", }) defer f.Close() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) f.Swap() // Swap 1st. info, err := os.Stat(dir + "/test.1.log") - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "files is not regular file", true, info.Mode().IsRegular()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, true, info.Mode().IsRegular()) f.Swap() // Swap 2nd. info, err = os.Stat(dir + "/test.2.log") - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "files is not regular file", true, info.Mode().IsRegular()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, true, info.Mode().IsRegular()) f.Close() // Swap 3rd. info, err = os.Stat(dir + "/test.3.log") - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "files is not regular file", true, info.Mode().IsRegular()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, true, info.Mode().IsRegular()) }) t.Run("close error", func(t *testing.T) { dir := t.TempDir() @@ -159,9 +159,9 @@ func TestLogicalFile_Swap(t *testing.T) { }) f.curFile.Close() // Force close to make Close() error. defer f.Close() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) err = f.Swap() - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("rename error", func(t *testing.T) { dir := t.TempDir() @@ -175,9 +175,9 @@ func TestLogicalFile_Swap(t *testing.T) { }) f.manager.srcDir += "/not-exist/" // Make srcDir invalid. defer f.Close() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) err = f.Swap() - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("open error", func(t *testing.T) { dir := t.TempDir() @@ -191,9 +191,9 @@ func TestLogicalFile_Swap(t *testing.T) { }) f.filePath += "/not-exist/invalid.log" // Make filePath invalid. defer f.Close() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) err = f.Swap() - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) } @@ -209,10 +209,10 @@ func TestLogicalFile_Fallback(t *testing.T) { curSize: 100, // Set to non zero. } f.fallbackStderr(nil, "fallback test") - ztesting.AssertEqual(t, "curFile was unexpectedly replaced", nil, f.curFile) - ztesting.AssertEqual(t, "isStderr should be false", false, f.isStderr) - ztesting.AssertEqual(t, "curSize should not modified", 100, f.curSize) - ztesting.AssertEqual(t, "onFallback should be false", false, onFallbackCalled) + ztesting.AssertEqual(t, nil, f.curFile) + ztesting.AssertEqual(t, false, f.isStderr) + ztesting.AssertEqual(t, 100, f.curSize) + ztesting.AssertEqual(t, false, onFallbackCalled) }) t.Run("non-nil error", func(t *testing.T) { var onFallbackCalled bool @@ -224,9 +224,9 @@ func TestLogicalFile_Fallback(t *testing.T) { curSize: 100, // Set to non zero. } f.fallbackStderr(errors.New("non-nil"), "fallback test") - ztesting.AssertEqual(t, "curFile is not stderr", os.Stderr, f.curFile) - ztesting.AssertEqual(t, "isStderr should be true", true, f.isStderr) - ztesting.AssertEqual(t, "curSize should be zero", 0, f.curSize) - ztesting.AssertEqual(t, "onFallback is not called", true, onFallbackCalled) + ztesting.AssertEqual(t, os.Stderr, f.curFile) + ztesting.AssertEqual(t, true, f.isStderr) + ztesting.AssertEqual(t, 0, f.curSize) + ztesting.AssertEqual(t, true, onFallbackCalled) }) } diff --git a/zlog/manager_test.go b/zlog/manager_test.go index 12100e8..2c453b5 100644 --- a/zlog/manager_test.go +++ b/zlog/manager_test.go @@ -21,26 +21,26 @@ func TestNewFileManager(t *testing.T) { _, err := NewFileManager(&FileManagerConfig{ Pattern: "foo/bar.txt", }) - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("pattern contains '\\'", func(t *testing.T) { _, err := NewFileManager(&FileManagerConfig{ Pattern: "foo\\bar.txt", }) - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("invalid pattern", func(t *testing.T) { _, err := NewFileManager(&FileManagerConfig{ Pattern: "bar.%x.%y.%z.txt", }) - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("%i added", func(t *testing.T) { dir := t.TempDir() c := &FileManagerConfig{SrcDir: dir, DstDir: dir, Pattern: "test.txt"} // ".%i" should be added. _, err := NewFileManager(c) - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "pattern not match", "test.%i.txt", c.Pattern) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "test.%i.txt", c.Pattern) }) t.Run("pattern contains specifier", func(t *testing.T) { dir := t.TempDir() @@ -48,31 +48,31 @@ func TestNewFileManager(t *testing.T) { for _, s := range specs { c := &FileManagerConfig{SrcDir: dir, DstDir: dir, Pattern: s + ".%i"} _, err := NewFileManager(c) - ztesting.AssertEqual(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "pattern should have length", true, len(c.Pattern) > 0) - ztesting.AssertEqual(t, "invalid pattern replace", true, c.Pattern[:len(c.Pattern)-3] != s) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, true, len(c.Pattern) > 0) + ztesting.AssertEqual(t, true, c.Pattern[:len(c.Pattern)-3] != s) } }) t.Run("srcDir create failed", func(t *testing.T) { dir := t.TempDir() c := &FileManagerConfig{SrcDir: dir + "/ng-\x00", DstDir: dir + "/ok"} _, err := NewFileManager(c) - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("dstDir create failed", func(t *testing.T) { dir := t.TempDir() c := &FileManagerConfig{SrcDir: dir + "/ok", DstDir: dir + "/ng-\x00"} _, err := NewFileManager(c) - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) } func TestFileManager_NewFile(t *testing.T) { t.Parallel() m := &FileManager{srcDir: "testdata/", pattern: "test.%i.txt"} - ztesting.AssertEqual(t, "file path not match", filepath.Join("testdata", "test.1.txt"), m.NewFile()) - ztesting.AssertEqual(t, "file path not match", filepath.Join("testdata", "test.2.txt"), m.NewFile()) - ztesting.AssertEqual(t, "file path not match", filepath.Join("testdata", "test.3.txt"), m.NewFile()) + ztesting.AssertEqual(t, filepath.Join("testdata", "test.1.txt"), m.NewFile()) + ztesting.AssertEqual(t, filepath.Join("testdata", "test.2.txt"), m.NewFile()) + ztesting.AssertEqual(t, filepath.Join("testdata", "test.3.txt"), m.NewFile()) } func TestFileManager_Manager(t *testing.T) { @@ -80,7 +80,7 @@ func TestFileManager_Manager(t *testing.T) { t.Run("failed to list srcDir", func(t *testing.T) { m := &FileManager{srcDir: "not-found"} err := m.Manage() - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("failed to archive", func(t *testing.T) { dir := t.TempDir() @@ -88,31 +88,31 @@ func TestFileManager_Manager(t *testing.T) { os.WriteFile(path, []byte("testdata"), os.ModePerm) m := &FileManager{srcDir: dir, dstDir: "not-found", pattern: "test.txt"} err := m.Manage() - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("failed to list dstDir", func(t *testing.T) { dir := t.TempDir() m := &FileManager{srcDir: dir, dstDir: "not-found", pattern: "test.txt"} err := m.Manage() - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("limit max history", func(t *testing.T) { dir := t.TempDir() copyDir("./testdata/manage/max-history", dir) m := &FileManager{srcDir: dir, dstDir: dir, pattern: "test.%i.txt", maxHistory: 3} err := m.Manage() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := []string{"test.5.txt", "test.6.txt", "test.9.txt"} - ztesting.AssertEqual(t, "files not match", want, listDirFiles(dir)) + ztesting.AssertEqual(t, want, listDirFiles(dir)) }) t.Run("limit max history gzip", func(t *testing.T) { dir := t.TempDir() copyDir("./testdata/manage/max-history-gz", dir) m := &FileManager{srcDir: dir, dstDir: dir, pattern: "test.%i.txt", maxHistory: 3, gzipLv: gzip.BestSpeed} err := m.Manage() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := []string{"test.5.txt.gz", "test.6.txt.gz", "test.9.txt.gz"} - ztesting.AssertEqual(t, "files not match", want, listDirFiles(dir)) + ztesting.AssertEqual(t, want, listDirFiles(dir)) }) t.Run("limit max age", func(t *testing.T) { dir := t.TempDir() @@ -125,27 +125,27 @@ func TestFileManager_Manager(t *testing.T) { os.WriteFile(dir+"/test."+time4+".txt", []byte("testdata"), os.ModePerm) m := &FileManager{srcDir: dir, dstDir: dir, pattern: "test.%u.txt", maxAge: 250 * time.Second} err := m.Manage() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := []string{"test." + time2 + ".txt", "test." + time1 + ".txt"} - ztesting.AssertEqual(t, "files not match", want, listDirFiles(dir)) + ztesting.AssertEqual(t, want, listDirFiles(dir)) }) t.Run("limit total size", func(t *testing.T) { dir := t.TempDir() copyDir("./testdata/manage/total-size", dir) m := &FileManager{srcDir: dir, dstDir: dir, pattern: "test.%i.txt", maxTotal: 25} err := m.Manage() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := []string{"test.4.txt", "test.5.txt"} - ztesting.AssertEqual(t, "files not match", want, listDirFiles(dir)) + ztesting.AssertEqual(t, want, listDirFiles(dir)) }) t.Run("limit total size", func(t *testing.T) { dir := t.TempDir() copyDir("./testdata/manage/total-size-gz", dir) m := &FileManager{srcDir: dir, dstDir: dir, pattern: "test.%i.txt", maxTotal: 25, gzipLv: gzip.BestSpeed} err := m.Manage() - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) want := []string{"test.4.txt.gz", "test.5.txt.gz"} - ztesting.AssertEqual(t, "files not match", want, listDirFiles(dir)) + ztesting.AssertEqual(t, want, listDirFiles(dir)) }) } @@ -185,9 +185,9 @@ func TestFileManager_archive(t *testing.T) { os.WriteFile(path, []byte("testdata"), os.ModePerm) m := &FileManager{srcDir: dir, dstDir: dir, gzipLv: gzip.NoCompression} err := m.archive([]*fileInfo{{name: "test.txt", path: path}}) - ztesting.AssertEqual(t, "error not match", nil, err) + ztesting.AssertEqual(t, nil, err) info, _ := os.Stat(path) - ztesting.AssertEqual(t, "file type not match", true, info.Mode().IsRegular()) + ztesting.AssertEqual(t, true, info.Mode().IsRegular()) }) t.Run("with compression", func(t *testing.T) { dir := t.TempDir() @@ -195,16 +195,16 @@ func TestFileManager_archive(t *testing.T) { os.WriteFile(path, []byte("testdata"), os.ModePerm) m := &FileManager{srcDir: dir, dstDir: dir, gzipLv: gzip.BestSpeed} err := m.archive([]*fileInfo{{name: "test.txt", path: path}}) - ztesting.AssertEqual(t, "error not match", nil, err) + ztesting.AssertEqual(t, nil, err) info, _ := os.Stat(path + ".gz") - ztesting.AssertEqual(t, "file type not match", true, info.Mode().IsRegular()) + ztesting.AssertEqual(t, true, info.Mode().IsRegular()) }) t.Run("compression failed", func(t *testing.T) { dir := t.TempDir() path := dir + "/test.txt" // Not exist. m := &FileManager{srcDir: dir, dstDir: dir, gzipLv: gzip.BestSpeed} err := m.archive([]*fileInfo{{name: "test.txt", path: path}}) - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) }) t.Run("different dir", func(t *testing.T) { @@ -215,9 +215,9 @@ func TestFileManager_archive(t *testing.T) { os.WriteFile(path, []byte("testdata"), os.ModePerm) m := &FileManager{srcDir: srcDir, dstDir: dstDir, gzipLv: gzip.NoCompression} err := m.archive([]*fileInfo{{name: "test.txt", path: path}}) - ztesting.AssertEqual(t, "error not match", nil, err) + ztesting.AssertEqual(t, nil, err) info, _ := os.Stat(dstDir + "/test.txt") - ztesting.AssertEqual(t, "file type not match", true, info.Mode().IsRegular()) + ztesting.AssertEqual(t, true, info.Mode().IsRegular()) }) t.Run("with compression", func(t *testing.T) { srcDir := t.TempDir() @@ -226,9 +226,9 @@ func TestFileManager_archive(t *testing.T) { os.WriteFile(path, []byte("testdata"), os.ModePerm) m := &FileManager{srcDir: srcDir, dstDir: dstDir, gzipLv: gzip.BestSpeed} err := m.archive([]*fileInfo{{name: "test.txt", path: path}}) - ztesting.AssertEqual(t, "error not match", nil, err) + ztesting.AssertEqual(t, nil, err) info, _ := os.Stat(dstDir + "/test.txt.gz") - ztesting.AssertEqual(t, "file type not match", true, info.Mode().IsRegular()) + ztesting.AssertEqual(t, true, info.Mode().IsRegular()) }) }) } @@ -259,15 +259,15 @@ func TestGzipCompressFile(t *testing.T) { if tc.err != nil { // Currently we only check if the error is nil or not because the PathError // contains platform dependent errors. - ztesting.AssertEqual(t, "error not match", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) return } - ztesting.AssertEqual(t, "error not match", nil, err) + ztesting.AssertEqual(t, nil, err) b, err := os.ReadFile(dstFile) r, _ := gzip.NewReader(bytes.NewReader(b)) bb, _ := io.ReadAll(r) - ztesting.AssertEqual(t, "error not match", nil, err) - ztesting.AssertEqual(t, "content not match", "testdata", string(bb)) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "testdata", string(bb)) }) } } @@ -315,15 +315,15 @@ func TestListFiles(t *testing.T) { if tc.err != nil { // Currently we only check if the error is nil or not because the PathError // contains platform dependent errors. - ztesting.AssertEqual(t, "error not match", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) return } - ztesting.AssertEqual(t, "error not match", nil, err) - ztesting.AssertEqual(t, "file length not match", len(tc.files), len(files)) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, len(tc.files), len(files)) for i := range tc.files { - ztesting.AssertEqual(t, "file name not match", tc.files[i].name, files[i].name) - ztesting.AssertEqual(t, "index not match", tc.files[i].index, files[i].index) - ztesting.AssertEqual(t, "created time not match", tc.files[i].created, files[i].created) + ztesting.AssertEqual(t, tc.files[i].name, files[i].name) + ztesting.AssertEqual(t, tc.files[i].index, files[i].index) + ztesting.AssertEqual(t, tc.files[i].created, files[i].created) } }) } @@ -361,8 +361,8 @@ func TestFormatFileName(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { str, ok := formatFileName(tc.format, tc.t, tc.index) - ztesting.AssertEqual(t, "string not match", tc.str, str) - ztesting.AssertEqual(t, "ok not match", tc.ok, ok) + ztesting.AssertEqual(t, tc.str, str) + ztesting.AssertEqual(t, tc.ok, ok) }) } } @@ -409,9 +409,9 @@ func TestScanFileName(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { tm, index, ok := scanFileName(tc.format, tc.str) - ztesting.AssertEqual(t, "time not match", tc.t, tm) - ztesting.AssertEqual(t, "index not match", tc.index, index) - ztesting.AssertEqual(t, "char not match", tc.ok, ok) + ztesting.AssertEqual(t, tc.t, tm) + ztesting.AssertEqual(t, tc.index, index) + ztesting.AssertEqual(t, tc.ok, ok) }) } } @@ -432,9 +432,9 @@ func TestScanFormat(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { prefix, rest, char := scanFormat(tc.format) - ztesting.AssertEqual(t, "prefix not match", tc.prefix, prefix) - ztesting.AssertEqual(t, "rest string not match", tc.rest, rest) - ztesting.AssertEqual(t, "char not match", tc.char, char) + ztesting.AssertEqual(t, tc.prefix, prefix) + ztesting.AssertEqual(t, tc.rest, rest) + ztesting.AssertEqual(t, tc.char, char) }) } } @@ -464,9 +464,9 @@ func TestScanNumber(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { num, rest, ok := scanNumber(tc.str, tc.digit) - ztesting.AssertEqual(t, "parsed num not match", tc.num, num) - ztesting.AssertEqual(t, "rest string not match", tc.rest, rest) - ztesting.AssertEqual(t, "ok not match", tc.ok, ok) + ztesting.AssertEqual(t, tc.num, num) + ztesting.AssertEqual(t, tc.rest, rest) + ztesting.AssertEqual(t, tc.ok, ok) }) } } diff --git a/zlog/zslog/attr_test.go b/zlog/zslog/attr_test.go index d92181e..034f4e4 100644 --- a/zlog/zslog/attr_test.go +++ b/zlog/zslog/attr_test.go @@ -11,53 +11,53 @@ import ( func TestCallerAttr(t *testing.T) { t.Parallel() attr := CallerAttr(0) - ztesting.AssertEqual(t, "invalid attribute key.", "caller", attr.Key) + ztesting.AssertEqual(t, "caller", attr.Key) values := attr.Value.Group() - ztesting.AssertEqual(t, "invalid number of values.", 4, len(values)) + ztesting.AssertEqual(t, 4, len(values)) if len(values) < 4 { return } - ztesting.AssertEqual(t, "invalid key name.", "pkg", values[0].Key) - ztesting.AssertEqual(t, "invalid key name.", "file", values[1].Key) - ztesting.AssertEqual(t, "invalid key name.", "func", values[2].Key) - ztesting.AssertEqual(t, "invalid key name.", "line", values[3].Key) + ztesting.AssertEqual(t, "pkg", values[0].Key) + ztesting.AssertEqual(t, "file", values[1].Key) + ztesting.AssertEqual(t, "func", values[2].Key) + ztesting.AssertEqual(t, "line", values[3].Key) } func TestDateTimeAttr(t *testing.T) { t.Parallel() attr := DateTimeAttr() - ztesting.AssertEqual(t, "invalid attribute key.", "datetime", attr.Key) + ztesting.AssertEqual(t, "datetime", attr.Key) values := attr.Value.Group() - ztesting.AssertEqual(t, "invalid number of values.", 2, len(values)) + ztesting.AssertEqual(t, 2, len(values)) if len(values) < 2 { return } - ztesting.AssertEqual(t, "invalid key name.", "date", values[0].Key) - ztesting.AssertEqual(t, "invalid key name.", "time", values[1].Key) + ztesting.AssertEqual(t, "date", values[0].Key) + ztesting.AssertEqual(t, "time", values[1].Key) } func TestFramesAttr(t *testing.T) { t.Parallel() attr := FramesAttr(0) - ztesting.AssertEqual(t, "invalid attribute key.", "frames", attr.Key) + ztesting.AssertEqual(t, "frames", attr.Key) values, ok := attr.Value.Any().([]string) - ztesting.AssertEqual(t, "no frames found.", true, ok) - ztesting.AssertEqual(t, "no frames found.", true, len(values) > 0) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, true, len(values) > 0) } func TestStackTraceAttrs(t *testing.T) { t.Parallel() attr := StackTraceAttrs(0) - ztesting.AssertEqual(t, "invalid attribute key.", "stack", attr.Key) - ztesting.AssertEqual(t, "stack trace is empty.", true, len(attr.Value.String()) > 0) + ztesting.AssertEqual(t, "stack", attr.Key) + ztesting.AssertEqual(t, true, len(attr.Value.String()) > 0) } func TestErrorAttr(t *testing.T) { t.Parallel() attr := ErrorAttr(io.EOF) - ztesting.AssertEqual(t, "invalid attribute key.", "error", attr.Key) - ztesting.AssertEqual(t, "unexpected error attribute.", "map[message:EOF]", fmt.Sprint(attr.Value.Any())) + ztesting.AssertEqual(t, "error", attr.Key) + ztesting.AssertEqual(t, "map[message:EOF]", fmt.Sprint(attr.Value.Any())) } diff --git a/zlog/zslog/buildlog_test.go b/zlog/zslog/buildlog_test.go index d2b7cda..c383b79 100644 --- a/zlog/zslog/buildlog_test.go +++ b/zlog/zslog/buildlog_test.go @@ -18,9 +18,9 @@ func TestBuildLog(t *testing.T) { BuildLog(context.Background(), "test", "foo", "bar") out := w.String() if !buildlogEnabled { - ztesting.AssertEqual(t, "output not match", "", out) + ztesting.AssertEqual(t, "", out) } else { - ztesting.AssertEqual(t, "message not output", true, strings.Contains(out, `"msg":"test"`)) - ztesting.AssertEqual(t, "args not output", true, strings.Contains(out, `"foo":"bar"`)) + ztesting.AssertEqual(t, true, strings.Contains(out, `"msg":"test"`)) + ztesting.AssertEqual(t, true, strings.Contains(out, `"foo":"bar"`)) } } diff --git a/zlog/zslog/context_test.go b/zlog/zslog/context_test.go index 2518e6c..8aab439 100644 --- a/zlog/zslog/context_test.go +++ b/zlog/zslog/context_test.go @@ -15,23 +15,23 @@ func TestContextWithAttrs(t *testing.T) { t.Run("nil context", func(t *testing.T) { ctx := zslog.ContextWithAttrs(nil, "foo", "bar") attrs := zslog.AttrsFromContext(ctx) - ztesting.AssertEqual(t, "invalid number of attributes.", 2, len(attrs)) - ztesting.AssertEqual(t, "invalid content of attributes.", []any{"foo", "bar"}, attrs) + ztesting.AssertEqual(t, 2, len(attrs)) + ztesting.AssertEqual(t, []any{"foo", "bar"}, attrs) }) t.Run("empty context", func(t *testing.T) { ctx := context.Background() ctx = zslog.ContextWithAttrs(ctx, "foo", "bar") attrs := zslog.AttrsFromContext(ctx) - ztesting.AssertEqual(t, "invalid number of attributes.", 2, len(attrs)) - ztesting.AssertEqual(t, "invalid content of attributes.", []any{"foo", "bar"}, attrs) + ztesting.AssertEqual(t, 2, len(attrs)) + ztesting.AssertEqual(t, []any{"foo", "bar"}, attrs) }) t.Run("non empty context", func(t *testing.T) { ctx := context.Background() ctx = zslog.ContextWithAttrs(ctx, "foo") ctx = zslog.ContextWithAttrs(ctx, "bar") attrs := zslog.AttrsFromContext(ctx) - ztesting.AssertEqual(t, "invalid number of attributes.", 2, len(attrs)) - ztesting.AssertEqual(t, "invalid content of attributes.", []any{"foo", "bar"}, attrs) + ztesting.AssertEqual(t, 2, len(attrs)) + ztesting.AssertEqual(t, []any{"foo", "bar"}, attrs) }) } @@ -39,13 +39,13 @@ func TestAttrsFromContext(t *testing.T) { t.Parallel() t.Run("empty context", func(t *testing.T) { attrs := zslog.AttrsFromContext(context.Background()) - ztesting.AssertEqual(t, "invalid number of attributes.", 0, len(attrs)) + ztesting.AssertEqual(t, 0, len(attrs)) }) t.Run("non empty context", func(t *testing.T) { ctx := zslog.ContextWithAttrs(context.Background(), "foo", "bar") attrs := zslog.AttrsFromContext(ctx) - ztesting.AssertEqual(t, "invalid number of attributes.", 2, len(attrs)) - ztesting.AssertEqual(t, "invalid content of attributes.", []any{"foo", "bar"}, attrs) + ztesting.AssertEqual(t, 2, len(attrs)) + ztesting.AssertEqual(t, []any{"foo", "bar"}, attrs) }) } @@ -54,20 +54,20 @@ func TestContextWithLevel(t *testing.T) { t.Run("nil context", func(t *testing.T) { ctx := zslog.ContextWithLevel(nil, slog.LevelError) lv := zslog.LevelFromContext(ctx) - ztesting.AssertEqual(t, "level mismatch.", slog.LevelError, lv) + ztesting.AssertEqual(t, slog.LevelError, lv) }) t.Run("empty context", func(t *testing.T) { ctx := context.Background() ctx = zslog.ContextWithLevel(ctx, slog.LevelError) lv := zslog.LevelFromContext(ctx) - ztesting.AssertEqual(t, "level mismatch.", slog.LevelError, lv) + ztesting.AssertEqual(t, slog.LevelError, lv) }) t.Run("non empty context", func(t *testing.T) { ctx := context.Background() ctx = zslog.ContextWithLevel(ctx, slog.LevelDebug) ctx = zslog.ContextWithLevel(ctx, slog.LevelError) lv := zslog.LevelFromContext(ctx) - ztesting.AssertEqual(t, "level mismatch.", slog.LevelError, lv) + ztesting.AssertEqual(t, slog.LevelError, lv) }) } @@ -75,12 +75,12 @@ func TestLevelFromContext(t *testing.T) { t.Parallel() t.Run("empty context", func(t *testing.T) { lv := zslog.LevelFromContext(context.Background()) - ztesting.AssertEqual(t, "level mismatch.", slog.Level(math.MinInt), lv) + ztesting.AssertEqual(t, slog.Level(math.MinInt), lv) }) t.Run("non empty context", func(t *testing.T) { ctx := zslog.ContextWithLevel(context.Background(), slog.LevelError) lv := zslog.LevelFromContext(ctx) - ztesting.AssertEqual(t, "level mismatch.", slog.LevelError, lv) + ztesting.AssertEqual(t, slog.LevelError, lv) }) } @@ -93,13 +93,13 @@ func TestContextWithHandler(t *testing.T) { t.Run("nil context", func(t *testing.T) { ctx := zslog.ContextWithHandler(nil, testHandler) got := zslog.HandlerFromContext(ctx) - ztesting.AssertEqual(t, "handler level mismatch.", slog.Handler(testHandler), got) + ztesting.AssertEqual(t, slog.Handler(testHandler), got) }) t.Run("empty context", func(t *testing.T) { ctx := context.Background() ctx = zslog.ContextWithHandler(ctx, testHandler) got := zslog.HandlerFromContext(ctx) - ztesting.AssertEqual(t, "handler mismatch.", slog.Handler(testHandler), got) + ztesting.AssertEqual(t, slog.Handler(testHandler), got) }) t.Run("non empty context", func(t *testing.T) { testHandler2 := struct { @@ -110,7 +110,7 @@ func TestContextWithHandler(t *testing.T) { ctx = zslog.ContextWithHandler(ctx, testHandler) ctx = zslog.ContextWithHandler(ctx, testHandler2) got := zslog.HandlerFromContext(ctx) - ztesting.AssertEqual(t, "handler mismatch.", slog.Handler(testHandler2), got) + ztesting.AssertEqual(t, slog.Handler(testHandler2), got) }) } @@ -122,11 +122,11 @@ func TestHandlerFromContext(t *testing.T) { }{nil, "test"} t.Run("empty context", func(t *testing.T) { got := zslog.HandlerFromContext(context.Background()) - ztesting.AssertEqual(t, "handler mismatch.", nil, got) + ztesting.AssertEqual(t, nil, got) }) t.Run("non empty context", func(t *testing.T) { ctx := zslog.ContextWithHandler(context.Background(), testHandler) got := zslog.HandlerFromContext(ctx) - ztesting.AssertEqual(t, "handler mismatch.", slog.Handler(testHandler), got) + ztesting.AssertEqual(t, slog.Handler(testHandler), got) }) } diff --git a/zlog/zslog/logger_test.go b/zlog/zslog/logger_test.go index 2232cae..de85af5 100644 --- a/zlog/zslog/logger_test.go +++ b/zlog/zslog/logger_test.go @@ -22,8 +22,8 @@ func TestDefaultLogger(t *testing.T) { dlg := zslog.Default() dlg.InfoContext(context.Background(), "test", "foo", "bar") out := w.String() - ztesting.AssertEqual(t, "message not found", true, strings.Contains(out, `"msg":"test"`)) - ztesting.AssertEqual(t, "message not found", true, strings.Contains(out, `"foo":"bar"`)) + ztesting.AssertEqual(t, true, strings.Contains(out, `"msg":"test"`)) + ztesting.AssertEqual(t, true, strings.Contains(out, `"foo":"bar"`)) } func TestNew(t *testing.T) { @@ -31,20 +31,20 @@ func TestNew(t *testing.T) { t.Run("json handler", func(t *testing.T) { var w bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&w, &slog.HandlerOptions{Level: slog.LevelDebug})) - ztesting.AssertEqual(t, "log level is not enabled.", true, lg.DebugEnabled(context.Background())) + ztesting.AssertEqual(t, true, lg.DebugEnabled(context.Background())) lg.InfoContext(context.Background(), "test", "foo", "bar") out := w.String() - ztesting.AssertEqual(t, "message not found", true, strings.Contains(out, `"msg":"test"`)) - ztesting.AssertEqual(t, "message not found", true, strings.Contains(out, `"foo":"bar"`)) + ztesting.AssertEqual(t, true, strings.Contains(out, `"msg":"test"`)) + ztesting.AssertEqual(t, true, strings.Contains(out, `"foo":"bar"`)) }) t.Run("text handler", func(t *testing.T) { var w bytes.Buffer lg := zslog.New(slog.NewTextHandler(&w, &slog.HandlerOptions{Level: slog.LevelDebug})) - ztesting.AssertEqual(t, "log level is not enabled.", true, lg.DebugEnabled(context.Background())) + ztesting.AssertEqual(t, true, lg.DebugEnabled(context.Background())) lg.InfoContext(context.Background(), "test", "foo", "bar") out := w.String() - ztesting.AssertEqual(t, "message not found", true, strings.Contains(out, `msg=test`)) - ztesting.AssertEqual(t, "message not found", true, strings.Contains(out, `foo=bar`)) + ztesting.AssertEqual(t, true, strings.Contains(out, `msg=test`)) + ztesting.AssertEqual(t, true, strings.Contains(out, `foo=bar`)) }) } @@ -107,12 +107,12 @@ func TestLogger_Enabled(t *testing.T) { ctx = zslog.ContextWithLevel(ctx, tc.ctxLv) } lg := zslog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: tc.setLv})) - ztesting.AssertEqual(t, "debug enabled not match.", slog.LevelDebug >= threshold, lg.DebugEnabled(ctx)) - ztesting.AssertEqual(t, "info enabled not match.", slog.LevelInfo >= threshold, lg.InfoEnabled(ctx)) - ztesting.AssertEqual(t, "warn enabled not match.", slog.LevelWarn >= threshold, lg.WarnEnabled(ctx)) - ztesting.AssertEqual(t, "error enabled not match.", slog.LevelError >= threshold, lg.ErrorEnabled(ctx)) + ztesting.AssertEqual(t, slog.LevelDebug >= threshold, lg.DebugEnabled(ctx)) + ztesting.AssertEqual(t, slog.LevelInfo >= threshold, lg.InfoEnabled(ctx)) + ztesting.AssertEqual(t, slog.LevelWarn >= threshold, lg.WarnEnabled(ctx)) + ztesting.AssertEqual(t, slog.LevelError >= threshold, lg.ErrorEnabled(ctx)) for i := -10; i < 10; i++ { - ztesting.AssertEqual(t, "enabled not match.", i >= int(threshold), lg.Enabled(ctx, slog.Level(i))) + ztesting.AssertEqual(t, i >= int(threshold), lg.Enabled(ctx, slog.Level(i))) } }) } @@ -133,9 +133,9 @@ func TestLogger_Debug(t *testing.T) { lg.DebugContext(ctx, "test message", "arg1", "arg2") result := buf.String() if threshold > slog.LevelDebug { - ztesting.AssertEqual(t, "log line is written.", "", buf.String()) + ztesting.AssertEqual(t, "", buf.String()) } else { - ztesting.AssertEqual(t, "log line is not written.", true, strings.Contains(result, "test message")) + ztesting.AssertEqual(t, true, strings.Contains(result, "test message")) } }) } @@ -144,14 +144,14 @@ func TestLogger_Debug(t *testing.T) { lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug})) lg.AddCaller = zslog.RangeDebug lg.DebugContext(context.Background(), "test message") - ztesting.AssertEqual(t, "log line does not contain caller.", true, strings.Contains(buf.String(), `"caller"`)) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `"caller"`)) }) t.Run("add frames", func(t *testing.T) { var buf bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug})) lg.AddFrames = zslog.RangeDebug lg.DebugContext(context.Background(), "test message") - ztesting.AssertEqual(t, "log line does not contain frames.", true, strings.Contains(buf.String(), `"frames"`)) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `"frames"`)) }) } @@ -170,9 +170,9 @@ func TestLogger_Info(t *testing.T) { lg.InfoContext(ctx, "test message", "arg1", "arg2") result := buf.String() if threshold > slog.LevelInfo { - ztesting.AssertEqual(t, "log line is written.", "", buf.String()) + ztesting.AssertEqual(t, "", buf.String()) } else { - ztesting.AssertEqual(t, "log line is not written.", true, strings.Contains(result, "test message")) + ztesting.AssertEqual(t, true, strings.Contains(result, "test message")) } }) } @@ -181,14 +181,14 @@ func TestLogger_Info(t *testing.T) { lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelInfo})) lg.AddCaller = zslog.RangeInfo lg.InfoContext(context.Background(), "test message") - ztesting.AssertEqual(t, "log line does not contain caller.", true, strings.Contains(buf.String(), `"caller"`)) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `"caller"`)) }) t.Run("add frames", func(t *testing.T) { var buf bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelInfo})) lg.AddFrames = zslog.RangeInfo lg.InfoContext(context.Background(), "test message") - ztesting.AssertEqual(t, "log line does not contain frames.", true, strings.Contains(buf.String(), `"frames"`)) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `"frames"`)) }) } @@ -207,9 +207,9 @@ func TestLogger_Warn(t *testing.T) { lg.WarnContext(ctx, "test message", "arg1", "arg2") result := buf.String() if threshold > slog.LevelWarn { - ztesting.AssertEqual(t, "log line is written.", "", buf.String()) + ztesting.AssertEqual(t, "", buf.String()) } else { - ztesting.AssertEqual(t, "log line is not written.", true, strings.Contains(result, "test message")) + ztesting.AssertEqual(t, true, strings.Contains(result, "test message")) } }) } @@ -218,14 +218,14 @@ func TestLogger_Warn(t *testing.T) { lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelWarn})) lg.AddCaller = zslog.RangeWarn lg.WarnContext(context.Background(), "test message") - ztesting.AssertEqual(t, "log line does not contain caller.", true, strings.Contains(buf.String(), `"caller"`)) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `"caller"`)) }) t.Run("add frames", func(t *testing.T) { var buf bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelWarn})) lg.AddFrames = zslog.RangeWarn lg.WarnContext(context.Background(), "test message") - ztesting.AssertEqual(t, "log line does not contain frames.", true, strings.Contains(buf.String(), `"frames"`)) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `"frames"`)) }) } @@ -244,9 +244,9 @@ func TestLogger_Error(t *testing.T) { lg.ErrorContext(ctx, "test message", "arg1", "arg2") result := buf.String() if threshold > slog.LevelError { - ztesting.AssertEqual(t, "log line is written.", "", buf.String()) + ztesting.AssertEqual(t, "", buf.String()) } else { - ztesting.AssertEqual(t, "log line is not written.", true, strings.Contains(result, "test message")) + ztesting.AssertEqual(t, true, strings.Contains(result, "test message")) } }) } @@ -255,14 +255,14 @@ func TestLogger_Error(t *testing.T) { lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelError})) lg.AddCaller = zslog.RangeError lg.ErrorContext(context.Background(), "test message") - ztesting.AssertEqual(t, "log line does not contain caller.", true, strings.Contains(buf.String(), `"caller"`)) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `"caller"`)) }) t.Run("add frames", func(t *testing.T) { var buf bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelError})) lg.AddFrames = zslog.RangeError lg.ErrorContext(context.Background(), "test message") - ztesting.AssertEqual(t, "log line does not contain frames.", true, strings.Contains(buf.String(), `"frames"`)) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `"frames"`)) }) } @@ -272,32 +272,32 @@ func TestLogger_nilContext(t *testing.T) { t.Run("enabled", func(t *testing.T) { var buf bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelInfo})) - ztesting.AssertEqual(t, "log level is unexpectedly enabled.", false, lg.Enabled(ctx, slog.LevelDebug)) - ztesting.AssertEqual(t, "log level is unexpectedly disabled.", true, lg.Enabled(ctx, slog.LevelInfo)) - ztesting.AssertEqual(t, "log level is unexpectedly disabled.", true, lg.Enabled(ctx, slog.LevelWarn)) + ztesting.AssertEqual(t, false, lg.Enabled(ctx, slog.LevelDebug)) + ztesting.AssertEqual(t, true, lg.Enabled(ctx, slog.LevelInfo)) + ztesting.AssertEqual(t, true, lg.Enabled(ctx, slog.LevelWarn)) }) t.Run("debug", func(t *testing.T) { var buf bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug})) lg.DebugContext(ctx, "test message") - ztesting.AssertEqual(t, "log line should be written", false, buf.String() == "") + ztesting.AssertEqual(t, false, buf.String() == "") }) t.Run("info", func(t *testing.T) { var buf bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug})) lg.InfoContext(ctx, "test message") - ztesting.AssertEqual(t, "log line should be written", false, buf.String() == "") + ztesting.AssertEqual(t, false, buf.String() == "") }) t.Run("warn", func(t *testing.T) { var buf bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug})) lg.WarnContext(ctx, "test message") - ztesting.AssertEqual(t, "log line should be written", false, buf.String() == "") + ztesting.AssertEqual(t, false, buf.String() == "") }) t.Run("error", func(t *testing.T) { var buf bytes.Buffer lg := zslog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug})) lg.ErrorContext(ctx, "test message") - ztesting.AssertEqual(t, "log line should be written", false, buf.String() == "") + ztesting.AssertEqual(t, false, buf.String() == "") }) } diff --git a/zmaps/maps_test.go b/zmaps/maps_test.go index a8f309a..8aae67a 100644 --- a/zmaps/maps_test.go +++ b/zmaps/maps_test.go @@ -23,7 +23,7 @@ func TestKeys(t *testing.T) { t.Run(name, func(t *testing.T) { v := zmaps.Keys(tc.input) slices.Sort(v) - ztesting.AssertEqual(t, "wrong element returned.", tc.want, v) + ztesting.AssertEqual(t, tc.want, v) }) } } @@ -43,7 +43,7 @@ func TestValues(t *testing.T) { t.Run(name, func(t *testing.T) { v := zmaps.Values(tc.input) slices.Sort(v) - ztesting.AssertEqual(t, "wrong element returned.", tc.want, v) + ztesting.AssertEqual(t, tc.want, v) }) } } diff --git a/zmath/set_internal_test.go b/zmath/set_internal_test.go index 1cf9b75..68fe6ba 100644 --- a/zmath/set_internal_test.go +++ b/zmath/set_internal_test.go @@ -25,11 +25,11 @@ func TestUniqueIterator(t *testing.T) { iter := uniqueIterator(tc.set) for _, v := range tc.elems { next, found := iter() - ztesting.AssertEqual(t, "value not match", v, next) - ztesting.AssertEqual(t, "value not found", true, found) + ztesting.AssertEqual(t, v, next) + ztesting.AssertEqual(t, true, found) } _, found := iter() - ztesting.AssertEqual(t, "value found", false, found) + ztesting.AssertEqual(t, false, found) }) } } diff --git a/zmath/set_test.go b/zmath/set_test.go index 7d66b4c..9af17f9 100644 --- a/zmath/set_test.go +++ b/zmath/set_test.go @@ -12,27 +12,27 @@ func TestNewSet(t *testing.T) { t.Run("empty slice", func(t *testing.T) { s := []string{} ss := zmath.NewSet(s) - ztesting.AssertEqual(t, "set not matched", []string{}, ss) + ztesting.AssertEqual(t, []string{}, ss) }) t.Run("1 elem slice", func(t *testing.T) { s := []string{"a"} ss := zmath.NewSet(s) - ztesting.AssertEqual(t, "set not matched", []string{"a"}, ss) + ztesting.AssertEqual(t, []string{"a"}, ss) }) t.Run("2 elems slice", func(t *testing.T) { s := []string{"a", "b"} ss := zmath.NewSet(s) - ztesting.AssertEqual(t, "set not matched", []string{"a", "b"}, ss) + ztesting.AssertEqual(t, []string{"a", "b"}, ss) }) t.Run("string slice", func(t *testing.T) { s := []string{"c", "a", "b"} ss := zmath.NewSet(s) - ztesting.AssertEqual(t, "set not matched", []string{"a", "b", "c"}, ss) + ztesting.AssertEqual(t, []string{"a", "b", "c"}, ss) }) t.Run("int slice", func(t *testing.T) { s := []int{3, -1, 2, 0, 1} ss := zmath.NewSet(s) - ztesting.AssertEqual(t, "set not matched", []int{-1, 0, 1, 2, 3}, ss) + ztesting.AssertEqual(t, []int{-1, 0, 1, 2, 3}, ss) }) } @@ -55,7 +55,7 @@ func TestSet_Has(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := tc.set.Has(tc.elem) - ztesting.AssertEqual(t, "has not matched", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -79,7 +79,7 @@ func TestSet_Add(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { tc.set.Add(tc.elem) - ztesting.AssertEqual(t, "has not matched", tc.want, tc.set) + ztesting.AssertEqual(t, tc.want, tc.set) }) } } @@ -108,7 +108,7 @@ func TestSet_AddElems(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { tc.set.AddElems(tc.elems...) - ztesting.AssertEqual(t, "has not matched", tc.want, tc.set) + ztesting.AssertEqual(t, tc.want, tc.set) }) } } @@ -132,7 +132,7 @@ func TestSet_Remove(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { tc.set.Remove(tc.elem) - ztesting.AssertEqual(t, "has not matched", tc.want, tc.set) + ztesting.AssertEqual(t, tc.want, tc.set) }) } } @@ -161,7 +161,7 @@ func TestSet_RemoveElems(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { tc.set.RemoveElems(tc.elems...) - ztesting.AssertEqual(t, "has not matched", tc.want, tc.set) + ztesting.AssertEqual(t, tc.want, tc.set) }) } } @@ -189,7 +189,7 @@ func TestEqual(t *testing.T) { a := zmath.NewSet(tc.setA) b := zmath.NewSet(tc.setB) equal := zmath.Equal(a, b) - ztesting.AssertEqual(t, "equal result not match", tc.equal, equal) + ztesting.AssertEqual(t, tc.equal, equal) }) } } @@ -237,8 +237,8 @@ func Test_Subset_SuperSet(t *testing.T) { b := zmath.NewSet(tc.setB) subSet := zmath.Subset(a, b) superSet := zmath.Superset(b, a) - ztesting.AssertEqual(t, "subset result not match", tc.subset, subSet) - ztesting.AssertEqual(t, "superset result not match", tc.subset, superSet) + ztesting.AssertEqual(t, tc.subset, subSet) + ztesting.AssertEqual(t, tc.subset, superSet) }) } } @@ -286,8 +286,8 @@ func Test_ProperSubset_ProperSuperset(t *testing.T) { b := zmath.NewSet(tc.setB) subset := zmath.ProperSubset(a, b) superset := zmath.ProperSuperset(b, a) - ztesting.AssertEqual(t, "proper subset result not match", tc.subset, subset) - ztesting.AssertEqual(t, "proper superset result not match", tc.subset, superset) + ztesting.AssertEqual(t, tc.subset, subset) + ztesting.AssertEqual(t, tc.subset, superset) }) } } @@ -324,7 +324,7 @@ func TestUnion(t *testing.T) { a := zmath.NewSet(tc.setA) b := zmath.NewSet(tc.setB) union := zmath.Union(a, b) - ztesting.AssertEqual(t, "unexpected union", tc.union, union) + ztesting.AssertEqual(t, tc.union, union) }) } } @@ -363,7 +363,7 @@ func TestIntersection(t *testing.T) { a := zmath.NewSet(tc.setA) b := zmath.NewSet(tc.setB) intersection := zmath.Intersection(a, b) - ztesting.AssertEqual(t, "unexpected intersection", tc.intersection, intersection) + ztesting.AssertEqual(t, tc.intersection, intersection) }) } } @@ -402,7 +402,7 @@ func TestDifference(t *testing.T) { a := zmath.NewSet(tc.setA) b := zmath.NewSet(tc.setB) difference := zmath.Difference(a, b) - ztesting.AssertEqual(t, "unexpected difference", tc.difference, difference) + ztesting.AssertEqual(t, tc.difference, difference) }) } } diff --git a/znet/allow_test.go b/znet/allow_test.go index fc27018..fa5bbfa 100644 --- a/znet/allow_test.go +++ b/znet/allow_test.go @@ -13,11 +13,11 @@ func TestAllowList(t *testing.T) { list := znet.NewWhiteList() t.Run("allow fails", func(t *testing.T) { err := list.Allow("127.0.0.1") // No CIDR - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("disallow fails", func(t *testing.T) { err := list.Disallow("127.0.0.1") // No CIDR - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) } @@ -58,12 +58,12 @@ func TestWhiteList(t *testing.T) { for _, ip := range tc.allowed { allowed := l.Allowed(ip) t.Log(ip, allowed) - ztesting.AssertEqual(t, "ip should be allowed", true, allowed) + ztesting.AssertEqual(t, true, allowed) } for _, ip := range tc.disallowed { allowed := l.Allowed(ip) t.Log(ip, allowed) - ztesting.AssertEqual(t, "ip should not be allowed", false, allowed) + ztesting.AssertEqual(t, false, allowed) } }) } @@ -106,12 +106,12 @@ func TestBlackList(t *testing.T) { for _, ip := range tc.allowed { allowed := l.Allowed(ip) t.Log(ip, allowed) - ztesting.AssertEqual(t, "ip should be allowed", true, allowed) + ztesting.AssertEqual(t, true, allowed) } for _, ip := range tc.disallowed { allowed := l.Allowed(ip) t.Log(ip, allowed) - ztesting.AssertEqual(t, "ip should not be allowed", false, allowed) + ztesting.AssertEqual(t, false, allowed) } }) } @@ -122,11 +122,11 @@ func TestAllowAddr(t *testing.T) { t.Run("blacklist zero addr", func(t *testing.T) { l := znet.NewBlackList() allowed := l.AllowedAddr(netip.Addr{}) - ztesting.AssertEqual(t, "ip should not be allowed", false, allowed) + ztesting.AssertEqual(t, false, allowed) }) t.Run("whitelist zero addr", func(t *testing.T) { l := znet.NewWhiteList() allowed := l.AllowedAddr(netip.Addr{}) - ztesting.AssertEqual(t, "ip should not be allowed", false, allowed) + ztesting.AssertEqual(t, false, allowed) }) } diff --git a/znet/internal/server_test.go b/znet/internal/server_test.go index 3d659e7..1cf1834 100644 --- a/znet/internal/server_test.go +++ b/znet/internal/server_test.go @@ -19,7 +19,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("serve error", func(t *testing.T) { t.Run("already closed", func(t *testing.T) { @@ -28,7 +28,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", http.ErrServerClosed, err) + ztesting.AssertEqualErr(t, http.ErrServerClosed, err) }) t.Run("non-nil error", func(t *testing.T) { testErr := errors.New("serve error") @@ -37,7 +37,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", testErr, err) + ztesting.AssertEqualErr(t, testErr, err) }) }) t.Run("shutdown error", func(t *testing.T) { @@ -52,8 +52,8 @@ func TestServerRunner(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() err := r.Run(ctx) - ztesting.AssertEqualErr(t, "error not match", context.DeadlineExceeded, err) - ztesting.AssertEqual(t, "close is not called", true, closeCalled) + ztesting.AssertEqualErr(t, context.DeadlineExceeded, err) + ztesting.AssertEqual(t, true, closeCalled) }) t.Run("non-nil error", func(t *testing.T) { testErr := errors.New("shutdown error") @@ -66,8 +66,8 @@ func TestServerRunner(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() err := r.Run(ctx) - ztesting.AssertEqualErr(t, "error not match", testErr, err) - ztesting.AssertEqual(t, "close is called", false, closeCalled) + ztesting.AssertEqualErr(t, testErr, err) + ztesting.AssertEqual(t, false, closeCalled) }) }) } diff --git a/znet/internal/store_test.go b/znet/internal/store_test.go index d16fdb4..ddf4035 100644 --- a/znet/internal/store_test.go +++ b/znet/internal/store_test.go @@ -25,21 +25,21 @@ func TestCloserStore(t *testing.T) { s := internal.CloserStore[*testCloser]{} foo := &testCloser{name: "foo"} s.Store(foo) - ztesting.AssertEqual(t, "length not match", 1, s.Length()) + ztesting.AssertEqual(t, 1, s.Length()) s.Delete(foo) - ztesting.AssertEqual(t, "length not match", 0, s.Length()) + ztesting.AssertEqual(t, 0, s.Length()) }) t.Run("store different value", func(t *testing.T) { s := internal.CloserStore[*testCloser]{} foo := &testCloser{name: "foo"} bar := &testCloser{name: "bar"} s.Store(foo) - ztesting.AssertEqual(t, "length not match", 1, s.Length()) + ztesting.AssertEqual(t, 1, s.Length()) s.Store(bar) - ztesting.AssertEqual(t, "length not match", 2, s.Length()) + ztesting.AssertEqual(t, 2, s.Length()) s.Delete(foo) s.Delete(bar) - ztesting.AssertEqual(t, "length not match", 0, s.Length()) + ztesting.AssertEqual(t, 0, s.Length()) }) t.Run("close", func(t *testing.T) { s := internal.CloserStore[*testCloser]{} @@ -47,12 +47,12 @@ func TestCloserStore(t *testing.T) { bar := &testCloser{name: "bar"} s.Store(foo) s.Store(bar) - ztesting.AssertEqual(t, "length not match", 2, s.Length()) + ztesting.AssertEqual(t, 2, s.Length()) err := s.CloseAll() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "length not match", 0, s.Length()) - ztesting.AssertEqual(t, "foo is not closed", 1, foo.closed) - ztesting.AssertEqual(t, "bar is not closed", 1, bar.closed) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 0, s.Length()) + ztesting.AssertEqual(t, 1, foo.closed) + ztesting.AssertEqual(t, 1, bar.closed) }) t.Run("close error", func(t *testing.T) { s := internal.CloserStore[*testCloser]{} @@ -62,8 +62,8 @@ func TestCloserStore(t *testing.T) { s.Store(bar) err := s.CloseAll() errs := err.(interface{ Unwrap() []error }).Unwrap() - ztesting.AssertEqual(t, "length of errors not match", 2, len(errs)) - ztesting.AssertEqual(t, "foo is not closed", 1, foo.closed) - ztesting.AssertEqual(t, "bar is not closed", 1, bar.closed) + ztesting.AssertEqual(t, 2, len(errs)) + ztesting.AssertEqual(t, 1, foo.closed) + ztesting.AssertEqual(t, 1, bar.closed) }) } diff --git a/znet/listener_test.go b/znet/listener_test.go index bb4b047..8c38b59 100644 --- a/znet/listener_test.go +++ b/znet/listener_test.go @@ -44,11 +44,11 @@ func TestNewWhiteListListener(t *testing.T) { t.Parallel() t.Run("error", func(t *testing.T) { _, err := znet.NewWhiteListListener(nil, "127.0.0.1") - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("no error", func(t *testing.T) { _, err := znet.NewWhiteListListener(nil, "127.0.0.1/32") - ztesting.AssertEqual(t, "error should be nil", true, err == nil) + ztesting.AssertEqual(t, true, err == nil) }) } @@ -56,11 +56,11 @@ func TestNewBlackListListener(t *testing.T) { t.Parallel() t.Run("error", func(t *testing.T) { _, err := znet.NewBlackListListener(nil, "127.0.0.1") - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("no error", func(t *testing.T) { _, err := znet.NewBlackListListener(nil, "127.0.0.1/32") - ztesting.AssertEqual(t, "error should be nil", true, err == nil) + ztesting.AssertEqual(t, true, err == nil) }) } @@ -95,8 +95,8 @@ func TestWhiteListListener(t *testing.T) { t.Run(name, func(t *testing.T) { ln, _ := znet.NewWhiteListListener(tc.ln, tc.allow...) conn, err := ln.Accept() - ztesting.AssertEqualErr(t, "error not match", tc.err, err) - ztesting.AssertEqual(t, "closed not match", tc.closed, conn.(*testConn).closed) + ztesting.AssertEqualErr(t, tc.err, err) + ztesting.AssertEqual(t, tc.closed, conn.(*testConn).closed) }) } } @@ -132,8 +132,8 @@ func TestBlackListListener(t *testing.T) { t.Run(name, func(t *testing.T) { ln, _ := znet.NewBlackListListener(tc.ln, tc.disallow...) conn, err := ln.Accept() - ztesting.AssertEqualErr(t, "error not match", tc.err, err) - ztesting.AssertEqual(t, "closed not match", tc.closed, conn.(*testConn).closed) + ztesting.AssertEqualErr(t, tc.err, err) + ztesting.AssertEqual(t, tc.closed, conn.(*testConn).closed) }) } } @@ -144,23 +144,23 @@ func TestLimitListener(t *testing.T) { inner := &testListener{remote: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 80}} ln := znet.NewLimitListener(inner, 0) conn, err := ln.Accept() - ztesting.AssertEqualErr(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "closed count not match", "1", conn.Close().Error()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "1", conn.Close().Error()) }) t.Run("limit 1", func(t *testing.T) { inner := &testListener{remote: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 80}} ln := znet.NewLimitListener(inner, 1) conn, err := ln.Accept() - ztesting.AssertEqualErr(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "closed count not match", "1", conn.Close().Error()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "1", conn.Close().Error()) }) t.Run("limit 2", func(t *testing.T) { inner := &testListener{remote: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 80}} ln := znet.NewLimitListener(inner, 2) _, _ = ln.Accept() // Discard first conn, err := ln.Accept() - ztesting.AssertEqualErr(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "closed count not match", "1", conn.Close().Error()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "1", conn.Close().Error()) }) t.Run("wait", func(t *testing.T) { inner := &testListener{remote: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 80}} @@ -168,15 +168,15 @@ func TestLimitListener(t *testing.T) { conn, _ := ln.Accept() time.AfterFunc(100*time.Millisecond, func() { conn.Close() }) conn, err := ln.Accept() - ztesting.AssertEqualErr(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "closed count not match", "1", conn.Close().Error()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "1", conn.Close().Error()) }) t.Run("inner error", func(t *testing.T) { inner := &testListener{err: io.EOF, remote: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 80}} ln := znet.NewLimitListener(inner, 1) conn, err := ln.Accept() - ztesting.AssertEqualErr(t, "error not match", io.EOF, err) - ztesting.AssertEqual(t, "closed count not match", "1", conn.Close().Error()) + ztesting.AssertEqualErr(t, io.EOF, err) + ztesting.AssertEqual(t, "1", conn.Close().Error()) }) } @@ -184,11 +184,11 @@ func TestNewTLSListener(t *testing.T) { t.Parallel() t.Run("error", func(t *testing.T) { _, err := znet.NewTLSListener(nil, &tls.Config{}, "127.0.0.1") - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("no error", func(t *testing.T) { _, err := znet.NewTLSListener(nil, &tls.Config{}, "127.0.0.1/32") - ztesting.AssertEqual(t, "error should be nil", true, err == nil) + ztesting.AssertEqual(t, true, err == nil) }) } @@ -224,9 +224,9 @@ func TestTLSListener(t *testing.T) { t.Run(name, func(t *testing.T) { ln, _ := znet.NewTLSListener(tc.ln, &tls.Config{}, tc.nonTLS...) conn, err := ln.Accept() - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) _, isTLS := conn.(*tls.Conn) - ztesting.AssertEqual(t, "connection is not TLS", tc.shouldTLS, isTLS) + ztesting.AssertEqual(t, tc.shouldTLS, isTLS) }) } } @@ -261,16 +261,16 @@ func TestACMEListener(t *testing.T) { ln := znet.NewACMEListener(tc.ln, tc.domains...) if tc.modify { ln.Modifier = func(c *tls.Config) { - ztesting.AssertEqual(t, "TLS config is nil", true, c != nil) + ztesting.AssertEqual(t, true, c != nil) } } conn, err := ln.Accept() - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if err != nil { return } _, isTLS := conn.(*tls.Conn) - ztesting.AssertEqual(t, "connection is not TLS", true, isTLS) + ztesting.AssertEqual(t, true, isTLS) }) } } diff --git a/znet/net_test.go b/znet/net_test.go index ff472a1..a3a06b7 100644 --- a/znet/net_test.go +++ b/znet/net_test.go @@ -33,8 +33,8 @@ func TestParseNetAddr(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { n, a := znet.ParseNetAddr(tc.addr) - ztesting.AssertEqual(t, "network not match", tc.network, n) - ztesting.AssertEqual(t, "address not match", tc.address, a) + ztesting.AssertEqual(t, tc.network, n) + ztesting.AssertEqual(t, tc.address, a) }) } } diff --git a/znet/resolver_test.go b/znet/resolver_test.go index 78e3c6b..9b38f7a 100644 --- a/znet/resolver_test.go +++ b/znet/resolver_test.go @@ -17,9 +17,9 @@ func TestIPResolver(t *testing.T) { }, } err := r.Resolve(context.Background()) - ztesting.AssertEqualErr(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "ip addresses not match", []string{}, r.IPs()) - ztesting.AssertEqual(t, "address not match", "", r.Next()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []string{}, r.IPs()) + ztesting.AssertEqual(t, "", r.Next()) }) t.Run("resolve 1 address", func(t *testing.T) { r := &IPResolver{ @@ -28,10 +28,10 @@ func TestIPResolver(t *testing.T) { }, } err := r.Resolve(context.Background()) - ztesting.AssertEqualErr(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "ip addresses not match", []string{"127.0.0.1"}, r.IPs()) - ztesting.AssertEqual(t, "1st address not match", "127.0.0.1", r.Next()) - ztesting.AssertEqual(t, "2nd address not match", "127.0.0.1", r.Next()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, []string{"127.0.0.1"}, r.IPs()) + ztesting.AssertEqual(t, "127.0.0.1", r.Next()) + ztesting.AssertEqual(t, "127.0.0.1", r.Next()) }) t.Run("resolve 3 addresses", func(t *testing.T) { var n, h string @@ -44,13 +44,13 @@ func TestIPResolver(t *testing.T) { }, } err := r.Resolve(context.Background()) - ztesting.AssertEqualErr(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "network not match", "ip", n) - ztesting.AssertEqual(t, "host not match", "test.com", h) - ztesting.AssertEqual(t, "ip addresses not match", []string{"127.0.0.1", "127.0.0.2", "127.0.0.3"}, r.IPs()) - ztesting.AssertEqual(t, "1st address not match", "127.0.0.2", r.Next()) - ztesting.AssertEqual(t, "2nd address not match", "127.0.0.3", r.Next()) - ztesting.AssertEqual(t, "3rd address not match", "127.0.0.1", r.Next()) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "ip", n) + ztesting.AssertEqual(t, "test.com", h) + ztesting.AssertEqual(t, []string{"127.0.0.1", "127.0.0.2", "127.0.0.3"}, r.IPs()) + ztesting.AssertEqual(t, "127.0.0.2", r.Next()) + ztesting.AssertEqual(t, "127.0.0.3", r.Next()) + ztesting.AssertEqual(t, "127.0.0.1", r.Next()) }) t.Run("network and host", func(t *testing.T) { var n, h string @@ -64,9 +64,9 @@ func TestIPResolver(t *testing.T) { }, } err := r.Resolve(context.Background()) - ztesting.AssertEqualErr(t, "error should be nil", nil, err) - ztesting.AssertEqual(t, "network not match", "ip4", n) - ztesting.AssertEqual(t, "host not match", "test.com", h) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "ip4", n) + ztesting.AssertEqual(t, "test.com", h) }) t.Run("resolve error", func(t *testing.T) { r := &IPResolver{ @@ -75,13 +75,13 @@ func TestIPResolver(t *testing.T) { }, } err := r.Resolve(context.Background()) - ztesting.AssertEqualErr(t, "error not match", &net.AddrError{Err: "test", Addr: ""}, err) + ztesting.AssertEqualErr(t, &net.AddrError{Err: "test", Addr: ""}, err) }) t.Run("default resolver", func(t *testing.T) { r := &IPResolver{ LookupIP: nil, } err := r.Resolve(context.Background()) - ztesting.AssertEqualErr(t, "error not match", &net.DNSError{Err: "no such host"}, err) + ztesting.AssertEqualErr(t, &net.DNSError{Err: "no such host"}, err) }) } diff --git a/znet/zhttp/cookie_test.go b/znet/zhttp/cookie_test.go index 250352f..ef8ae5f 100644 --- a/znet/zhttp/cookie_test.go +++ b/znet/zhttp/cookie_test.go @@ -14,37 +14,37 @@ func TestGetMultiCookie(t *testing.T) { t.Parallel() t.Run("empty prefix for nil", func(t *testing.T) { cks, value := zhttp.GetMultiCookie("", nil) - ztesting.AssertEqual(t, "cookies should be empty", 0, len(cks)) - ztesting.AssertEqual(t, "value should be empty", "", value) + ztesting.AssertEqual(t, 0, len(cks)) + ztesting.AssertEqual(t, "", value) }) t.Run("with prefix for nil", func(t *testing.T) { cks, value := zhttp.GetMultiCookie("prefix", nil) - ztesting.AssertEqual(t, "cookies should be empty", 0, len(cks)) - ztesting.AssertEqual(t, "value should be empty", "", value) + ztesting.AssertEqual(t, 0, len(cks)) + ztesting.AssertEqual(t, "", value) }) t.Run("no index", func(t *testing.T) { cookies := []*http.Cookie{ {Name: "prefix", Value: "value"}, } cks, value := zhttp.GetMultiCookie("prefix", cookies) - ztesting.AssertEqual(t, "cookies should be empty", 0, len(cks)) - ztesting.AssertEqual(t, "value should be empty", "", value) + ztesting.AssertEqual(t, 0, len(cks)) + ztesting.AssertEqual(t, "", value) }) t.Run("parse index fails", func(t *testing.T) { cookies := []*http.Cookie{ {Name: "prefixNN", Value: "value"}, } cks, value := zhttp.GetMultiCookie("prefix", cookies) - ztesting.AssertEqual(t, "cookies should be empty", 0, len(cks)) - ztesting.AssertEqual(t, "value should be empty", "", value) + ztesting.AssertEqual(t, 0, len(cks)) + ztesting.AssertEqual(t, "", value) }) t.Run("index from 0 to 0", func(t *testing.T) { cookies := []*http.Cookie{ {Name: "prefix0", Value: "value0"}, } cks, value := zhttp.GetMultiCookie("prefix", cookies) - ztesting.AssertEqual(t, "cookies should be obtained", 1, len(cks)) - ztesting.AssertEqual(t, "value should be obtained", "value0", value) + ztesting.AssertEqual(t, 1, len(cks)) + ztesting.AssertEqual(t, "value0", value) }) t.Run("index from 0 to 1", func(t *testing.T) { cookies := []*http.Cookie{ @@ -52,16 +52,16 @@ func TestGetMultiCookie(t *testing.T) { {Name: "prefix1", Value: "value1"}, } cks, value := zhttp.GetMultiCookie("prefix", cookies) - ztesting.AssertEqual(t, "cookies should be obtained", 2, len(cks)) - ztesting.AssertEqual(t, "value should be obtained", "value0value1", value) + ztesting.AssertEqual(t, 2, len(cks)) + ztesting.AssertEqual(t, "value0value1", value) }) t.Run("index starts 1", func(t *testing.T) { cookies := []*http.Cookie{ {Name: "prefix1", Value: "value1"}, } cks, value := zhttp.GetMultiCookie("prefix", cookies) - ztesting.AssertEqual(t, "cookies should be obtained", 1, len(cks)) - ztesting.AssertEqual(t, "value should be empty", "", value) + ztesting.AssertEqual(t, 1, len(cks)) + ztesting.AssertEqual(t, "", value) }) t.Run("ignore irrelevant cookie", func(t *testing.T) { cookies := []*http.Cookie{ @@ -72,8 +72,8 @@ func TestGetMultiCookie(t *testing.T) { {Name: "prefix1", Value: "value1"}, } cks, value := zhttp.GetMultiCookie("prefix", cookies) - ztesting.AssertEqual(t, "cookies should be obtained", 2, len(cks)) - ztesting.AssertEqual(t, "value should be obtained", "value0value1", value) + ztesting.AssertEqual(t, 2, len(cks)) + ztesting.AssertEqual(t, "value0value1", value) }) } @@ -82,38 +82,38 @@ func TestSetMultiCookie(t *testing.T) { t.Run("nil cookie", func(t *testing.T) { rec := httptest.NewRecorder() cookie := zhttp.SetMultiCookie(rec, nil) - ztesting.AssertEqual(t, "cookie should not be set", 0, len(cookie)) + ztesting.AssertEqual(t, 0, len(cookie)) }) t.Run("empty value", func(t *testing.T) { rec := httptest.NewRecorder() cookie := zhttp.SetMultiCookie(rec, &http.Cookie{Name: "test", Value: ""}) - ztesting.AssertEqual(t, "1 cookie should be set", 1, len(cookie)) - ztesting.AssertEqual(t, "0-th cookie not match", http.Cookie{Name: "test0", Value: ""}, *cookie[0]) + ztesting.AssertEqual(t, 1, len(cookie)) + ztesting.AssertEqual(t, http.Cookie{Name: "test0", Value: ""}, *cookie[0]) }) t.Run("non-empty value", func(t *testing.T) { rec := httptest.NewRecorder() cookie := zhttp.SetMultiCookie(rec, &http.Cookie{Name: "test", Value: "value"}) - ztesting.AssertEqual(t, "1 cookie should be set", 1, len(cookie)) - ztesting.AssertEqual(t, "cookie not match", http.Cookie{Name: "test0", Value: "value"}, *cookie[0]) + ztesting.AssertEqual(t, 1, len(cookie)) + ztesting.AssertEqual(t, http.Cookie{Name: "test0", Value: "value"}, *cookie[0]) }) t.Run("copy attributes", func(t *testing.T) { rec := httptest.NewRecorder() cookie := zhttp.SetMultiCookie(rec, &http.Cookie{Name: "test", Value: "value", Domain: "example.com"}) - ztesting.AssertEqual(t, "1 cookie should be set", 1, len(cookie)) - ztesting.AssertEqual(t, "cookie not match", http.Cookie{Name: "test0", Value: "value", Domain: "example.com"}, *cookie[0]) + ztesting.AssertEqual(t, 1, len(cookie)) + ztesting.AssertEqual(t, http.Cookie{Name: "test0", Value: "value", Domain: "example.com"}, *cookie[0]) }) t.Run("large value", func(t *testing.T) { rec := httptest.NewRecorder() cookie := zhttp.SetMultiCookie(rec, &http.Cookie{Name: "test", Value: strings.Repeat("0123456789", 400)}) - ztesting.AssertEqual(t, "2 cookie should be set", 2, len(cookie)) - ztesting.AssertEqual(t, "0-th cookie not match", http.Cookie{Name: "test0", Value: strings.Repeat("0123456789", 200)}, *cookie[0]) - ztesting.AssertEqual(t, "1-th cookie not match", http.Cookie{Name: "test1", Value: strings.Repeat("0123456789", 200)}, *cookie[1]) + ztesting.AssertEqual(t, 2, len(cookie)) + ztesting.AssertEqual(t, http.Cookie{Name: "test0", Value: strings.Repeat("0123456789", 200)}, *cookie[0]) + ztesting.AssertEqual(t, http.Cookie{Name: "test1", Value: strings.Repeat("0123456789", 200)}, *cookie[1]) }) t.Run("max length value", func(t *testing.T) { rec := httptest.NewRecorder() cookie := zhttp.SetMultiCookie(rec, &http.Cookie{Name: "test", Value: strings.Repeat("0123456789", 396) + "01234567"}) - ztesting.AssertEqual(t, "2 cookie should be set", 2, len(cookie)) - ztesting.AssertEqual(t, "0-th cookie not match", http.Cookie{Name: "test0", Value: strings.Repeat("0123456789", 198) + "0123"}, *cookie[0]) - ztesting.AssertEqual(t, "1-th cookie not match", http.Cookie{Name: "test1", Value: "456789" + strings.Repeat("0123456789", 197) + "01234567"}, *cookie[1]) + ztesting.AssertEqual(t, 2, len(cookie)) + ztesting.AssertEqual(t, http.Cookie{Name: "test0", Value: strings.Repeat("0123456789", 198) + "0123"}, *cookie[0]) + ztesting.AssertEqual(t, http.Cookie{Name: "test1", Value: "456789" + strings.Repeat("0123456789", 197) + "01234567"}, *cookie[1]) }) } diff --git a/znet/zhttp/error_test.go b/znet/zhttp/error_test.go index 9853abc..c3e1e2b 100644 --- a/znet/zhttp/error_test.go +++ b/znet/zhttp/error_test.go @@ -24,8 +24,8 @@ func TestNewErrorHandler(t *testing.T) { r := httptest.NewRequest(http.MethodGet, "http://test.com", nil) w := httptest.NewRecorder() eh(w, r, &zhttp.HTTPError{Code: http.StatusBadGateway}) - ztesting.AssertEqual(t, "message not contained", true, strings.Contains(buf.String(), `level=ERROR`)) - ztesting.AssertEqual(t, "response status not match", http.StatusBadGateway, w.Result().StatusCode) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `level=ERROR`)) + ztesting.AssertEqual(t, http.StatusBadGateway, w.Result().StatusCode) }) t.Run("client-side error with info logger", func(t *testing.T) { var buf bytes.Buffer @@ -34,8 +34,8 @@ func TestNewErrorHandler(t *testing.T) { r := httptest.NewRequest(http.MethodGet, "http://test.com", nil) w := httptest.NewRecorder() eh(w, r, &zhttp.HTTPError{Code: http.StatusBadRequest}) - ztesting.AssertEqual(t, "message not match", "", buf.String()) - ztesting.AssertEqual(t, "response status not match", http.StatusBadRequest, w.Result().StatusCode) + ztesting.AssertEqual(t, "", buf.String()) + ztesting.AssertEqual(t, http.StatusBadRequest, w.Result().StatusCode) }) t.Run("client-side error with debug logger", func(t *testing.T) { var buf bytes.Buffer @@ -44,8 +44,8 @@ func TestNewErrorHandler(t *testing.T) { r := httptest.NewRequest(http.MethodGet, "http://test.com", nil) w := httptest.NewRecorder() eh(w, r, &zhttp.HTTPError{Code: http.StatusBadRequest}) - ztesting.AssertEqual(t, "message not contained", true, strings.Contains(buf.String(), `level=DEBUG`)) - ztesting.AssertEqual(t, "response status not match", http.StatusBadRequest, w.Result().StatusCode) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `level=DEBUG`)) + ztesting.AssertEqual(t, http.StatusBadRequest, w.Result().StatusCode) }) t.Run("non http error", func(t *testing.T) { var buf bytes.Buffer @@ -54,8 +54,8 @@ func TestNewErrorHandler(t *testing.T) { r := httptest.NewRequest(http.MethodGet, "http://test.com", nil) w := httptest.NewRecorder() eh(w, r, io.EOF) - ztesting.AssertEqual(t, "message not contained", true, strings.Contains(buf.String(), `level=ERROR`)) - ztesting.AssertEqual(t, "response status not match", http.StatusInternalServerError, w.Result().StatusCode) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), `level=ERROR`)) + ztesting.AssertEqual(t, http.StatusInternalServerError, w.Result().StatusCode) }) } @@ -70,7 +70,7 @@ func TestHTTPError_Error(t *testing.T) { } got := err.Error() want := "test cause (Code:200). test detail" - ztesting.AssertEqual(t, "error message not match", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("empty detail", func(t *testing.T) { err := &zhttp.HTTPError{ @@ -81,7 +81,7 @@ func TestHTTPError_Error(t *testing.T) { } got := err.Error() want := "test cause (Code:200)." - ztesting.AssertEqual(t, "error message not match", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("non-nil inner error", func(t *testing.T) { err := &zhttp.HTTPError{ @@ -91,7 +91,7 @@ func TestHTTPError_Error(t *testing.T) { } got := err.Error() want := "test cause (Code:200). [EOF]" - ztesting.AssertEqual(t, "error message not match", want, got) + ztesting.AssertEqual(t, want, got) }) } @@ -100,36 +100,36 @@ func TestHTTPError_Is(t *testing.T) { t.Run("same error", func(t *testing.T) { err1 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo"} err2 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo"} - ztesting.AssertEqual(t, "errors not match", true, err1.Is(err2)) + ztesting.AssertEqual(t, true, err1.Is(err2)) }) t.Run("same after unwrap", func(t *testing.T) { err1 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo"} err2 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo"} err3 := fmt.Errorf("outer error [%w]", err2) - ztesting.AssertEqual(t, "errors not match", true, err1.Is(err3)) + ztesting.AssertEqual(t, true, err1.Is(err3)) }) t.Run("not match nil", func(t *testing.T) { err1 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo"} - ztesting.AssertEqual(t, "errors unexpectedly matched", false, err1.Is(nil)) + ztesting.AssertEqual(t, false, err1.Is(nil)) }) t.Run("not match after unwrap", func(t *testing.T) { err1 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo"} err2 := fmt.Errorf("outer error [%w]", io.EOF) - ztesting.AssertEqual(t, "errors unexpectedly matched", false, err1.Is(err2)) + ztesting.AssertEqual(t, false, err1.Is(err2)) }) t.Run("unwrap error", func(t *testing.T) { err1 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo"} err2 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo", Err: io.EOF} - ztesting.AssertEqual(t, "errors unexpectedly matched", false, err1.Is(err2.Unwrap())) + ztesting.AssertEqual(t, false, err1.Is(err2.Unwrap())) }) t.Run("status not match", func(t *testing.T) { err1 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo"} err2 := &zhttp.HTTPError{Code: http.StatusBadGateway, Cause: "foo"} - ztesting.AssertEqual(t, "errors unexpectedly matched", false, err1.Is(err2)) + ztesting.AssertEqual(t, false, err1.Is(err2)) }) t.Run("cause not match", func(t *testing.T) { err1 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "foo"} err2 := &zhttp.HTTPError{Code: http.StatusOK, Cause: "bar"} - ztesting.AssertEqual(t, "errors unexpectedly matched", false, err1.Is(err2)) + ztesting.AssertEqual(t, false, err1.Is(err2)) }) } diff --git a/znet/zhttp/header_test.go b/znet/zhttp/header_test.go index 81fd2c1..f0d8a53 100644 --- a/znet/zhttp/header_test.go +++ b/znet/zhttp/header_test.go @@ -14,29 +14,29 @@ func TestHTTPHeader(t *testing.T) { h := httpHeader{} h.Add("Test", "v1") h.Add("Test", "v2") - ztesting.AssertEqual(t, "values not match", []string{"v1", "v2"}, h["Test"]) + ztesting.AssertEqual(t, []string{"v1", "v2"}, h["Test"]) }) t.Run("del", func(t *testing.T) { h := httpHeader{"Test": {"value"}} h.Del("Test") - ztesting.AssertEqual(t, "values not match", nil, h["Test"]) + ztesting.AssertEqual(t, nil, h["Test"]) }) t.Run("get exist", func(t *testing.T) { h := httpHeader{"Test": {"v1", "v2"}} - ztesting.AssertEqual(t, "values not match", "v1", h.Get("Test")) + ztesting.AssertEqual(t, "v1", h.Get("Test")) }) t.Run("get non exist", func(t *testing.T) { h := httpHeader{} - ztesting.AssertEqual(t, "values not match", "", h.Get("Test")) + ztesting.AssertEqual(t, "", h.Get("Test")) }) t.Run("set", func(t *testing.T) { h := httpHeader{"Test": {"v1", "v2"}} h.Set("Test", "v3") - ztesting.AssertEqual(t, "values not match", []string{"v3"}, h["Test"]) + ztesting.AssertEqual(t, []string{"v3"}, h["Test"]) }) t.Run("values", func(t *testing.T) { h := httpHeader{"Test": {"v1", "v2"}} - ztesting.AssertEqual(t, "values not match", []string{"v1", "v2"}, h.Values("Test")) + ztesting.AssertEqual(t, []string{"v1", "v2"}, h.Values("Test")) }) } @@ -49,11 +49,11 @@ func TestSetForwardedHeaders(t *testing.T) { } h := http.Header{} SetForwardedHeaders(r, h) - ztesting.AssertEqual(t, "Forwarded not match", `for="127.0.0.1"; host="test.com"; proto=http`, h.Get("Forwarded")) - ztesting.AssertEqual(t, "X-Forwarded-For not match", "127.0.0.1", h.Get("X-Forwarded-For")) - ztesting.AssertEqual(t, "X-Forwarded-Port not match", "1234", h.Get("X-Forwarded-Port")) - ztesting.AssertEqual(t, "X-Forwarded-Host not match", "test.com", h.Get("X-Forwarded-Host")) - ztesting.AssertEqual(t, "X-Forwarded-Proto not match", "http", h.Get("X-Forwarded-Proto")) + ztesting.AssertEqual(t, `for="127.0.0.1"; host="test.com"; proto=http`, h.Get("Forwarded")) + ztesting.AssertEqual(t, "127.0.0.1", h.Get("X-Forwarded-For")) + ztesting.AssertEqual(t, "1234", h.Get("X-Forwarded-Port")) + ztesting.AssertEqual(t, "test.com", h.Get("X-Forwarded-Host")) + ztesting.AssertEqual(t, "http", h.Get("X-Forwarded-Proto")) }) t.Run("invalid remote addr", func(t *testing.T) { r := &http.Request{ @@ -62,11 +62,11 @@ func TestSetForwardedHeaders(t *testing.T) { } h := http.Header{} SetForwardedHeaders(r, h) - ztesting.AssertEqual(t, "Forwarded not match", "", h.Get("Forwarded")) - ztesting.AssertEqual(t, "X-Forwarded-For not match", "", h.Get("X-Forwarded-For")) - ztesting.AssertEqual(t, "X-Forwarded-Port not match", "", h.Get("X-Forwarded-Port")) - ztesting.AssertEqual(t, "X-Forwarded-Host not match", "test.com", h.Get("X-Forwarded-Host")) - ztesting.AssertEqual(t, "X-Forwarded-Proto not match", "http", h.Get("X-Forwarded-Proto")) + ztesting.AssertEqual(t, "", h.Get("Forwarded")) + ztesting.AssertEqual(t, "", h.Get("X-Forwarded-For")) + ztesting.AssertEqual(t, "", h.Get("X-Forwarded-Port")) + ztesting.AssertEqual(t, "test.com", h.Get("X-Forwarded-Host")) + ztesting.AssertEqual(t, "http", h.Get("X-Forwarded-Proto")) }) t.Run("https", func(t *testing.T) { r := &http.Request{ @@ -76,11 +76,11 @@ func TestSetForwardedHeaders(t *testing.T) { } h := http.Header{} SetForwardedHeaders(r, h) - ztesting.AssertEqual(t, "Forwarded not match", `for="127.0.0.1"; host="test.com"; proto=https`, h.Get("Forwarded")) - ztesting.AssertEqual(t, "X-Forwarded-For not match", "127.0.0.1", h.Get("X-Forwarded-For")) - ztesting.AssertEqual(t, "X-Forwarded-Port not match", "1234", h.Get("X-Forwarded-Port")) - ztesting.AssertEqual(t, "X-Forwarded-Host not match", "test.com", h.Get("X-Forwarded-Host")) - ztesting.AssertEqual(t, "X-Forwarded-Proto not match", "https", h.Get("X-Forwarded-Proto")) + ztesting.AssertEqual(t, `for="127.0.0.1"; host="test.com"; proto=https`, h.Get("Forwarded")) + ztesting.AssertEqual(t, "127.0.0.1", h.Get("X-Forwarded-For")) + ztesting.AssertEqual(t, "1234", h.Get("X-Forwarded-Port")) + ztesting.AssertEqual(t, "test.com", h.Get("X-Forwarded-Host")) + ztesting.AssertEqual(t, "https", h.Get("X-Forwarded-Proto")) }) t.Run("Forwarded exists", func(t *testing.T) { r := &http.Request{ @@ -96,11 +96,11 @@ func TestSetForwardedHeaders(t *testing.T) { } h := http.Header{} SetForwardedHeaders(r, h) - ztesting.AssertEqual(t, "Forwarded not match", `for="192.168.0.1", for="127.0.0.1"; host="test.com"; proto=http`, h.Get("Forwarded")) - ztesting.AssertEqual(t, "X-Forwarded-For not match", "192.168.0.1, 127.0.0.1", h.Get("X-Forwarded-For")) - ztesting.AssertEqual(t, "X-Forwarded-Port not match", "1234", h.Get("X-Forwarded-Port")) - ztesting.AssertEqual(t, "X-Forwarded-Host not match", "test.com", h.Get("X-Forwarded-Host")) - ztesting.AssertEqual(t, "X-Forwarded-Proto not match", "http", h.Get("X-Forwarded-Proto")) + ztesting.AssertEqual(t, `for="192.168.0.1", for="127.0.0.1"; host="test.com"; proto=http`, h.Get("Forwarded")) + ztesting.AssertEqual(t, "192.168.0.1, 127.0.0.1", h.Get("X-Forwarded-For")) + ztesting.AssertEqual(t, "1234", h.Get("X-Forwarded-Port")) + ztesting.AssertEqual(t, "test.com", h.Get("X-Forwarded-Host")) + ztesting.AssertEqual(t, "http", h.Get("X-Forwarded-Proto")) }) t.Run("don't set Forwarded", func(t *testing.T) { r := &http.Request{ @@ -111,7 +111,7 @@ func TestSetForwardedHeaders(t *testing.T) { h := http.Header{} SetForwardedHeaders(r, h) _, found := h["Forwarded"] - ztesting.AssertEqual(t, "found not match", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("don't set X-Forwarded-For", func(t *testing.T) { r := &http.Request{ @@ -122,7 +122,7 @@ func TestSetForwardedHeaders(t *testing.T) { h := http.Header{} SetForwardedHeaders(r, h) _, found := h["X-Forwarded-For"] - ztesting.AssertEqual(t, "found not match", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("don't set X-Forwarded-Port", func(t *testing.T) { r := &http.Request{ @@ -133,7 +133,7 @@ func TestSetForwardedHeaders(t *testing.T) { h := http.Header{} SetForwardedHeaders(r, h) _, found := h["X-Forwarded-Port"] - ztesting.AssertEqual(t, "found not match", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("don't set X-Forwarded-Host", func(t *testing.T) { r := &http.Request{ @@ -144,7 +144,7 @@ func TestSetForwardedHeaders(t *testing.T) { h := http.Header{} SetForwardedHeaders(r, h) _, found := h["X-Forwarded-Host"] - ztesting.AssertEqual(t, "found not match", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("don't set X-Forwarded-Proto", func(t *testing.T) { r := &http.Request{ @@ -155,7 +155,7 @@ func TestSetForwardedHeaders(t *testing.T) { h := http.Header{} SetForwardedHeaders(r, h) _, found := h["X-Forwarded-Proto"] - ztesting.AssertEqual(t, "found not match", false, found) + ztesting.AssertEqual(t, false, found) }) } @@ -176,17 +176,17 @@ func TestRemoveHopByHopHeaders(t *testing.T) { "Baz": []string{"Value-Baz"}, } RemoveHopByHopHeaders(h) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Keep-Alive")) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Proxy-Authenticate")) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Proxy-Authorization")) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Te")) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Trailer")) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Transfer-Encoding")) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Upgrade")) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Proxy-Connection")) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Foo")) - ztesting.AssertEqual(t, "header not deleted", "", h.Get("Bar")) - ztesting.AssertEqual(t, "header was deleted", "Value-Baz", h.Get("Baz")) + ztesting.AssertEqual(t, "", h.Get("Keep-Alive")) + ztesting.AssertEqual(t, "", h.Get("Proxy-Authenticate")) + ztesting.AssertEqual(t, "", h.Get("Proxy-Authorization")) + ztesting.AssertEqual(t, "", h.Get("Te")) + ztesting.AssertEqual(t, "", h.Get("Trailer")) + ztesting.AssertEqual(t, "", h.Get("Transfer-Encoding")) + ztesting.AssertEqual(t, "", h.Get("Upgrade")) + ztesting.AssertEqual(t, "", h.Get("Proxy-Connection")) + ztesting.AssertEqual(t, "", h.Get("Foo")) + ztesting.AssertEqual(t, "", h.Get("Bar")) + ztesting.AssertEqual(t, "Value-Baz", h.Get("Baz")) } func TestCopyHeaders(t *testing.T) { @@ -200,9 +200,9 @@ func TestCopyHeaders(t *testing.T) { "Baz": []string{"baz"}, } CopyHeaders(dst, src) - ztesting.AssertEqual(t, "value not match", []string{"foo"}, dst.Values("Foo")) - ztesting.AssertEqual(t, "value not match", []string{"bar1", "bar2"}, dst.Values("Bar")) - ztesting.AssertEqual(t, "value not match", []string{"baz"}, dst.Values("Baz")) + ztesting.AssertEqual(t, []string{"foo"}, dst.Values("Foo")) + ztesting.AssertEqual(t, []string{"bar1", "bar2"}, dst.Values("Bar")) + ztesting.AssertEqual(t, []string{"baz"}, dst.Values("Baz")) } func TestCopyTrailers(t *testing.T) { @@ -216,10 +216,10 @@ func TestCopyTrailers(t *testing.T) { "Baz": []string{"baz"}, } CopyTrailers(dst, src) - ztesting.AssertEqual(t, "value not match", []string{"foo"}, dst.Values("Foo")) - ztesting.AssertEqual(t, "value not match", []string{"bar1"}, dst.Values("Bar")) - ztesting.AssertEqual(t, "value not match", []string{"bar2"}, dst.Values(http.TrailerPrefix+"Bar")) - ztesting.AssertEqual(t, "value not match", []string{"baz"}, dst.Values(http.TrailerPrefix+"Baz")) + ztesting.AssertEqual(t, []string{"foo"}, dst.Values("Foo")) + ztesting.AssertEqual(t, []string{"bar1"}, dst.Values("Bar")) + ztesting.AssertEqual(t, []string{"bar2"}, dst.Values(http.TrailerPrefix+"Bar")) + ztesting.AssertEqual(t, []string{"baz"}, dst.Values(http.TrailerPrefix+"Baz")) } func TestParseQualifiedHeader(t *testing.T) { @@ -265,9 +265,9 @@ func TestParseQualifiedHeader(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { values, params := ParseQualifiedHeader(tc.header) - ztesting.AssertEqual(t, "values not match", tc.values, values) + ztesting.AssertEqual(t, tc.values, values) for i := range tc.params { - ztesting.AssertEqual(t, "params not match", tc.params[i], params[i]) + ztesting.AssertEqual(t, tc.params[i], params[i]) } }) } @@ -294,9 +294,9 @@ func TestParseHeader(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { values, params := ParseHeader(tc.header) - ztesting.AssertEqual(t, "values not match", tc.values, values) + ztesting.AssertEqual(t, tc.values, values) for i := range tc.params { - ztesting.AssertEqual(t, "params not match", tc.params[i], params[i]) + ztesting.AssertEqual(t, tc.params[i], params[i]) } }) } @@ -331,7 +331,7 @@ func TestMatchMediaType(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := MatchMediaType(tc.mt, tc.list) - ztesting.AssertEqual(t, "returned type not match", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -360,7 +360,7 @@ func TestScanElement(t *testing.T) { got = append(got, e) } } - ztesting.AssertEqual(t, "elems not match", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } diff --git a/znet/zhttp/middleware_test.go b/znet/zhttp/middleware_test.go index ff848d1..e1bbf10 100644 --- a/znet/zhttp/middleware_test.go +++ b/znet/zhttp/middleware_test.go @@ -23,7 +23,7 @@ func TestServerMiddlewareFunc(t *testing.T) { }) }) m.ServerMiddleware(nopHandler).ServeHTTP(nil, nil) - ztesting.AssertEqual(t, "middleware was not called", true, called) + ztesting.AssertEqual(t, true, called) } func TestClientMiddlewareFunc(t *testing.T) { @@ -36,7 +36,7 @@ func TestClientMiddlewareFunc(t *testing.T) { }) }) m.ClientMiddleware(nopRoundTripper).RoundTrip(nil) - ztesting.AssertEqual(t, "middleware was not called", true, called) + ztesting.AssertEqual(t, true, called) } type testMiddleware struct { @@ -76,7 +76,7 @@ func TestNewHandler(t *testing.T) { ms = append(ms, &testMiddleware{name: n, list: &list}) } zhttp.NewHandler(nopHandler, ms...).ServeHTTP(nil, nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -110,7 +110,7 @@ func TestServerMiddlewareChain_Handler(t *testing.T) { ms = append(ms, &testMiddleware{name: n, list: &list}) } chain.Handler(nopHandler, ms...).ServeHTTP(nil, nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -158,7 +158,7 @@ func TestServerMiddlewareChain_Insert(t *testing.T) { } chain.Insert(tc.index, ms...) chain.ServerMiddleware(nopHandler).ServeHTTP(nil, nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -193,7 +193,7 @@ func TestServerMiddlewareChain_InsertAll(t *testing.T) { } chain.InsertAll(ms...) chain.ServerMiddleware(nopHandler).ServeHTTP(nil, nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -228,7 +228,7 @@ func TestServerMiddlewareChain_BeforeAll(t *testing.T) { } chain.BeforeAll(ms...) chain.ServerMiddleware(nopHandler).ServeHTTP(nil, nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -263,7 +263,7 @@ func TestServerMiddlewareChain_AfterAll(t *testing.T) { } chain.AfterAll(ms...) chain.ServerMiddleware(nopHandler).ServeHTTP(nil, nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -286,7 +286,7 @@ func TestNewRoundTripper(t *testing.T) { ms = append(ms, &testMiddleware{name: n, list: &list}) } zhttp.NewRoundTripper(nopRoundTripper, ms...).RoundTrip(nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -320,7 +320,7 @@ func TestClientMiddlewareChain_RoundTripper(t *testing.T) { ms = append(ms, &testMiddleware{name: n, list: &list}) } chain.RoundTripper(nopRoundTripper, ms...).RoundTrip(nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -368,7 +368,7 @@ func TestClientMiddlewareChain_Insert(t *testing.T) { } chain.Insert(tc.index, ms...) chain.ClientMiddleware(nopRoundTripper).RoundTrip(nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -403,7 +403,7 @@ func TestClientMiddlewareChain_InsertAll(t *testing.T) { } chain.InsertAll(ms...) chain.ClientMiddleware(nopRoundTripper).RoundTrip(nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -438,7 +438,7 @@ func TestClientMiddlewareChain_BeforeAll(t *testing.T) { } chain.BeforeAll(ms...) chain.ClientMiddleware(nopRoundTripper).RoundTrip(nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } @@ -473,7 +473,7 @@ func TestClientMiddlewareChain_AfterAll(t *testing.T) { } chain.AfterAll(ms...) chain.ClientMiddleware(nopRoundTripper).RoundTrip(nil) - ztesting.AssertEqual(t, "middleware not match", tc.want, list) + ztesting.AssertEqual(t, tc.want, list) }) } } diff --git a/znet/zhttp/proxy_test.go b/znet/zhttp/proxy_test.go index da20ec7..c3ae0e7 100644 --- a/znet/zhttp/proxy_test.go +++ b/znet/zhttp/proxy_test.go @@ -45,7 +45,7 @@ func TestRewriteProxyURL(t *testing.T) { matched := reflect.DeepEqual(tc.want, tc.dst) t.Logf("dst: %#v\n", tc.dst) t.Logf("want: %#v\n", tc.want) - ztesting.AssertEqual(t, "url not match", true, matched) + ztesting.AssertEqual(t, true, matched) }) } } @@ -82,7 +82,7 @@ func TestJoinWithByte(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := joinWithByte(tc.left, tc.right, '/') - ztesting.AssertEqual(t, "join not match", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -110,10 +110,10 @@ func TestNewProxy(t *testing.T) { t.Run(name, func(t *testing.T) { proxy, err := NewProxy(tc.targets...) if tc.err != nil { - ztesting.AssertEqual(t, "error should not be nil", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) return } - ztesting.AssertEqualErr(t, "error should be nil", nil, err) + ztesting.AssertEqualErr(t, nil, err) nt := &nopTransport{} proxy.Transport = nt r := httptest.NewRequest(http.MethodGet, "http://example.com", nil) @@ -121,7 +121,7 @@ func TestNewProxy(t *testing.T) { for i := range 2 * len(tc.targets) { target := tc.targets[i%len(tc.targets)] proxy.ServeHTTP(w, r) - ztesting.AssertEqual(t, "url not match", target, nt.r.URL.String()) + ztesting.AssertEqual(t, target, nt.r.URL.String()) } }) } @@ -154,11 +154,11 @@ func TestProxy(t *testing.T) { } resp := httptest.NewRecorder() proxy.ServeHTTP(resp, req) - ztesting.AssertEqual(t, "method not match", http.MethodGet, tp.req.Method) - ztesting.AssertEqual(t, "target not match", "http://test.com", tp.req.URL.String()) - ztesting.AssertEqual(t, "response status not match", http.StatusBadRequest, resp.Result().StatusCode) - ztesting.AssertEqual(t, "response header not match", "foo", resp.Header().Get("Test")) - ztesting.AssertEqual(t, "response body not match", "resp body", resp.Body.String()) + ztesting.AssertEqual(t, http.MethodGet, tp.req.Method) + ztesting.AssertEqual(t, "http://test.com", tp.req.URL.String()) + ztesting.AssertEqual(t, http.StatusBadRequest, resp.Result().StatusCode) + ztesting.AssertEqual(t, "foo", resp.Header().Get("Test")) + ztesting.AssertEqual(t, "resp body", resp.Body.String()) }) t.Run("simple request with body", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://test.com", strings.NewReader("req body")) @@ -175,12 +175,12 @@ func TestProxy(t *testing.T) { resp := httptest.NewRecorder() proxy.ServeHTTP(resp, req) body, _ := io.ReadAll(tp.req.Body) - ztesting.AssertEqual(t, "method not match", http.MethodGet, tp.req.Method) - ztesting.AssertEqual(t, "target not match", "http://test.com", tp.req.URL.String()) - ztesting.AssertEqual(t, "request body not match", "req body", string(body)) - ztesting.AssertEqual(t, "response status not match", http.StatusBadRequest, resp.Result().StatusCode) - ztesting.AssertEqual(t, "response header not match", "foo", resp.Header().Get("Test")) - ztesting.AssertEqual(t, "response body not match", "resp body", resp.Body.String()) + ztesting.AssertEqual(t, http.MethodGet, tp.req.Method) + ztesting.AssertEqual(t, "http://test.com", tp.req.URL.String()) + ztesting.AssertEqual(t, "req body", string(body)) + ztesting.AssertEqual(t, http.StatusBadRequest, resp.Result().StatusCode) + ztesting.AssertEqual(t, "foo", resp.Header().Get("Test")) + ztesting.AssertEqual(t, "resp body", resp.Body.String()) }) t.Run("nil request header", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://test.com", nil) @@ -194,7 +194,7 @@ func TestProxy(t *testing.T) { resp := httptest.NewRecorder() proxy.ServeHTTP(resp, req) t.Log(tp.req.Header) - ztesting.AssertEqual(t, "header not match", true, reflect.DeepEqual(http.Header{"User-Agent": []string{""}}, tp.req.Header)) + ztesting.AssertEqual(t, true, reflect.DeepEqual(http.Header{"User-Agent": []string{""}}, tp.req.Header)) }) t.Run("request with trailer", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://test.com", nil) @@ -207,7 +207,7 @@ func TestProxy(t *testing.T) { } resp := httptest.NewRecorder() proxy.ServeHTTP(resp, req) - ztesting.AssertEqual(t, "trailers not found", "trailers", tp.req.Header.Get("Te")) + ztesting.AssertEqual(t, "trailers", tp.req.Header.Get("Te")) }) t.Run("response with trailer", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://test.com", nil) @@ -219,8 +219,8 @@ func TestProxy(t *testing.T) { rec := httptest.NewRecorder() resp := &testFlushResponse{ResponseWriter: rec} proxy.ServeHTTP(resp, req) - ztesting.AssertEqual(t, "trailers not match", "foo", rec.Result().Trailer.Get("Test")) - ztesting.AssertEqual(t, "response not flushed", true, resp.flushed) + ztesting.AssertEqual(t, "foo", rec.Result().Trailer.Get("Test")) + ztesting.AssertEqual(t, true, resp.flushed) }) t.Run("protocol switch", func(t *testing.T) { respRW := bufio.NewReadWriter(nil, bufio.NewWriter(&bytes.Buffer{})) @@ -241,8 +241,8 @@ func TestProxy(t *testing.T) { Transport: &testTransport{resp: res}, } proxy.ServeHTTP(rw, req) - ztesting.AssertEqual(t, "copied content not match", "foo", buf.String()) - ztesting.AssertEqual(t, "copied content not match", "bar", conn.content.String()) + ztesting.AssertEqual(t, "foo", buf.String()) + ztesting.AssertEqual(t, "bar", conn.content.String()) }) t.Run("pre roundtrip error", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://test.com", nil) @@ -256,7 +256,7 @@ func TestProxy(t *testing.T) { } resp := httptest.NewRecorder() proxy.ServeHTTP(resp, req) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CausePreRoundTrip, Code: http.StatusInternalServerError}, gotErr) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CausePreRoundTrip, Code: http.StatusInternalServerError}, gotErr) }) t.Run("post roundtrip error", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://test.com", nil) @@ -270,7 +270,7 @@ func TestProxy(t *testing.T) { } resp := httptest.NewRecorder() proxy.ServeHTTP(resp, req) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CausePostRoundTrip, Code: http.StatusInternalServerError}, gotErr) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CausePostRoundTrip, Code: http.StatusInternalServerError}, gotErr) }) t.Run("upgrade error", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://test.com", nil) @@ -283,7 +283,7 @@ func TestProxy(t *testing.T) { } resp := httptest.NewRecorder() proxy.ServeHTTP(resp, req) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseUpgrade, Code: http.StatusInternalServerError}, gotErr) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseUpgrade, Code: http.StatusInternalServerError}, gotErr) }) t.Run("copy response body error", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://test.com", nil) @@ -297,8 +297,8 @@ func TestProxy(t *testing.T) { } resp := httptest.NewRecorder() proxy.ServeHTTP(resp, req) - ztesting.AssertEqual(t, "copied body not match", "test", resp.Body.String()) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseCopyResponse, Code: -1}, gotErr) + ztesting.AssertEqual(t, "test", resp.Body.String()) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseCopyResponse, Code: -1}, gotErr) }) t.Run("copy trailer error", func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://test.com", nil) @@ -311,7 +311,7 @@ func TestProxy(t *testing.T) { } resp := struct{ http.ResponseWriter }{httptest.NewRecorder()} // Resp does not implement flusher. proxy.ServeHTTP(resp, req) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseFlushBody, Code: -1}, gotErr) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseFlushBody, Code: -1}, gotErr) }) } @@ -370,9 +370,9 @@ func TestHandleUpgradeResponse(t *testing.T) { res := &http.Response{Header: http.Header{"Connection": {"Upgrade"}, "Upgrade": {"test"}}, Body: body} err := handleUpgradeResponse(rw, req, res) - ztesting.AssertEqualErr(t, "error not match", (*HTTPError)(nil), err) - ztesting.AssertEqual(t, "copied content not match", "foo", buf.String()) - ztesting.AssertEqual(t, "copied content not match", "bar", conn.content.String()) + ztesting.AssertEqualErr(t, (*HTTPError)(nil), err) + ztesting.AssertEqual(t, "foo", buf.String()) + ztesting.AssertEqual(t, "bar", conn.content.String()) }) t.Run("upgrade not match", func(t *testing.T) { respRW := bufio.NewReadWriter(nil, bufio.NewWriter(&bytes.Buffer{})) @@ -385,9 +385,9 @@ func TestHandleUpgradeResponse(t *testing.T) { res := &http.Response{Header: http.Header{"Connection": {"Upgrade"}, "Upgrade": {"test2"}}, Body: body} err := handleUpgradeResponse(rw, req, res) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseUpgradeMismatch, Code: http.StatusBadRequest}, err) - ztesting.AssertEqual(t, "copied content not match", "", buf.String()) - ztesting.AssertEqual(t, "copied content not match", "", conn.content.String()) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseUpgradeMismatch, Code: http.StatusBadRequest}, err) + ztesting.AssertEqual(t, "", buf.String()) + ztesting.AssertEqual(t, "", conn.content.String()) }) t.Run("no connection header", func(t *testing.T) { respRW := bufio.NewReadWriter(nil, bufio.NewWriter(&bytes.Buffer{})) @@ -400,9 +400,9 @@ func TestHandleUpgradeResponse(t *testing.T) { res := &http.Response{Header: http.Header{"Connection": {""}, "Upgrade": {"test2"}}, Body: body} // No connection header. err := handleUpgradeResponse(rw, req, res) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseUpgradeMismatch, Code: http.StatusBadRequest}, err) - ztesting.AssertEqual(t, "copied content not match", "", buf.String()) - ztesting.AssertEqual(t, "copied content not match", "", conn.content.String()) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseUpgradeMismatch, Code: http.StatusBadRequest}, err) + ztesting.AssertEqual(t, "", buf.String()) + ztesting.AssertEqual(t, "", conn.content.String()) }) t.Run("non ReadWriteCloser body", func(t *testing.T) { respRW := bufio.NewReadWriter(nil, bufio.NewWriter(&bytes.Buffer{})) @@ -414,9 +414,9 @@ func TestHandleUpgradeResponse(t *testing.T) { res := &http.Response{Header: http.Header{"Connection": {"Upgrade"}, "Upgrade": {"test"}}, Body: nil} // Body is nil. err := handleUpgradeResponse(rw, req, res) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseUpgrade, Code: http.StatusInternalServerError}, err) - ztesting.AssertEqual(t, "copied content not match", "", buf.String()) - ztesting.AssertEqual(t, "copied content not match", "", conn.content.String()) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseUpgrade, Code: http.StatusInternalServerError}, err) + ztesting.AssertEqual(t, "", buf.String()) + ztesting.AssertEqual(t, "", conn.content.String()) }) t.Run("hijack failed", func(t *testing.T) { respRW := bufio.NewReadWriter(nil, bufio.NewWriter(&bytes.Buffer{})) @@ -430,9 +430,9 @@ func TestHandleUpgradeResponse(t *testing.T) { res := &http.Response{Header: http.Header{"Connection": {"Upgrade"}, "Upgrade": {"test"}}, Body: body} err := handleUpgradeResponse(rw, req, res) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseHijack, Code: http.StatusInternalServerError}, err) - ztesting.AssertEqual(t, "copied content not match", "", buf.String()) - ztesting.AssertEqual(t, "copied content not match", "", conn.content.String()) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseHijack, Code: http.StatusInternalServerError}, err) + ztesting.AssertEqual(t, "", buf.String()) + ztesting.AssertEqual(t, "", conn.content.String()) }) t.Run("flush error", func(t *testing.T) { ew := ziotest.ErrWriter(&bytes.Buffer{}, 0) // Error writer results in flush error. @@ -446,9 +446,9 @@ func TestHandleUpgradeResponse(t *testing.T) { res := &http.Response{Header: http.Header{"Connection": {"Upgrade"}, "Upgrade": {"test"}}, Body: body} err := handleUpgradeResponse(rw, req, res) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseFlushBody, Code: -1}, err) - ztesting.AssertEqual(t, "copied content not match", "", buf.String()) - ztesting.AssertEqual(t, "copied content not match", "", conn.content.String()) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseFlushBody, Code: -1}, err) + ztesting.AssertEqual(t, "", buf.String()) + ztesting.AssertEqual(t, "", conn.content.String()) }) t.Run("response header write error", func(t *testing.T) { respRW := bufio.NewReadWriter(nil, bufio.NewWriterSize(ziotest.ErrWriter(&bytes.Buffer{}, 0), 1)) // Error writer. @@ -461,9 +461,9 @@ func TestHandleUpgradeResponse(t *testing.T) { res := &http.Response{Header: http.Header{"Connection": {"Upgrade"}, "Upgrade": {"test"}}, Body: body} err := handleUpgradeResponse(rw, req, res) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseCopyResponse, Code: -1}, err) - ztesting.AssertEqual(t, "copied content not match", "", buf.String()) - ztesting.AssertEqual(t, "copied content not match", "", conn.content.String()) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseCopyResponse, Code: -1}, err) + ztesting.AssertEqual(t, "", buf.String()) + ztesting.AssertEqual(t, "", conn.content.String()) }) t.Run("copy front to back error", func(t *testing.T) { respRW := bufio.NewReadWriter(nil, bufio.NewWriter(&bytes.Buffer{})) @@ -476,9 +476,9 @@ func TestHandleUpgradeResponse(t *testing.T) { res := &http.Response{Header: http.Header{"Connection": {"Upgrade"}, "Upgrade": {"test"}}, Body: body} err := handleUpgradeResponse(rw, req, res) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseCopyResponse, Code: -1}, err) - ztesting.AssertEqual(t, "copied content not match", "f", buf.String()) - // ztesting.AssertEqual(t, "copied content not match", "bar", conn.content.String()) // Do not check. + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseCopyResponse, Code: -1}, err) + ztesting.AssertEqual(t, "f", buf.String()) + // ztesting.AssertEqual(t, "bar", conn.content.String()) // Do not check. }) t.Run("copy back to front error", func(t *testing.T) { respRW := bufio.NewReadWriter(nil, bufio.NewWriter(&bytes.Buffer{})) @@ -491,9 +491,9 @@ func TestHandleUpgradeResponse(t *testing.T) { res := &http.Response{Header: http.Header{"Connection": {"Upgrade"}, "Upgrade": {"test"}}, Body: body} err := handleUpgradeResponse(rw, req, res) - ztesting.AssertEqualErr(t, "error not match", &HTTPError{Cause: CauseCopyResponse, Code: -1}, err) - // ztesting.AssertEqual(t, "copied content not match", "foo", buf.String()) // Do not check. - ztesting.AssertEqual(t, "copied content not match", "b", conn.content.String()) + ztesting.AssertEqualErr(t, &HTTPError{Cause: CauseCopyResponse, Code: -1}, err) + // ztesting.AssertEqual(t, "foo", buf.String()) // Do not check. + ztesting.AssertEqual(t, "b", conn.content.String()) }) } @@ -519,8 +519,8 @@ func TestCopyResponseBody(t *testing.T) { w := &testFlushResponse{ResponseWriter: rec} res := &http.Response{ContentLength: -1, Body: io.NopCloser(strings.NewReader("test"))} copyResponseBody(w, res) - ztesting.AssertEqual(t, "flush not called", true, w.flushed) - ztesting.AssertEqual(t, "written body not match not", "test", w.body.String()) + ztesting.AssertEqual(t, true, w.flushed) + ztesting.AssertEqual(t, "test", w.body.String()) }) t.Run("sse", func(t *testing.T) { rec := httptest.NewRecorder() @@ -529,8 +529,8 @@ func TestCopyResponseBody(t *testing.T) { Header: http.Header{"Content-Type": {"text/event-stream"}}, Body: io.NopCloser(strings.NewReader("test"))} copyResponseBody(w, res) - ztesting.AssertEqual(t, "flush not called", true, w.flushed) - ztesting.AssertEqual(t, "written body not match not", "test", w.body.String()) + ztesting.AssertEqual(t, true, w.flushed) + ztesting.AssertEqual(t, "test", w.body.String()) }) t.Run("chunked", func(t *testing.T) { rec := httptest.NewRecorder() @@ -539,16 +539,16 @@ func TestCopyResponseBody(t *testing.T) { Header: http.Header{"Transfer-Encoding": {"chunked"}}, Body: io.NopCloser(strings.NewReader("test"))} copyResponseBody(w, res) - ztesting.AssertEqual(t, "flush not called", true, w.flushed) - ztesting.AssertEqual(t, "written body not match not", "test", w.body.String()) + ztesting.AssertEqual(t, true, w.flushed) + ztesting.AssertEqual(t, "test", w.body.String()) }) t.Run("default", func(t *testing.T) { rec := httptest.NewRecorder() w := &testFlushResponse{ResponseWriter: rec} res := &http.Response{Body: io.NopCloser(strings.NewReader("test"))} copyResponseBody(w, res) - ztesting.AssertEqual(t, "flush should not be called", false, w.flushed) - ztesting.AssertEqual(t, "written body not match not", "test", w.body.String()) + ztesting.AssertEqual(t, false, w.flushed) + ztesting.AssertEqual(t, "test", w.body.String()) }) } @@ -572,19 +572,19 @@ func TestWithImmediateFlushWriter(t *testing.T) { rec := httptest.NewRecorder() w := withImmediateFlushWriter(rec) w.Write([]byte("test")) - ztesting.AssertEqual(t, "body not written", "test", rec.Body.String()) + ztesting.AssertEqual(t, "test", rec.Body.String()) }) t.Run("unwrap flush", func(t *testing.T) { rec := httptest.NewRecorder() tr := &testResponseWrapper{ResponseWriter: rec} w := withImmediateFlushWriter(tr) w.Write([]byte("test")) - ztesting.AssertEqual(t, "body not written", "test", tr.body.String()) - ztesting.AssertEqual(t, "body not written", "test", rec.Body.String()) + ztesting.AssertEqual(t, "test", tr.body.String()) + ztesting.AssertEqual(t, "test", rec.Body.String()) }) t.Run("no flusher", func(t *testing.T) { tr := &testResponseWrapper{ResponseWriter: nil} w := withImmediateFlushWriter(tr) - ztesting.AssertEqual(t, "writer not match", io.Writer(tr), w) + ztesting.AssertEqual(t, io.Writer(tr), w) }) } diff --git a/znet/zhttp/request_test.go b/znet/zhttp/request_test.go index 13cc932..dd23e6f 100644 --- a/znet/zhttp/request_test.go +++ b/znet/zhttp/request_test.go @@ -18,14 +18,14 @@ func TestSetupRewindBody(t *testing.T) { Body: nil, } err := zhttp.SetupRewindBody(r) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("no body", func(t *testing.T) { r := &http.Request{ Body: http.NoBody, } err := zhttp.SetupRewindBody(r) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("idempotent", func(t *testing.T) { r := &http.Request{ @@ -33,17 +33,17 @@ func TestSetupRewindBody(t *testing.T) { Body: io.NopCloser(strings.NewReader("body")), } err := zhttp.SetupRewindBody(r) - ztesting.AssertEqualErr(t, "error not match", zhttp.ErrCannotRewind, err) + ztesting.AssertEqualErr(t, zhttp.ErrCannotRewind, err) }) t.Run("no get body", func(t *testing.T) { r := &http.Request{ Body: io.NopCloser(strings.NewReader("body")), } err := zhttp.SetupRewindBody(r) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) gb, _ := r.GetBody() body, _ := io.ReadAll(gb) - ztesting.AssertEqual(t, "body not match", "body", string(body)) + ztesting.AssertEqual(t, "body", string(body)) }) t.Run("get body", func(t *testing.T) { b := io.NopCloser(strings.NewReader("body")) @@ -52,15 +52,15 @@ func TestSetupRewindBody(t *testing.T) { Body: b, } err := zhttp.SetupRewindBody(r) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "body not match", b, r.Body) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, b, r.Body) }) t.Run("body read error", func(t *testing.T) { r := &http.Request{ Body: io.NopCloser(ziotest.ErrReader(strings.NewReader("body"), 2)), } err := zhttp.SetupRewindBody(r) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, err) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, err) }) } @@ -71,14 +71,14 @@ func TestRewindBody(t *testing.T) { Body: nil, } err := zhttp.RewindBody(r) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("no body", func(t *testing.T) { r := &http.Request{ Body: http.NoBody, } err := zhttp.RewindBody(r) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("idempotent", func(t *testing.T) { r := &http.Request{ @@ -86,14 +86,14 @@ func TestRewindBody(t *testing.T) { Body: io.NopCloser(strings.NewReader("body")), } err := zhttp.RewindBody(r) - ztesting.AssertEqualErr(t, "error not match", zhttp.ErrCannotRewind, err) + ztesting.AssertEqualErr(t, zhttp.ErrCannotRewind, err) }) t.Run("no get body", func(t *testing.T) { r := &http.Request{ Body: io.NopCloser(strings.NewReader("body")), } err := zhttp.RewindBody(r) - ztesting.AssertEqualErr(t, "error not match", zhttp.ErrCannotRewind, err) + ztesting.AssertEqualErr(t, zhttp.ErrCannotRewind, err) }) t.Run("get body", func(t *testing.T) { b := io.NopCloser(strings.NewReader("body")) @@ -102,8 +102,8 @@ func TestRewindBody(t *testing.T) { Body: io.NopCloser(strings.NewReader("temp")), } err := zhttp.RewindBody(r) - ztesting.AssertEqual(t, "body not match", b, r.Body) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, b, r.Body) + ztesting.AssertEqualErr(t, nil, err) }) } @@ -114,27 +114,27 @@ func TestReadBody(t *testing.T) { Body: nil, } body, err := zhttp.ReadBody(r) - ztesting.AssertEqual(t, "body length not match", 0, len(body)) - ztesting.AssertEqual(t, "body not match", "", string(body)) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 0, len(body)) + ztesting.AssertEqual(t, "", string(body)) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("no body", func(t *testing.T) { r := &http.Request{ Body: http.NoBody, } body, err := zhttp.ReadBody(r) - ztesting.AssertEqual(t, "body length not match", 0, len(body)) - ztesting.AssertEqual(t, "body not match", "", string(body)) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 0, len(body)) + ztesting.AssertEqual(t, "", string(body)) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("no get body", func(t *testing.T) { r := &http.Request{ Body: io.NopCloser(strings.NewReader("body")), } body, err := zhttp.ReadBody(r) - ztesting.AssertEqual(t, "body length not match", 4, len(body)) - ztesting.AssertEqual(t, "body not match", "body", string(body)) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 4, len(body)) + ztesting.AssertEqual(t, "body", string(body)) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("get body", func(t *testing.T) { r := &http.Request{ @@ -144,22 +144,22 @@ func TestReadBody(t *testing.T) { Body: io.NopCloser(strings.NewReader("temp")), } body, err := zhttp.ReadBody(r) - ztesting.AssertEqual(t, "body length not match", 4, len(body)) - ztesting.AssertEqual(t, "body not match", "body", string(body)) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 4, len(body)) + ztesting.AssertEqual(t, "body", string(body)) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("read multiple times", func(t *testing.T) { r := &http.Request{ Body: io.NopCloser(strings.NewReader("body")), } body, err := zhttp.ReadBody(r) - ztesting.AssertEqual(t, "body length not match", 4, len(body)) - ztesting.AssertEqual(t, "body not match", "body", string(body)) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 4, len(body)) + ztesting.AssertEqual(t, "body", string(body)) + ztesting.AssertEqualErr(t, nil, err) body, err = zhttp.ReadBody(r) - ztesting.AssertEqual(t, "body length not match", 4, len(body)) - ztesting.AssertEqual(t, "body not match", "body", string(body)) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 4, len(body)) + ztesting.AssertEqual(t, "body", string(body)) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("get body error", func(t *testing.T) { r := &http.Request{ @@ -169,17 +169,17 @@ func TestReadBody(t *testing.T) { Body: io.NopCloser(strings.NewReader("temp")), } body, err := zhttp.ReadBody(r) - ztesting.AssertEqual(t, "body length not match", 0, len(body)) - ztesting.AssertEqual(t, "body not match", "", string(body)) - ztesting.AssertEqualErr(t, "error not match", io.ErrUnexpectedEOF, err) + ztesting.AssertEqual(t, 0, len(body)) + ztesting.AssertEqual(t, "", string(body)) + ztesting.AssertEqualErr(t, io.ErrUnexpectedEOF, err) }) t.Run("read body error", func(t *testing.T) { r := &http.Request{ Body: io.NopCloser(ziotest.ErrReader(strings.NewReader("body"), 4)), } body, err := zhttp.ReadBody(r) - ztesting.AssertEqual(t, "body length not match", 0, len(body)) - ztesting.AssertEqual(t, "body not match", "", string(body)) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, err) + ztesting.AssertEqual(t, 0, len(body)) + ztesting.AssertEqual(t, "", string(body)) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, err) }) } diff --git a/znet/zhttp/response_test.go b/znet/zhttp/response_test.go index 85f48f1..ed18b32 100644 --- a/znet/zhttp/response_test.go +++ b/znet/zhttp/response_test.go @@ -14,15 +14,15 @@ func TestWrapResponseWriter(t *testing.T) { w := httptest.NewRecorder() ww := zhttp.WrapResponseWriter(w) ww.WriteHeader(http.StatusBadRequest) - ztesting.AssertEqual(t, "status code not match", http.StatusBadRequest, w.Result().StatusCode) + ztesting.AssertEqual(t, http.StatusBadRequest, w.Result().StatusCode) }) t.Run("already wrapped", func(t *testing.T) { w := httptest.NewRecorder() ww1 := zhttp.WrapResponseWriter(w) ww2 := zhttp.WrapResponseWriter(ww1) - ztesting.AssertEqual(t, "writer not match", ww1, ww2) + ztesting.AssertEqual(t, ww1, ww2) ww2.WriteHeader(http.StatusBadRequest) - ztesting.AssertEqual(t, "status code not match", http.StatusBadRequest, w.Result().StatusCode) + ztesting.AssertEqual(t, http.StatusBadRequest, w.Result().StatusCode) }) } @@ -30,37 +30,37 @@ func TestResponseWrapper(t *testing.T) { t.Run("not written", func(t *testing.T) { w := httptest.NewRecorder() ww := zhttp.WrapResponseWriter(w) - ztesting.AssertEqual(t, "status code not match", -1, ww.StatusCode()) - ztesting.AssertEqual(t, "written bytes not match", 0, ww.Written()) + ztesting.AssertEqual(t, -1, ww.StatusCode()) + ztesting.AssertEqual(t, 0, ww.Written()) }) t.Run("header written", func(t *testing.T) { w := httptest.NewRecorder() ww := zhttp.WrapResponseWriter(w) ww.Header().Set("Test", "value") // No affection. - ztesting.AssertEqual(t, "status code not match", -1, ww.StatusCode()) - ztesting.AssertEqual(t, "header not match", "value", ww.Header().Get("Test")) - ztesting.AssertEqual(t, "written bytes not match", 0, ww.Written()) + ztesting.AssertEqual(t, -1, ww.StatusCode()) + ztesting.AssertEqual(t, "value", ww.Header().Get("Test")) + ztesting.AssertEqual(t, 0, ww.Written()) }) t.Run("status written", func(t *testing.T) { w := httptest.NewRecorder() ww := zhttp.WrapResponseWriter(w) ww.WriteHeader(http.StatusBadRequest) - ztesting.AssertEqual(t, "status code not match", http.StatusBadRequest, ww.StatusCode()) - ztesting.AssertEqual(t, "written bytes not match", 0, ww.Written()) + ztesting.AssertEqual(t, http.StatusBadRequest, ww.StatusCode()) + ztesting.AssertEqual(t, 0, ww.Written()) }) t.Run("nil body written", func(t *testing.T) { w := httptest.NewRecorder() ww := zhttp.WrapResponseWriter(w) ww.Write(nil) - ztesting.AssertEqual(t, "status code not match", http.StatusOK, ww.StatusCode()) - ztesting.AssertEqual(t, "written bytes not match", 0, ww.Written()) + ztesting.AssertEqual(t, http.StatusOK, ww.StatusCode()) + ztesting.AssertEqual(t, 0, ww.Written()) }) t.Run("non-nil body written", func(t *testing.T) { w := httptest.NewRecorder() ww := zhttp.WrapResponseWriter(w) ww.Write([]byte("test")) - ztesting.AssertEqual(t, "status code not match", http.StatusOK, ww.StatusCode()) - ztesting.AssertEqual(t, "written bytes not match", 4, ww.Written()) + ztesting.AssertEqual(t, http.StatusOK, ww.StatusCode()) + ztesting.AssertEqual(t, 4, ww.Written()) }) t.Run("hook on status written", func(t *testing.T) { w := httptest.NewRecorder() @@ -68,7 +68,7 @@ func TestResponseWrapper(t *testing.T) { status := 0 ww.StatusWritten = func(statusCode int) { status = statusCode } ww.WriteHeader(http.StatusBadRequest) - ztesting.AssertEqual(t, "status code not match", http.StatusBadRequest, status) + ztesting.AssertEqual(t, http.StatusBadRequest, status) }) t.Run("hook on body written", func(t *testing.T) { w := httptest.NewRecorder() @@ -76,13 +76,13 @@ func TestResponseWrapper(t *testing.T) { status := 0 ww.StatusWritten = func(statusCode int) { status = statusCode } ww.Write(nil) - ztesting.AssertEqual(t, "status code not match", http.StatusOK, status) + ztesting.AssertEqual(t, http.StatusOK, status) }) t.Run("hijack error", func(t *testing.T) { w := httptest.NewRecorder() ww := zhttp.WrapResponseWriter(w) _, _, err := ww.Hijack() - ztesting.AssertEqual(t, "hijack should be error", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) } @@ -129,7 +129,7 @@ func TestResponseWrapper_Flush(t *testing.T) { ww := zhttp.WrapResponseWriter(w) ww.Flush() ww.Flush() - ztesting.AssertEqual(t, "flush was not called", true, w.called) + ztesting.AssertEqual(t, true, w.called) }) t.Run("flush error", func(t *testing.T) { w := &testFlushErrorResponse{ @@ -138,7 +138,7 @@ func TestResponseWrapper_Flush(t *testing.T) { ww := zhttp.WrapResponseWriter(w) ww.Flush() ww.Flush() - ztesting.AssertEqual(t, "flush was not called", true, w.called) + ztesting.AssertEqual(t, true, w.called) }) t.Run("flush after unwrap", func(t *testing.T) { inner := &testFlushResponse{ @@ -150,6 +150,6 @@ func TestResponseWrapper_Flush(t *testing.T) { ww := zhttp.WrapResponseWriter(w) ww.Flush() ww.Flush() - ztesting.AssertEqual(t, "flush was not called", true, inner.called) + ztesting.AssertEqual(t, true, inner.called) }) } diff --git a/znet/zhttp/runner_test.go b/znet/zhttp/runner_test.go index 2333e40..88cbc11 100644 --- a/znet/zhttp/runner_test.go +++ b/znet/zhttp/runner_test.go @@ -19,7 +19,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("serve error", func(t *testing.T) { t.Run("already closed", func(t *testing.T) { @@ -28,7 +28,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", http.ErrServerClosed, err) + ztesting.AssertEqualErr(t, http.ErrServerClosed, err) }) t.Run("non-nil error", func(t *testing.T) { testErr := errors.New("serve error") @@ -37,7 +37,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", testErr, err) + ztesting.AssertEqualErr(t, testErr, err) }) }) t.Run("shutdown error", func(t *testing.T) { @@ -52,8 +52,8 @@ func TestServerRunner(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() err := r.Run(ctx) - ztesting.AssertEqualErr(t, "error not match", context.DeadlineExceeded, err) - ztesting.AssertEqual(t, "close is not called", true, closeCalled) + ztesting.AssertEqualErr(t, context.DeadlineExceeded, err) + ztesting.AssertEqual(t, true, closeCalled) }) t.Run("non-nil error", func(t *testing.T) { testErr := errors.New("shutdown error") @@ -66,8 +66,8 @@ func TestServerRunner(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() err := r.Run(ctx) - ztesting.AssertEqualErr(t, "error not match", testErr, err) - ztesting.AssertEqual(t, "close is called", false, closeCalled) + ztesting.AssertEqualErr(t, testErr, err) + ztesting.AssertEqual(t, false, closeCalled) }) }) } diff --git a/znet/ztcp/proxy_test.go b/znet/ztcp/proxy_test.go index 6ae6204..625955e 100644 --- a/znet/ztcp/proxy_test.go +++ b/znet/ztcp/proxy_test.go @@ -21,13 +21,13 @@ func TestNewProxy(t *testing.T) { t.Run("no targets", func(t *testing.T) { defer func() { r := recover() - ztesting.AssertEqual(t, "recovered value not match", r.(error), ErrNoTarget) + ztesting.AssertEqual(t, r.(error), ErrNoTarget) }() _ = NewProxy() }) t.Run("with targets", func(t *testing.T) { p := NewProxy("foo", "bar") - ztesting.AssertEqual(t, "dialer is nil", true, p.Dial != nil) + ztesting.AssertEqual(t, true, p.Dial != nil) }) } @@ -43,21 +43,21 @@ func TestRoundRobinDialer(t *testing.T) { got = append(got, rrd.next()) } want := []string{"addr1", "addr2", "addr3", "addr1", "addr2", "addr3"} - ztesting.AssertEqual(t, "address not match", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("invalid tcp address", func(t *testing.T) { rrd := &roundRobinDialer{addrs: []string{"tcp://12345"}} conn, err := rrd.dial(context.Background(), nil) - ztesting.AssertEqual(t, "conn should be nil", nil, conn) + ztesting.AssertEqual(t, nil, conn) _, ok := err.(*net.AddrError) - ztesting.AssertEqual(t, "error should be addr error", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("dial tcp", func(t *testing.T) { ln, _ := net.Listen("tcp4", ":0") defer ln.Close() rrd := &roundRobinDialer{addrs: []string{"tcp4://" + ln.Addr().String()}} conn, err := rrd.dial(context.Background(), nil) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) _ = conn.Close() }) t.Run("dial unix", func(t *testing.T) { @@ -66,7 +66,7 @@ func TestRoundRobinDialer(t *testing.T) { defer ln.Close() rrd := &roundRobinDialer{addrs: []string{"unix://" + s}} conn, err := rrd.dial(context.Background(), nil) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) _ = conn.Close() }) t.Run("dial fallback", func(t *testing.T) { @@ -74,7 +74,7 @@ func TestRoundRobinDialer(t *testing.T) { defer ln.Close() rrd := &roundRobinDialer{addrs: []string{ln.Addr().String()}} conn, err := rrd.dial(context.Background(), nil) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) _ = conn.Close() }) } @@ -91,8 +91,8 @@ func TestProxy_handleError(t *testing.T) { }, } p.handleError(nil, nil, io.EOF) - ztesting.AssertEqual(t, "handler not called", true, called) - ztesting.AssertEqualErr(t, "error not match", io.EOF, got) + ztesting.AssertEqual(t, true, called) + ztesting.AssertEqualErr(t, io.EOF, got) }) t.Run("handle nil", func(t *testing.T) { var got error @@ -104,8 +104,8 @@ func TestProxy_handleError(t *testing.T) { }, } p.handleError(nil, nil, nil) - ztesting.AssertEqual(t, "handler called", false, called) - ztesting.AssertEqualErr(t, "error not match", nil, got) + ztesting.AssertEqual(t, false, called) + ztesting.AssertEqualErr(t, nil, got) }) } @@ -150,11 +150,11 @@ func TestProxy(t *testing.T) { ErrorHandler: func(dc, uc net.Conn, err error) { handledErr = err }, } p.ServeTCP(context.Background(), dConn) - ztesting.AssertEqual(t, "upstream data was not written", "upstream data", dWriter.String()) - ztesting.AssertEqual(t, "downstream data was not written", "downstream data", uWriter.String()) - ztesting.AssertEqual(t, "upstream conn was not closed", true, uConn.closed) - ztesting.AssertEqual(t, "downstream conn was closed", false, dConn.closed) - ztesting.AssertEqualErr(t, "error not match", nil, handledErr) + ztesting.AssertEqual(t, "upstream data", dWriter.String()) + ztesting.AssertEqual(t, "downstream data", uWriter.String()) + ztesting.AssertEqual(t, true, uConn.closed) + ztesting.AssertEqual(t, false, dConn.closed) + ztesting.AssertEqualErr(t, nil, handledErr) }) t.Run("dial error", func(t *testing.T) { var handledErr error @@ -165,7 +165,7 @@ func TestProxy(t *testing.T) { ErrorHandler: func(dc, uc net.Conn, err error) { handledErr = err }, } p.ServeTCP(context.Background(), nil) - ztesting.AssertEqualErr(t, "error not match", net.ErrClosed, handledErr) + ztesting.AssertEqualErr(t, net.ErrClosed, handledErr) }) t.Run("downstream read error", func(t *testing.T) { dWriter := bytes.NewBuffer(nil) @@ -189,11 +189,11 @@ func TestProxy(t *testing.T) { for dWriter.Len() == 0 || uWriter.Len() == 0 { time.Sleep(100 * time.Millisecond) // Wait both written. } - ztesting.AssertEqual(t, "upstream data was not written", "upstream data", dWriter.String()) - ztesting.AssertEqual(t, "downstream data was not written", "downstream", uWriter.String()) - ztesting.AssertEqual(t, "upstream conn was not closed", true, uConn.closed) - ztesting.AssertEqual(t, "downstream conn was closed", false, dConn.closed) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, handledErr) + ztesting.AssertEqual(t, "upstream data", dWriter.String()) + ztesting.AssertEqual(t, "downstream", uWriter.String()) + ztesting.AssertEqual(t, true, uConn.closed) + ztesting.AssertEqual(t, false, dConn.closed) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, handledErr) }) t.Run("upstream read error", func(t *testing.T) { dWriter := bytes.NewBuffer(nil) @@ -217,10 +217,10 @@ func TestProxy(t *testing.T) { for dWriter.Len() == 0 || uWriter.Len() == 0 { time.Sleep(100 * time.Millisecond) // Wait both written. } - ztesting.AssertEqual(t, "upstream data was not written", "upstream", dWriter.String()) - ztesting.AssertEqual(t, "downstream data was not written", "downstream data", uWriter.String()) - ztesting.AssertEqual(t, "upstream conn was not closed", true, uConn.closed) - ztesting.AssertEqual(t, "downstream conn was closed", false, dConn.closed) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, handledErr) + ztesting.AssertEqual(t, "upstream", dWriter.String()) + ztesting.AssertEqual(t, "downstream data", uWriter.String()) + ztesting.AssertEqual(t, true, uConn.closed) + ztesting.AssertEqual(t, false, dConn.closed) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, handledErr) }) } diff --git a/znet/ztcp/runner_test.go b/znet/ztcp/runner_test.go index 1c71962..d015df8 100644 --- a/znet/ztcp/runner_test.go +++ b/znet/ztcp/runner_test.go @@ -19,7 +19,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("serve error", func(t *testing.T) { t.Run("already closed", func(t *testing.T) { @@ -28,7 +28,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", net.ErrClosed, err) + ztesting.AssertEqualErr(t, net.ErrClosed, err) }) t.Run("non-nil error", func(t *testing.T) { testErr := errors.New("serve error") @@ -37,7 +37,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", testErr, err) + ztesting.AssertEqualErr(t, testErr, err) }) }) t.Run("shutdown error", func(t *testing.T) { @@ -52,8 +52,8 @@ func TestServerRunner(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() err := r.Run(ctx) - ztesting.AssertEqualErr(t, "error not match", context.DeadlineExceeded, err) - ztesting.AssertEqual(t, "close is not called", true, closeCalled) + ztesting.AssertEqualErr(t, context.DeadlineExceeded, err) + ztesting.AssertEqual(t, true, closeCalled) }) t.Run("non-nil error", func(t *testing.T) { testErr := errors.New("shutdown error") @@ -66,8 +66,8 @@ func TestServerRunner(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() err := r.Run(ctx) - ztesting.AssertEqualErr(t, "error not match", testErr, err) - ztesting.AssertEqual(t, "close is called", false, closeCalled) + ztesting.AssertEqualErr(t, testErr, err) + ztesting.AssertEqual(t, false, closeCalled) }) }) } diff --git a/znet/ztcp/server_test.go b/znet/ztcp/server_test.go index 76d9b65..6bbd2f1 100644 --- a/znet/ztcp/server_test.go +++ b/znet/ztcp/server_test.go @@ -21,13 +21,13 @@ func TestServer_ListenAndServe(t *testing.T) { s := &Server{} s.Shutdown(context.Background()) err := s.ListenAndServe() - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("create listener error", func(t *testing.T) { s := &Server{Addr: "tcp4://1234567890"} err := s.ListenAndServe() _, ok := err.(*net.AddrError) - ztesting.AssertEqual(t, "addr error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("listen success", func(t *testing.T) { served := make(chan struct{}) @@ -42,9 +42,9 @@ func TestServer_ListenAndServe(t *testing.T) { shutdown <- s.Shutdown(context.Background()) }() err := s.ListenAndServe() - ztesting.AssertEqualErr(t, "serve error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) err = <-shutdown - ztesting.AssertEqualErr(t, "shutdown error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) } @@ -54,13 +54,13 @@ func TestServer_ListenAndServeTLS(t *testing.T) { s := &Server{} s.Shutdown(context.Background()) err := s.ListenAndServeTLS("", "") - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("create listener error", func(t *testing.T) { s := &Server{Addr: "tcp4://1234567890"} err := s.ListenAndServeTLS("", "") _, ok := err.(*net.AddrError) - ztesting.AssertEqual(t, "addr error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("listen success", func(t *testing.T) { // Obtain available address. @@ -75,12 +75,12 @@ func TestServer_ListenAndServeTLS(t *testing.T) { go func() { <-served cn, err := net.Dial("tcp4", ln.Addr().String()) - ztesting.AssertEqual(t, "dial failed", nil, err) + ztesting.AssertEqual(t, nil, err) cn.Close() s.Close() }() err := s.ListenAndServeTLS("./testdata/cert.pem", "./testdata/key.pem") - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) } @@ -90,13 +90,13 @@ func TestServer_ServeTLS(t *testing.T) { s := &Server{} s.Shutdown(context.Background()) err := s.ServeTLS(nil, "", "") - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("read cert error", func(t *testing.T) { s := &Server{} err := s.ServeTLS(nil, "./testdata/not-found.pem", "./testdata/key.pem") _, ok := err.(*fs.PathError) - ztesting.AssertEqual(t, "path error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("non-nil config", func(t *testing.T) { ln, _ := net.Listen("tcp4", ":0") // Obtain available address. @@ -109,12 +109,12 @@ func TestServer_ServeTLS(t *testing.T) { go func() { <-served conn, err := net.Dial("tcp4", ln.Addr().String()) - ztesting.AssertEqual(t, "dial failed", nil, err) + ztesting.AssertEqual(t, nil, err) conn.Close() s.Close() }() err := s.ServeTLS(ln, "./testdata/cert.pem", "./testdata/key.pem") - ztesting.AssertEqual(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqual(t, ErrServerClosed, err) }) } @@ -174,13 +174,13 @@ func TestServer_Serve(t *testing.T) { s := &Server{} s.Shutdown(context.Background()) err := s.Serve(nil) - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("create listener error", func(t *testing.T) { s := &Server{Addr: "tcp4://1234567890"} err := s.ListenAndServe() _, ok := err.(*net.AddrError) - ztesting.AssertEqual(t, "addr error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("serve success", func(t *testing.T) { baseCtx := context.Background() @@ -190,9 +190,9 @@ func TestServer_Serve(t *testing.T) { s := &Server{ BaseContext: func(l net.Listener) context.Context { return baseCtx }, Handler: HandlerFunc(func(ctx context.Context, conn net.Conn) { - ztesting.AssertEqual(t, "context not match", baseCtx, ctx) + ztesting.AssertEqual(t, baseCtx, ctx) got := conn.(*ocConn).Conn - ztesting.AssertEqual(t, "connection not match", net.Conn(cn), got) + ztesting.AssertEqual(t, net.Conn(cn), got) checked <- struct{}{} }), } @@ -201,7 +201,7 @@ func TestServer_Serve(t *testing.T) { s.Close() }() err := s.Serve(ln) - ztesting.AssertEqual(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqual(t, ErrServerClosed, err) }) t.Run("skip serving", func(t *testing.T) { cn := &testConn{Conn: &net.TCPConn{}} @@ -214,11 +214,11 @@ func TestServer_Serve(t *testing.T) { for cn.closed == 0 { time.Sleep(10 * time.Millisecond) } - ztesting.AssertEqual(t, "handler should not be called", 0, count) + ztesting.AssertEqual(t, 0, count) s.Close() }() err := s.Serve(ln) - ztesting.AssertEqual(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqual(t, ErrServerClosed, err) }) t.Run("timeout error", func(t *testing.T) { cn := &testConn{Conn: &net.TCPConn{}} @@ -231,11 +231,11 @@ func TestServer_Serve(t *testing.T) { for ln.accept <= 2 { time.Sleep(10 * time.Millisecond) } - ztesting.AssertEqual(t, "handler should not be called", 0, count) + ztesting.AssertEqual(t, 0, count) s.Close() }() err := s.Serve(ln) - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("non-timeout error", func(t *testing.T) { cn := &testConn{Conn: &net.TCPConn{}} @@ -248,11 +248,11 @@ func TestServer_Serve(t *testing.T) { for ln.accept <= 2 { time.Sleep(10 * time.Millisecond) } - ztesting.AssertEqual(t, "handler should not be called", 0, count) + ztesting.AssertEqual(t, 0, count) s.Close() }() err := s.Serve(ln) - ztesting.AssertEqualErr(t, "error not match", timeoutError(false), err) + ztesting.AssertEqualErr(t, timeoutError(false), err) }) t.Run("panic error", func(t *testing.T) { cn := &testConn{Conn: &net.TCPConn{}} @@ -269,8 +269,8 @@ func TestServer_Serve(t *testing.T) { s.Close() }() err := s.Serve(ln) - ztesting.AssertEqualErr(t, "serve error not match", ErrServerClosed, err) - ztesting.AssertEqual(t, "listener not closed", 1, ln.closed) + ztesting.AssertEqualErr(t, ErrServerClosed, err) + ztesting.AssertEqual(t, 1, ln.closed) }) t.Run("panic with handler", func(t *testing.T) { cn := &testConn{Conn: &net.TCPConn{}} @@ -286,12 +286,12 @@ func TestServer_Serve(t *testing.T) { } go func() { err := <-panicked - ztesting.AssertEqualErr(t, "error not match", net.ErrWriteToConnected, err) + ztesting.AssertEqualErr(t, net.ErrWriteToConnected, err) s.Close() }() err := s.Serve(ln) - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) - ztesting.AssertEqual(t, "listener not closed", 1, ln.closed) + ztesting.AssertEqualErr(t, ErrServerClosed, err) + ztesting.AssertEqual(t, 1, ln.closed) }) } @@ -307,11 +307,11 @@ func TestServer_Close(t *testing.T) { s.listeners.Store(&ocListener{Listener: ln}) s.conns.Store(&ocConn{Conn: &net.TCPConn{}}) - ztesting.AssertEqual(t, "listeners length not match", 1, s.listeners.Length()) - ztesting.AssertEqual(t, "conns length not match", 1, s.conns.Length()) + ztesting.AssertEqual(t, 1, s.listeners.Length()) + ztesting.AssertEqual(t, 1, s.conns.Length()) s.Close() - ztesting.AssertEqual(t, "listeners length not match", 0, s.listeners.Length()) - ztesting.AssertEqual(t, "conns length not match", 0, s.conns.Length()) + ztesting.AssertEqual(t, 0, s.listeners.Length()) + ztesting.AssertEqual(t, 0, s.conns.Length()) } func TestServer_Shutdown(t *testing.T) { @@ -320,7 +320,7 @@ func TestServer_Shutdown(t *testing.T) { s := &Server{} s.Shutdown(context.Background()) err := s.Shutdown(context.Background()) - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("shutdown success", func(t *testing.T) { served := make(chan struct{}) @@ -331,13 +331,13 @@ func TestServer_Shutdown(t *testing.T) { go func() { <-served err := s.Shutdown(context.Background()) - ztesting.AssertEqual(t, "error not match", nil, err) + ztesting.AssertEqual(t, nil, err) }() err := s.ListenAndServe() - ztesting.AssertEqual(t, "error not match", ErrServerClosed, err) - ztesting.AssertEqual(t, "listeners length not match", 0, s.listeners.Length()) - ztesting.AssertEqual(t, "conns length not match", 0, s.conns.Length()) - ztesting.AssertEqual(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqual(t, ErrServerClosed, err) + ztesting.AssertEqual(t, 0, s.listeners.Length()) + ztesting.AssertEqual(t, 0, s.conns.Length()) + ztesting.AssertEqual(t, ErrServerClosed, err) }) t.Run("shutdown context done", func(t *testing.T) { served := make(chan struct{}) @@ -359,14 +359,14 @@ func TestServer_Shutdown(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() err := s.Shutdown(ctx) - ztesting.AssertEqual(t, "error not match", context.DeadlineExceeded, err) + ztesting.AssertEqual(t, context.DeadlineExceeded, err) shutdown <- struct{}{} }() err := s.Serve(ln) <-shutdown - ztesting.AssertEqual(t, "listeners length not match", 0, s.listeners.Length()) - ztesting.AssertEqual(t, "conns length not match", 1, s.conns.Length()) // Conn is yet alive. - ztesting.AssertEqual(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqual(t, 0, s.listeners.Length()) + ztesting.AssertEqual(t, 1, s.conns.Length()) // Conn is yet alive. + ztesting.AssertEqual(t, ErrServerClosed, err) }) } @@ -374,41 +374,41 @@ func TestNewListener(t *testing.T) { t.Parallel() t.Run("listen tcp without prefix", func(t *testing.T) { ln, err := newListener(":0") - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) defer ln.Close() cn, err := net.Dial("tcp", ln.Addr().String()) - ztesting.AssertEqual(t, "dial failed", nil, err) + ztesting.AssertEqual(t, nil, err) cn.Close() }) t.Run("listen tcp4 success", func(t *testing.T) { ln, err := newListener("tcp4://:0") - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) defer ln.Close() cn, err := net.Dial("tcp4", ln.Addr().String()) - ztesting.AssertEqual(t, "dial failed", nil, err) + ztesting.AssertEqual(t, nil, err) cn.Close() }) t.Run("listen tcp4 failed", func(t *testing.T) { _, err := newListener("tcp4://1234567890") _, ok := err.(*net.AddrError) - ztesting.AssertEqual(t, "addr error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("listen unix success", func(t *testing.T) { s := filepath.Join(os.TempDir(), "TestNewListener_test.sock") // Socket path must not be too long. ln, err := newListener("unix://" + s) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) cn, err := net.Dial("unix", s) - ztesting.AssertEqual(t, "dial failed", nil, err) + ztesting.AssertEqual(t, nil, err) cn.Close() ln.Close() // Socket file should be removed. _, err = os.Stat(s) // Check socket file removed - ztesting.AssertEqual(t, "socket not removed", true, os.IsNotExist(err)) + ztesting.AssertEqual(t, true, os.IsNotExist(err)) }) t.Run("fallback to tcp", func(t *testing.T) { _, err := newListener("udp://1234567890") _, ok := err.(*net.OpError) t.Logf("%#v\n", err) - ztesting.AssertEqual(t, "net op error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) } @@ -445,30 +445,30 @@ func TestOCListener(t *testing.T) { ncl := &nopCloseListener{addr: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12345}} ln := &ocListener{Listener: ncl} err := ln.Close() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, ncl.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, ncl.count) }) t.Run("close multiple", func(t *testing.T) { ncl := &nopCloseListener{addr: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12345}} ln := &ocListener{Listener: ncl} _ = ln.Close() // close once err := ln.Close() // close twice - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, ncl.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, ncl.count) }) t.Run("close error", func(t *testing.T) { ncl := &nopCloseListener{addr: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12345}, err: io.EOF} ln := &ocListener{Listener: ncl} err := ln.Close() - ztesting.AssertEqualErr(t, "close error not match", io.EOF, err) - ztesting.AssertEqual(t, "close count not match", 1, ncl.count) + ztesting.AssertEqualErr(t, io.EOF, err) + ztesting.AssertEqual(t, 1, ncl.count) }) t.Run("close abstract socket", func(t *testing.T) { ncl := &nopCloseListener{addr: &net.UnixAddr{Net: "unix", Name: "@test"}} ln := &ocListener{Listener: ncl} err := ln.Close() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, ncl.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, ncl.count) }) t.Run("close path name socket", func(t *testing.T) { sock := t.TempDir() + "/test.sock" @@ -477,10 +477,10 @@ func TestOCListener(t *testing.T) { ncl := &nopCloseListener{addr: &net.UnixAddr{Net: "unix", Name: sock}} ln := &ocListener{Listener: ncl} err := ln.Close() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, ncl.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, ncl.count) _, err = os.Stat(sock) // Socket must be removed. - ztesting.AssertEqual(t, "socket not removed", true, os.IsNotExist(err)) + ztesting.AssertEqual(t, true, os.IsNotExist(err)) }) } @@ -490,22 +490,22 @@ func TestOCConn(t *testing.T) { nc := &nopCloseConn{} conn := &ocConn{Conn: nc} err := conn.Close() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, nc.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, nc.count) }) t.Run("close multiple", func(t *testing.T) { nc := &nopCloseConn{} conn := &ocConn{Conn: nc} _ = conn.Close() // close once err := conn.Close() // close twice - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close called more than once", 1, nc.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, nc.count) }) t.Run("close error", func(t *testing.T) { nc := &nopCloseConn{err: io.EOF} conn := &ocConn{Conn: nc} err := conn.Close() - ztesting.AssertEqualErr(t, "close error not match", io.EOF, err) - ztesting.AssertEqual(t, "close count not match", 1, nc.count) + ztesting.AssertEqualErr(t, io.EOF, err) + ztesting.AssertEqual(t, 1, nc.count) }) } diff --git a/znet/zudp/conn_test.go b/znet/zudp/conn_test.go index 0c2f9db..09c3128 100644 --- a/znet/zudp/conn_test.go +++ b/znet/zudp/conn_test.go @@ -19,16 +19,16 @@ func TestConn_Read(t *testing.T) { pc: pc, packets: packets, } - ztesting.AssertEqual(t, "local addr not match", pc.LocalAddr(), c.LocalAddr()) + ztesting.AssertEqual(t, pc.LocalAddr(), c.LocalAddr()) go func() { packets <- []byte("test") }() buf := make([]byte, 10) n, err := c.Read(buf) - ztesting.AssertEqual(t, "num packet not match", 4, n) - ztesting.AssertEqual(t, "packet content not match", "test", string(buf[:n])) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 4, n) + ztesting.AssertEqual(t, "test", string(buf[:n])) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("read from closed conn", func(t *testing.T) { packets := make(chan []byte, 1) @@ -39,7 +39,7 @@ func TestConn_Read(t *testing.T) { channels: &sync.Map{}, raddr: raddr, } - ztesting.AssertEqual(t, "local addr not match", pc.LocalAddr(), c.LocalAddr()) + ztesting.AssertEqual(t, pc.LocalAddr(), c.LocalAddr()) c.Close() go func() { @@ -47,9 +47,9 @@ func TestConn_Read(t *testing.T) { }() buf := make([]byte, 10) n, err := c.Read(buf) - ztesting.AssertEqual(t, "num packet not match", 0, n) - ztesting.AssertEqual(t, "packet content not match", "", string(buf[:n])) - ztesting.AssertEqualErr(t, "error not match", net.ErrClosed, err) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, "", string(buf[:n])) + ztesting.AssertEqualErr(t, net.ErrClosed, err) }) } @@ -80,13 +80,13 @@ func TestConn_Write(t *testing.T) { packets: packets, raddr: raddr, } - ztesting.AssertEqual(t, "remote addr not match", raddr.String(), c.RemoteAddr().String()) + ztesting.AssertEqual(t, raddr.String(), c.RemoteAddr().String()) n, err := c.Write([]byte("test")) - ztesting.AssertEqual(t, "num packet not match", 4, n) - ztesting.AssertEqualErr(t, "error not match", nil, err) - ztesting.AssertEqual(t, "packet content not match", "test", string(rpc.written)) - ztesting.AssertEqual(t, "written address not match", raddr.String(), rpc.raddr.String()) + ztesting.AssertEqual(t, 4, n) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, "test", string(rpc.written)) + ztesting.AssertEqual(t, raddr.String(), rpc.raddr.String()) }) t.Run("write to closed conn", func(t *testing.T) { packets := make(chan []byte, 1) @@ -98,16 +98,16 @@ func TestConn_Write(t *testing.T) { channels: &sync.Map{}, raddr: raddr, } - ztesting.AssertEqual(t, "remote addr not match", raddr.String(), c.RemoteAddr().String()) + ztesting.AssertEqual(t, raddr.String(), c.RemoteAddr().String()) c.Close() go func() { packets <- []byte("test") }() n, err := c.Write([]byte("test")) - ztesting.AssertEqual(t, "num packet not match", 0, n) - ztesting.AssertEqual(t, "packet content not match", "", string(rpc.written)) - ztesting.AssertEqualErr(t, "error not match", net.ErrClosed, err) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, "", string(rpc.written)) + ztesting.AssertEqualErr(t, net.ErrClosed, err) }) } @@ -122,10 +122,10 @@ func TestConn_Close(t *testing.T) { } channels.Store(addr.String(), "test") _, ok := channels.Load(addr.String()) - ztesting.AssertEqual(t, "value not found", true, ok) + ztesting.AssertEqual(t, true, ok) c.Close() _, ok = channels.Load(addr.String()) - ztesting.AssertEqual(t, "value unexpectedly found", false, ok) + ztesting.AssertEqual(t, false, ok) }) t.Run("close multiple times", func(t *testing.T) { channels := &sync.Map{} @@ -136,14 +136,14 @@ func TestConn_Close(t *testing.T) { } channels.Store(addr.String(), "test") _, ok := channels.Load(addr.String()) - ztesting.AssertEqual(t, "value not found", true, ok) + ztesting.AssertEqual(t, true, ok) c.Close() _, ok = channels.Load(addr.String()) - ztesting.AssertEqual(t, "key found", false, ok) + ztesting.AssertEqual(t, false, ok) channels.Store(addr.String(), "test") // Store value again. c.Close() // Value should not be removed. _, ok = channels.Load(addr.String()) - ztesting.AssertEqual(t, "value not found", true, ok) + ztesting.AssertEqual(t, true, ok) }) } diff --git a/znet/zudp/proxy_test.go b/znet/zudp/proxy_test.go index 15c1796..14ccb96 100644 --- a/znet/zudp/proxy_test.go +++ b/znet/zudp/proxy_test.go @@ -22,13 +22,13 @@ func TestNewProxy(t *testing.T) { t.Run("no targets", func(t *testing.T) { defer func() { r := recover() - ztesting.AssertEqual(t, "recovered value not match", r.(error), ErrNoTarget) + ztesting.AssertEqual(t, r.(error), ErrNoTarget) }() NewProxy() }) t.Run("with targets", func(t *testing.T) { p := NewProxy("foo", "bar") - ztesting.AssertEqual(t, "dialer is nil", true, p.Dial != nil) + ztesting.AssertEqual(t, true, p.Dial != nil) }) } @@ -44,21 +44,21 @@ func TestRoundRobinDialer(t *testing.T) { got = append(got, rrd.next()) } want := []string{"addr1", "addr2", "addr3", "addr1", "addr2", "addr3"} - ztesting.AssertEqual(t, "address not match", want, got) + ztesting.AssertEqual(t, want, got) }) t.Run("invalid udp address", func(t *testing.T) { rrd := &roundRobinDialer{addrs: []string{"udp://12345"}} conn, err := rrd.dial(context.Background(), nil) - ztesting.AssertEqual(t, "conn should be nil", nil, conn) + ztesting.AssertEqual(t, nil, conn) _, ok := err.(*net.AddrError) - ztesting.AssertEqual(t, "error should be addr error", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("dial udp", func(t *testing.T) { pc, _ := net.ListenPacket("udp4", ":0") defer pc.Close() rrd := &roundRobinDialer{addrs: []string{"udp4://" + pc.LocalAddr().String()}} conn, err := rrd.dial(context.Background(), nil) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) conn.Close() }) t.Run("dial unix", func(t *testing.T) { @@ -67,14 +67,14 @@ func TestRoundRobinDialer(t *testing.T) { rrd := &roundRobinDialer{addrs: []string{"unixgram://" + s}} _, err := rrd.dial(context.Background(), nil) _, ok := err.(*net.OpError) - ztesting.AssertEqual(t, "error should be net op error", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("dial fallback", func(t *testing.T) { pc, _ := net.ListenPacket("udp", ":0") defer pc.Close() rrd := &roundRobinDialer{addrs: []string{pc.LocalAddr().String()}} conn, err := rrd.dial(context.Background(), nil) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) conn.Close() }) } @@ -91,8 +91,8 @@ func TestProxy_handleError(t *testing.T) { }, } p.handleError(nil, nil, io.EOF) - ztesting.AssertEqual(t, "handler not called", true, called) - ztesting.AssertEqualErr(t, "error not match", io.EOF, got) + ztesting.AssertEqual(t, true, called) + ztesting.AssertEqualErr(t, io.EOF, got) }) t.Run("handle nil", func(t *testing.T) { var got error @@ -104,8 +104,8 @@ func TestProxy_handleError(t *testing.T) { }, } p.handleError(nil, nil, nil) - ztesting.AssertEqual(t, "handler called", false, called) - ztesting.AssertEqualErr(t, "error not match", nil, got) + ztesting.AssertEqual(t, false, called) + ztesting.AssertEqualErr(t, nil, got) }) } @@ -166,11 +166,11 @@ func TestProxy(t *testing.T) { for dWriter.Len() == 0 || uWriter.Len() == 0 { time.Sleep(100 * time.Millisecond) // Wait both written. } - ztesting.AssertEqual(t, "upstream data was not written", "upstream data", dWriter.String()) - ztesting.AssertEqual(t, "downstream data was not written", "downstream data", uWriter.String()) - ztesting.AssertEqual(t, "upstream conn was not closed", true, uConn.closed) - ztesting.AssertEqual(t, "downstream conn was closed", false, dConn.closed) - ztesting.AssertEqualErr(t, "error not match", nil, handledErr) + ztesting.AssertEqual(t, "upstream data", dWriter.String()) + ztesting.AssertEqual(t, "downstream data", uWriter.String()) + ztesting.AssertEqual(t, true, uConn.closed) + ztesting.AssertEqual(t, false, dConn.closed) + ztesting.AssertEqualErr(t, nil, handledErr) }) t.Run("dial error", func(t *testing.T) { var handledErr error @@ -181,7 +181,7 @@ func TestProxy(t *testing.T) { ErrorHandler: func(dc Conn, uc net.Conn, err error) { handledErr = err }, } p.ServeUDP(context.Background(), nil) - ztesting.AssertEqualErr(t, "error not match", net.ErrClosed, handledErr) + ztesting.AssertEqualErr(t, net.ErrClosed, handledErr) }) t.Run("read error", func(t *testing.T) { dWriter := bytes.NewBuffer(nil) @@ -205,11 +205,11 @@ func TestProxy(t *testing.T) { for dWriter.Len() == 0 || uWriter.Len() == 0 { time.Sleep(100 * time.Millisecond) // Wait both written. } - ztesting.AssertEqual(t, "upstream data was not written", "upstream", dWriter.String()) - ztesting.AssertEqual(t, "downstream data was not written", "downstream", uWriter.String()) - ztesting.AssertEqual(t, "upstream conn was not closed", true, uConn.closed) - ztesting.AssertEqual(t, "downstream conn was closed", false, dConn.closed) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, handledErr) + ztesting.AssertEqual(t, "upstream", dWriter.String()) + ztesting.AssertEqual(t, "downstream", uWriter.String()) + ztesting.AssertEqual(t, true, uConn.closed) + ztesting.AssertEqual(t, false, dConn.closed) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, handledErr) }) t.Run("short write", func(t *testing.T) { dWriter := bytes.NewBuffer(nil) @@ -233,11 +233,11 @@ func TestProxy(t *testing.T) { for dWriter.Len() == 0 || uWriter.Len() == 0 { time.Sleep(100 * time.Millisecond) // Wait both written. } - ztesting.AssertEqual(t, "upstream data was not written", "upstream", dWriter.String()) - ztesting.AssertEqual(t, "downstream data was not written", "downstream", uWriter.String()) - ztesting.AssertEqual(t, "upstream conn was not closed", true, uConn.closed) - ztesting.AssertEqual(t, "downstream conn was closed", false, dConn.closed) - ztesting.AssertEqualErr(t, "error not match", io.ErrClosedPipe, handledErr) + ztesting.AssertEqual(t, "upstream", dWriter.String()) + ztesting.AssertEqual(t, "downstream", uWriter.String()) + ztesting.AssertEqual(t, true, uConn.closed) + ztesting.AssertEqual(t, false, dConn.closed) + ztesting.AssertEqualErr(t, io.ErrClosedPipe, handledErr) }) t.Run("timeout", func(t *testing.T) { var eof atomic.Bool @@ -257,7 +257,7 @@ func TestProxy(t *testing.T) { } p.ServeUDP(context.Background(), dConn) eof.Store(true) // Close goroutine - ztesting.AssertEqual(t, "upstream conn was not closed", true, uConn.closed) - ztesting.AssertEqual(t, "downstream conn was closed", false, dConn.closed) + ztesting.AssertEqual(t, true, uConn.closed) + ztesting.AssertEqual(t, false, dConn.closed) }) } diff --git a/znet/zudp/runner_test.go b/znet/zudp/runner_test.go index 762f6f1..97bd289 100644 --- a/znet/zudp/runner_test.go +++ b/znet/zudp/runner_test.go @@ -19,7 +19,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("serve error", func(t *testing.T) { t.Run("already closed", func(t *testing.T) { @@ -28,7 +28,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", net.ErrClosed, err) + ztesting.AssertEqualErr(t, net.ErrClosed, err) }) t.Run("non-nil error", func(t *testing.T) { testErr := errors.New("serve error") @@ -37,7 +37,7 @@ func TestServerRunner(t *testing.T) { Shutdown: func(context.Context) error { return nil }, } err := r.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", testErr, err) + ztesting.AssertEqualErr(t, testErr, err) }) }) t.Run("shutdown error", func(t *testing.T) { @@ -52,8 +52,8 @@ func TestServerRunner(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() err := r.Run(ctx) - ztesting.AssertEqualErr(t, "error not match", context.DeadlineExceeded, err) - ztesting.AssertEqual(t, "close is not called", true, closeCalled) + ztesting.AssertEqualErr(t, context.DeadlineExceeded, err) + ztesting.AssertEqual(t, true, closeCalled) }) t.Run("non-nil error", func(t *testing.T) { testErr := errors.New("shutdown error") @@ -66,8 +66,8 @@ func TestServerRunner(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() err := r.Run(ctx) - ztesting.AssertEqualErr(t, "error not match", testErr, err) - ztesting.AssertEqual(t, "close is called", false, closeCalled) + ztesting.AssertEqualErr(t, testErr, err) + ztesting.AssertEqual(t, false, closeCalled) }) }) } diff --git a/znet/zudp/server_test.go b/znet/zudp/server_test.go index ea8a6c4..e64a16d 100644 --- a/znet/zudp/server_test.go +++ b/znet/zudp/server_test.go @@ -19,13 +19,13 @@ func TestServer_ListenAndServe(t *testing.T) { s := &Server{} s.Shutdown(context.Background()) err := s.ListenAndServe() - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("create listener error", func(t *testing.T) { s := &Server{Addr: "udp4://1234567890"} err := s.ListenAndServe() _, ok := err.(*net.AddrError) - ztesting.AssertEqual(t, "addr error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("listen success", func(t *testing.T) { served := make(chan struct{}) @@ -40,9 +40,9 @@ func TestServer_ListenAndServe(t *testing.T) { shutdwon <- s.Shutdown(context.Background()) }() err := s.ListenAndServe() - ztesting.AssertEqualErr(t, "serve error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) err = <-shutdwon - ztesting.AssertEqualErr(t, "shutdown error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) } @@ -91,13 +91,13 @@ func TestServer_Serve(t *testing.T) { s := &Server{} s.Shutdown(context.Background()) err := s.Serve(nil) - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("create listener error", func(t *testing.T) { s := &Server{Addr: "udp4://1234567890"} err := s.ListenAndServe() _, ok := err.(*net.AddrError) - ztesting.AssertEqual(t, "addr error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("serve success", func(t *testing.T) { baseCtx := context.Background() @@ -106,7 +106,7 @@ func TestServer_Serve(t *testing.T) { s := &Server{ BaseContext: func(_ net.PacketConn) context.Context { return baseCtx }, Handler: HandlerFunc(func(ctx context.Context, conn Conn) { - ztesting.AssertEqual(t, "context not match", baseCtx, ctx) + ztesting.AssertEqual(t, baseCtx, ctx) invoked <- struct{}{} }), } @@ -115,7 +115,7 @@ func TestServer_Serve(t *testing.T) { s.Close() }() err := s.Serve(ln) - ztesting.AssertEqual(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqual(t, ErrServerClosed, err) }) t.Run("skip serving", func(t *testing.T) { pc := &testPacketConn{PacketConn: dpc, raddr: &net.UDPAddr{}, readErr: ErrSkipHandler} @@ -127,11 +127,11 @@ func TestServer_Serve(t *testing.T) { for pc.accept <= 2 { time.Sleep(10 * time.Millisecond) } - ztesting.AssertEqual(t, "handler should not be called", 0, count) + ztesting.AssertEqual(t, 0, count) s.Close() }() err := s.Serve(pc) - ztesting.AssertEqual(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqual(t, ErrServerClosed, err) }) t.Run("timeout error", func(t *testing.T) { pc := &testPacketConn{PacketConn: dpc, raddr: &net.UDPAddr{}, readErr: timeoutError(true)} @@ -143,11 +143,11 @@ func TestServer_Serve(t *testing.T) { for pc.accept <= 2 { time.Sleep(10 * time.Millisecond) } - ztesting.AssertEqual(t, "read data should be proceeded", true, count > 0) + ztesting.AssertEqual(t, true, count > 0) s.Close() }() err := s.Serve(pc) - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("non-timeout error", func(t *testing.T) { pc := &testPacketConn{PacketConn: dpc, raddr: &net.UDPAddr{}, readErr: timeoutError(false)} @@ -159,11 +159,11 @@ func TestServer_Serve(t *testing.T) { for pc.accept <= 2 { time.Sleep(10 * time.Millisecond) } - ztesting.AssertEqual(t, "handler should not be called", 0, count) + ztesting.AssertEqual(t, 0, count) s.Close() }() err := s.Serve(pc) - ztesting.AssertEqualErr(t, "error not match", timeoutError(false), err) + ztesting.AssertEqualErr(t, timeoutError(false), err) }) t.Run("panic error", func(t *testing.T) { pc := &testPacketConn{PacketConn: dpc, raddr: &net.UDPAddr{}} @@ -179,8 +179,8 @@ func TestServer_Serve(t *testing.T) { s.Close() }() err := s.Serve(pc) - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) - ztesting.AssertEqual(t, "packet conn not closed", 1, pc.closed) + ztesting.AssertEqualErr(t, ErrServerClosed, err) + ztesting.AssertEqual(t, 1, pc.closed) }) t.Run("panic with handler", func(t *testing.T) { pc := &testPacketConn{PacketConn: dpc, raddr: &net.UDPAddr{}} @@ -195,12 +195,12 @@ func TestServer_Serve(t *testing.T) { } go func() { err := <-panicked - ztesting.AssertEqualErr(t, "error not match", net.ErrWriteToConnected, err) + ztesting.AssertEqualErr(t, net.ErrWriteToConnected, err) s.Close() }() err := s.Serve(pc) - ztesting.AssertEqualErr(t, "serve error not match", ErrServerClosed, err) - ztesting.AssertEqual(t, "packet conn not closed", 1, pc.closed) + ztesting.AssertEqualErr(t, ErrServerClosed, err) + ztesting.AssertEqual(t, 1, pc.closed) }) } @@ -216,11 +216,11 @@ func TestServer_Close(t *testing.T) { s.packetConns.Store(&ocPacketConn{PacketConn: pc}) s.conns.Store(&ocConn{Conn: &net.TCPConn{}}) - ztesting.AssertEqual(t, "packetConns length not match", 1, s.packetConns.Length()) - ztesting.AssertEqual(t, "conns length not match", 1, s.conns.Length()) + ztesting.AssertEqual(t, 1, s.packetConns.Length()) + ztesting.AssertEqual(t, 1, s.conns.Length()) s.Close() - ztesting.AssertEqual(t, "packetConns length not match", 0, s.packetConns.Length()) - ztesting.AssertEqual(t, "conns length not match", 0, s.conns.Length()) + ztesting.AssertEqual(t, 0, s.packetConns.Length()) + ztesting.AssertEqual(t, 0, s.conns.Length()) } func TestServer_Shutdown(t *testing.T) { @@ -229,7 +229,7 @@ func TestServer_Shutdown(t *testing.T) { s := &Server{} s.Shutdown(context.Background()) err := s.Shutdown(context.Background()) - ztesting.AssertEqualErr(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqualErr(t, ErrServerClosed, err) }) t.Run("shutdown success", func(t *testing.T) { pc, _ := net.ListenPacket("udp", ":0") @@ -248,11 +248,11 @@ func TestServer_Shutdown(t *testing.T) { shutdown <- s.Shutdown(context.Background()) }() err := s.Serve(pc) - ztesting.AssertEqual(t, "serve error not match", ErrServerClosed, err) + ztesting.AssertEqual(t, ErrServerClosed, err) err = <-shutdown - ztesting.AssertEqual(t, "shutdown error not match", nil, err) - ztesting.AssertEqual(t, "listeners length not match", 0, s.packetConns.Length()) - ztesting.AssertEqual(t, "conns length not match", 0, s.conns.Length()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, 0, s.packetConns.Length()) + ztesting.AssertEqual(t, 0, s.conns.Length()) }) t.Run("shutdown context done", func(t *testing.T) { handlerInvoked := make(chan struct{}) @@ -267,21 +267,21 @@ func TestServer_Shutdown(t *testing.T) { shutdown := make(chan struct{}) go func() { conn, err := net.DialUDP("udp", nil, pc.LocalAddr().(*net.UDPAddr)) - ztesting.AssertEqual(t, "error should be nil", nil, err) + ztesting.AssertEqual(t, nil, err) conn.Write([]byte("test")) defer conn.Close() <-handlerInvoked ctx, cancel := context.WithTimeout(context.Background(), 0) defer cancel() err = s.Shutdown(ctx) - ztesting.AssertEqual(t, "error not match", context.DeadlineExceeded, err) + ztesting.AssertEqual(t, context.DeadlineExceeded, err) shutdown <- struct{}{} }() err := s.Serve(pc) <-shutdown - ztesting.AssertEqual(t, "listeners length not match", 0, s.packetConns.Length()) - ztesting.AssertEqual(t, "conns length not match", 1, s.conns.Length()) // Conn is yet alive. - ztesting.AssertEqual(t, "error not match", ErrServerClosed, err) + ztesting.AssertEqual(t, 0, s.packetConns.Length()) + ztesting.AssertEqual(t, 1, s.conns.Length()) // Conn is yet alive. + ztesting.AssertEqual(t, ErrServerClosed, err) testDone <- struct{}{} }) } @@ -290,37 +290,37 @@ func TestNewPacketConn(t *testing.T) { t.Parallel() t.Run("udp without prefix", func(t *testing.T) { ln, err := newPacketConn(":0") - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) defer ln.Close() cn, err := net.Dial("udp", ln.LocalAddr().String()) - ztesting.AssertEqual(t, "dial failed", nil, err) + ztesting.AssertEqual(t, nil, err) cn.Close() }) t.Run("listen udp4 success", func(t *testing.T) { ln, err := newPacketConn("udp4://:0") - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) defer ln.Close() cn, err := net.Dial("udp4", ln.LocalAddr().String()) - ztesting.AssertEqual(t, "dial failed", nil, err) + ztesting.AssertEqual(t, nil, err) cn.Close() }) t.Run("listen udp4 failed", func(t *testing.T) { _, err := newPacketConn("udp4://1234567890") _, ok := err.(*net.AddrError) - ztesting.AssertEqual(t, "addr error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("listen unixgram", func(t *testing.T) { s := t.TempDir() + "/not-exist/test.sock" _, err := newPacketConn("unixgram://" + s) // Make error because windows not support it. _, ok := err.(*net.OpError) t.Logf("%#v\n", err) - ztesting.AssertEqual(t, "net op error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) t.Run("fallback to udp", func(t *testing.T) { _, err := newPacketConn("tcp://1234567890") _, ok := err.(*net.OpError) t.Logf("%#v\n", err) - ztesting.AssertEqual(t, "net op error should be returned", true, ok) + ztesting.AssertEqual(t, true, ok) }) } @@ -357,30 +357,30 @@ func TestOCPacketConn(t *testing.T) { ocp := &nopClosePacketConn{addr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12345}} pc := &ocPacketConn{PacketConn: ocp} err := pc.Close() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, ocp.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, ocp.count) }) t.Run("close multiple", func(t *testing.T) { ocp := &nopClosePacketConn{addr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12345}} pc := &ocPacketConn{PacketConn: ocp} _ = pc.Close() err := pc.Close() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, ocp.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, ocp.count) }) t.Run("close error", func(t *testing.T) { ocp := &nopClosePacketConn{addr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12345}, err: io.EOF} pc := &ocPacketConn{PacketConn: ocp} err := pc.Close() - ztesting.AssertEqualErr(t, "close error not match", io.EOF, err) - ztesting.AssertEqual(t, "close count not match", 1, ocp.count) + ztesting.AssertEqualErr(t, io.EOF, err) + ztesting.AssertEqual(t, 1, ocp.count) }) t.Run("close abstract socket", func(t *testing.T) { ocp := &nopClosePacketConn{addr: &net.UnixAddr{Net: "unixgram", Name: "@test"}} pc := &ocPacketConn{PacketConn: ocp} err := pc.Close() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, ocp.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, ocp.count) }) t.Run("close path name socket", func(t *testing.T) { sock := t.TempDir() + "/test.sock" @@ -389,10 +389,10 @@ func TestOCPacketConn(t *testing.T) { ocp := &nopClosePacketConn{addr: &net.UnixAddr{Net: "unixgram", Name: sock}} pc := &ocPacketConn{PacketConn: ocp} err := pc.Close() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, ocp.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, ocp.count) _, err = os.Stat(sock) // Socket must be removed. - ztesting.AssertEqual(t, "socket not removed", true, os.IsNotExist(err)) + ztesting.AssertEqual(t, true, os.IsNotExist(err)) }) } @@ -402,23 +402,23 @@ func TestOCConn(t *testing.T) { nc := &nopCloseConn{} conn := &ocConn{Conn: nc} err := conn.Close() - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close count not match", 1, nc.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, nc.count) }) t.Run("close multiple", func(t *testing.T) { nc := &nopCloseConn{} conn := &ocConn{Conn: nc} _ = conn.Close() // close once err := conn.Close() // close twice - ztesting.AssertEqualErr(t, "close error not match", nil, err) - ztesting.AssertEqual(t, "close called more than once", 1, nc.count) + ztesting.AssertEqualErr(t, nil, err) + ztesting.AssertEqual(t, 1, nc.count) }) t.Run("close error", func(t *testing.T) { nc := &nopCloseConn{err: io.EOF} conn := &ocConn{Conn: nc} err := conn.Close() - ztesting.AssertEqualErr(t, "close error not match", io.EOF, err) - ztesting.AssertEqual(t, "close count not match", 1, nc.count) + ztesting.AssertEqualErr(t, io.EOF, err) + ztesting.AssertEqual(t, 1, nc.count) }) } @@ -427,20 +427,20 @@ func TestGetChannel(t *testing.T) { t.Run("new channel", func(t *testing.T) { m := &sync.Map{} c, isNew := getChannel(m, "addr") - ztesting.AssertEqual(t, "channel is not new", true, isNew) - ztesting.AssertEqual(t, "channel length not match", 0, len(c)) - ztesting.AssertEqual(t, "channel capacity not match", 256, cap(c)) + ztesting.AssertEqual(t, true, isNew) + ztesting.AssertEqual(t, 0, len(c)) + ztesting.AssertEqual(t, 256, cap(c)) }) t.Run("existing channel", func(t *testing.T) { m := &sync.Map{} c, isNew := getChannel(m, "addr") - ztesting.AssertEqual(t, "channel is not new", true, isNew) + ztesting.AssertEqual(t, true, isNew) c <- []byte("1") c <- []byte("2") c <- []byte("3") c, isNew = getChannel(m, "addr") - ztesting.AssertEqual(t, "channel is new", false, isNew) - ztesting.AssertEqual(t, "channel length not match", 3, len(c)) - ztesting.AssertEqual(t, "channel capacity not match", 256, cap(c)) + ztesting.AssertEqual(t, false, isNew) + ztesting.AssertEqual(t, 3, len(c)) + ztesting.AssertEqual(t, 256, cap(c)) }) } diff --git a/zos/env_test.go b/zos/env_test.go index 64cab4e..a037b7a 100644 --- a/zos/env_test.go +++ b/zos/env_test.go @@ -11,14 +11,14 @@ func TestEnvSubst(t *testing.T) { t.Run("resolve all", func(t *testing.T) { txt := `${TestEnvSubst}` b, err := EnvSubst([]byte(txt)) - ztesting.AssertEqual(t, "value not match", "test", string(b)) - ztesting.AssertEqualErr(t, "error not nil", nil, err) + ztesting.AssertEqual(t, "test", string(b)) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("env error", func(t *testing.T) { txt := `${!TestEnvSubst}` b, err := EnvSubst([]byte(txt)) - ztesting.AssertEqual(t, "value not match", "", string(b)) - ztesting.AssertEqualErr(t, "error not match", &EnvError{Type: typeSyntax}, err) + ztesting.AssertEqual(t, "", string(b)) + ztesting.AssertEqualErr(t, &EnvError{Type: typeSyntax}, err) }) } @@ -28,20 +28,20 @@ func TestEnvSubst2(t *testing.T) { t.Run("resolve all", func(t *testing.T) { txt := `${${TestEnvSubst2_PTR}}` b, err := EnvSubst2([]byte(txt)) - ztesting.AssertEqual(t, "value not match", "test", string(b)) - ztesting.AssertEqualErr(t, "error not nil", nil, err) + ztesting.AssertEqual(t, "test", string(b)) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("inner env error", func(t *testing.T) { txt := `${${!TestEnvSubst2_PTR}}` b, err := EnvSubst2([]byte(txt)) - ztesting.AssertEqual(t, "value not match", "", string(b)) - ztesting.AssertEqualErr(t, "error not match", &EnvError{Type: typeSyntax}, err) + ztesting.AssertEqual(t, "", string(b)) + ztesting.AssertEqualErr(t, &EnvError{Type: typeSyntax}, err) }) t.Run("outer env error", func(t *testing.T) { txt := `${!${TestEnvSubst2_PTR}}` b, err := EnvSubst2([]byte(txt)) - ztesting.AssertEqual(t, "value not match", "", string(b)) - ztesting.AssertEqualErr(t, "error not match", &EnvError{Type: typeSyntax}, err) + ztesting.AssertEqual(t, "", string(b)) + ztesting.AssertEqualErr(t, &EnvError{Type: typeSyntax}, err) }) } @@ -87,8 +87,8 @@ func TestResolveEnv(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { v, err := ResolveEnv([]byte(tc.in)) - ztesting.AssertEqual(t, "value not match", tc.result, string(v)) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.result, string(v)) + ztesting.AssertEqualErr(t, tc.err, err) }) } } @@ -109,8 +109,8 @@ func TestResolveGroup1(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { v, err := resolveGroup1(tc.o) - ztesting.AssertEqual(t, "value not match", tc.result, v) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.result, v) + ztesting.AssertEqualErr(t, tc.err, err) }) } } @@ -139,8 +139,8 @@ func TestResolveGroup2(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { v, err := resolveGroup2(tc.p, tc.o) - ztesting.AssertEqual(t, "value not match", tc.result, v) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.result, v) + ztesting.AssertEqualErr(t, tc.err, err) }) } } @@ -162,8 +162,8 @@ func TestResolveGroup3(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { v, err := resolveGroup3(tc.p, tc.o) - ztesting.AssertEqual(t, "value not match", tc.result, v) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.result, v) + ztesting.AssertEqualErr(t, tc.err, err) }) } } @@ -186,8 +186,8 @@ func TestResolveGroup4(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { v, err := resolveGroup4(tc.p, tc.o) - ztesting.AssertEqual(t, "value not match", tc.result, v) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.result, v) + ztesting.AssertEqualErr(t, tc.err, err) }) } } @@ -210,8 +210,8 @@ func TestResolveGroup5(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { v, err := resolveGroup5(tc.p, tc.o) - ztesting.AssertEqual(t, "value not match", tc.result, v) - ztesting.AssertEqualErr(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.result, v) + ztesting.AssertEqualErr(t, tc.err, err) }) } } diff --git a/zos/file_test.go b/zos/file_test.go index 00552d8..cdbf545 100644 --- a/zos/file_test.go +++ b/zos/file_test.go @@ -14,10 +14,10 @@ func TestOpenFileReadOnly(t *testing.T) { t.Run("cannot write", func(t *testing.T) { f, err := zos.OpenFileReadOnly("./testdata/readonly.txt") defer f.Close() - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) n, err := f.Write([]byte("test")) - ztesting.AssertEqual(t, "could write", 0, n) - ztesting.AssertEqual(t, "expected error not occurred", true, err != nil) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, true, err != nil) }) } @@ -30,17 +30,17 @@ func TestOpenFileWriteOnly(t *testing.T) { t.Run("cannot read", func(t *testing.T) { f, err := zos.OpenFileWriteOnly("./testdata/TestOpenFileWriteOnly/cannot-read1.txt") defer f.Close() - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) n, err := f.Write([]byte("test")) - ztesting.AssertEqual(t, "unexpected written bytes", 4, n) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, 4, n) + ztesting.AssertEqual(t, nil, err) n, err = f.ReadAt(make([]byte, 10), 0) - ztesting.AssertEqual(t, "could read", 0, n) - ztesting.AssertEqual(t, "expected error not occurred", true, err != nil) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("create dir failed", func(t *testing.T) { _, err := zos.OpenFileWriteOnly("./testdata/TestOpenFileWriteOnly\x00/cannot-read2.txt") - ztesting.AssertEqual(t, "expected error not occurred", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) } @@ -53,17 +53,17 @@ func TestOpenFileReadWrite(t *testing.T) { t.Run("cannot read", func(t *testing.T) { f, err := zos.OpenFileReadWrite("./testdata/TestOpenFileReadWrite/read-write1.txt") defer f.Close() - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) n, err := f.Write([]byte("test")) - ztesting.AssertEqual(t, "unexpected written bytes", 4, n) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, 4, n) + ztesting.AssertEqual(t, nil, err) n, err = f.ReadAt(make([]byte, 3), 0) - ztesting.AssertEqual(t, "could not read", 3, n) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, 3, n) + ztesting.AssertEqual(t, nil, err) }) t.Run("create dir failed", func(t *testing.T) { _, err := zos.OpenFileReadWrite("./testdata/TestOpenFileReadWrite\x00/read-write2.txt") - ztesting.AssertEqual(t, "expected error not occurred", true, err != nil) + ztesting.AssertEqual(t, true, err != nil) }) } @@ -71,18 +71,18 @@ func TestIsFile(t *testing.T) { t.Parallel() t.Run("file", func(t *testing.T) { ok, err := zos.IsFile("./testdata/regular-file.txt") - ztesting.AssertEqual(t, "incorrect judgement", true, ok) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, nil, err) }) t.Run("non file", func(t *testing.T) { ok, err := zos.IsFile("./testdata/") - ztesting.AssertEqual(t, "incorrect judgement", false, ok) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, nil, err) }) t.Run("stat error", func(t *testing.T) { ok, err := zos.IsFile("./testdata\x00/") - ztesting.AssertEqual(t, "incorrect judgement", false, ok) - ztesting.AssertEqual(t, "expected error not occurred", true, err != nil) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, true, err != nil) }) } @@ -90,18 +90,18 @@ func TestIsDir(t *testing.T) { t.Parallel() t.Run("dir", func(t *testing.T) { ok, err := zos.IsDir("./testdata/") - ztesting.AssertEqual(t, "incorrect judgement", true, ok) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, nil, err) }) t.Run("non dir", func(t *testing.T) { ok, err := zos.IsDir("./testdata/regular-file.txt") - ztesting.AssertEqual(t, "incorrect judgement", false, ok) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, nil, err) }) t.Run("stat error", func(t *testing.T) { ok, err := zos.IsDir("./testdata\x00/") - ztesting.AssertEqual(t, "incorrect judgement", false, ok) - ztesting.AssertEqual(t, "expected error not occurred", true, err != nil) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, true, err != nil) }) } @@ -109,18 +109,18 @@ func TestReadFiles(t *testing.T) { t.Parallel() t.Run("no paths", func(t *testing.T) { contents, err := zos.ReadFiles(false) - ztesting.AssertEqual(t, "returned data not match", 0, len(contents)) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, 0, len(contents)) + ztesting.AssertEqual(t, nil, err) }) t.Run("empty path", func(t *testing.T) { contents, err := zos.ReadFiles(false, "") - ztesting.AssertEqual(t, "returned data not match", 0, len(contents)) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, 0, len(contents)) + ztesting.AssertEqual(t, nil, err) }) t.Run("invalid path", func(t *testing.T) { contents, err := zos.ReadFiles(false, "./not-found/") - ztesting.AssertEqual(t, "returned data not match", 0, len(contents)) - ztesting.AssertEqual(t, "expected error not occurred", true, err != nil) + ztesting.AssertEqual(t, 0, len(contents)) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("not recursive", func(t *testing.T) { contents, err := zos.ReadFiles(false, "./testdata/regular-file.txt", "./testdata/files/") @@ -128,11 +128,11 @@ func TestReadFiles(t *testing.T) { for k, v := range want { vv := contents[k] if !slices.Equal(v, vv) { - ztesting.AssertEqual(t, "content not match for key="+k, v, contents[k]) + ztesting.AssertEqual(t, v, contents[k]) } } - ztesting.AssertEqual(t, "returned data size not match", 2, len(contents)) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, 2, len(contents)) + ztesting.AssertEqual(t, nil, err) }) t.Run("recursive", func(t *testing.T) { contents, err := zos.ReadFiles(true, "./testdata/files/") @@ -142,11 +142,11 @@ func TestReadFiles(t *testing.T) { for k, v := range want { vv := contents[k] if !slices.Equal(v, vv) { - ztesting.AssertEqual(t, "content not match for key="+k, v, contents[k]) + ztesting.AssertEqual(t, v, contents[k]) } } - ztesting.AssertEqual(t, "returned data size not match", 2, len(contents)) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, 2, len(contents)) + ztesting.AssertEqual(t, nil, err) }) } @@ -154,26 +154,26 @@ func TestListFiles(t *testing.T) { t.Parallel() t.Run("contain empty", func(t *testing.T) { paths, err := zos.ListFiles(false, "") - ztesting.AssertEqual(t, "paths not match", nil, paths) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, paths) + ztesting.AssertEqual(t, nil, err) }) t.Run("invalid file path", func(t *testing.T) { paths, err := zos.ListFiles(false, "./not-found/") - ztesting.AssertEqual(t, "paths not match", nil, paths) - ztesting.AssertEqual(t, "expected error not occurred", true, err != nil) + ztesting.AssertEqual(t, nil, paths) + ztesting.AssertEqual(t, true, err != nil) }) t.Run("not recursive", func(t *testing.T) { paths, err := zos.ListFiles(false, "./testdata/regular-file.txt", "./testdata/files/") want := []string{filepath.Clean("./testdata/regular-file.txt"), filepath.Clean("./testdata/files/level0.txt")} - ztesting.AssertEqual(t, "paths not match", want, paths) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, want, paths) + ztesting.AssertEqual(t, nil, err) }) t.Run("recursive", func(t *testing.T) { paths, err := zos.ListFiles(true, "./testdata/files/") want := []string{} want = append(want, filepath.Clean("./testdata/files/level0.txt")) want = append(want, filepath.Clean("./testdata/files/level1/level1.txt")) - ztesting.AssertEqual(t, "paths not match", want, paths) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, want, paths) + ztesting.AssertEqual(t, nil, err) }) } diff --git a/zos/load_test.go b/zos/load_test.go index 1f9e753..e5c9230 100644 --- a/zos/load_test.go +++ b/zos/load_test.go @@ -14,105 +14,105 @@ func TestLoadEnv(t *testing.T) { err := zos.LoadEnv("testdata/env/comment.txt") want := map[string]string{"FOO": "foo"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("export", func(t *testing.T) { err := zos.LoadEnv("testdata/env/export.txt") want := map[string]string{"FOO": "foo", "B_A_R": "bar"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("char escape", func(t *testing.T) { err := zos.LoadEnv("testdata/env/char-escape.txt") want := map[string]string{"FOO": "foo"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("quotations", func(t *testing.T) { err := zos.LoadEnv("testdata/env/quotations.txt") want := map[string]string{"NONE": "none", "SINGLE": "single", "DOUBLE": "double"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("quotations in quotations", func(t *testing.T) { err := zos.LoadEnv("testdata/env/quotations-in-quotations.txt") want := map[string]string{"SINGLE": "single and \"double\"", "DOUBLE": "'single' and double"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("quotations escape", func(t *testing.T) { err := zos.LoadEnv("testdata/env/quotations-escape.txt") want := map[string]string{"SINGLE": "single 'escape'", "DOUBLE": "double \"escape\""} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("quotations sequence", func(t *testing.T) { err := zos.LoadEnv("testdata/env/quotations-sequence.txt") want := map[string]string{"SEQ1": "SingleDouble", "SEQ2": "Single and Double"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("multiline", func(t *testing.T) { err := zos.LoadEnv("testdata/env/multiline.txt") want := map[string]string{"MULTI1": "line1line2", "MULTI2": "line1line2"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("multiline with line break", func(t *testing.T) { err := zos.LoadEnv("testdata/env/multiline-line-break.txt") want := map[string]string{"MULTI1": "line1\nline2", "MULTI2": "line1\nline2"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("end with escape", func(t *testing.T) { err := zos.LoadEnv("testdata/env/end-with-escape.txt") want := map[string]string{"FOO": "foo\\"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, os.Getenv(k)) + ztesting.AssertEqual(t, v, os.Getenv(k)) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("env not found", func(t *testing.T) { err := zos.LoadEnv("testdata/env/env-not-found.txt") - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: loading env failed."}, err) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: loading env failed."}, err) }) t.Run("invalid char", func(t *testing.T) { err := zos.LoadEnv("testdata/env/invalid-char.txt") - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: loading env failed."}, err) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: loading env failed."}, err) }) t.Run("invalid line format", func(t *testing.T) { err := zos.LoadEnv("testdata/env/invalid-line-format.txt") - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: loading env failed."}, err) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: loading env failed."}, err) }) t.Run("quotation not closed", func(t *testing.T) { err := zos.LoadEnv("testdata/env/quotation-not-closed.txt") - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: loading env failed."}, err) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: loading env failed."}, err) }) t.Run("env subst error", func(t *testing.T) { err := zos.LoadEnv("testdata/env/env-subst-error.txt") - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: loading env failed."}, err) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: loading env failed."}, err) }) t.Run("read file error", func(t *testing.T) { err := zos.LoadEnv("testdata/env/not-exist.txt") - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: loading env failed."}, err) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: loading env failed."}, err) }) } @@ -126,9 +126,9 @@ func TestParseEnv(t *testing.T) { m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"FOO": "foo"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("export", func(t *testing.T) { txt := ` @@ -138,18 +138,18 @@ func TestParseEnv(t *testing.T) { m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"FOO": "foo", "B_A_R": "bar"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("char escape", func(t *testing.T) { txt := `FOO=\f\o\o` m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"FOO": "foo"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("quotations", func(t *testing.T) { txt := ` @@ -160,9 +160,9 @@ func TestParseEnv(t *testing.T) { m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"NONE": "none", "SINGLE": "single", "DOUBLE": "double"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("quotations in quotations", func(t *testing.T) { txt := ` @@ -172,9 +172,9 @@ func TestParseEnv(t *testing.T) { m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"SINGLE": "single and \"double\"", "DOUBLE": "'single' and double"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("quotations escape", func(t *testing.T) { txt := ` @@ -184,9 +184,9 @@ func TestParseEnv(t *testing.T) { m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"SINGLE": "single 'escape'", "DOUBLE": "double \"escape\""} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("quotations sequence", func(t *testing.T) { txt := ` @@ -196,9 +196,9 @@ func TestParseEnv(t *testing.T) { m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"SEQ1": "SingleDouble", "SEQ2": "Single and Double"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("multiline", func(t *testing.T) { txt := ` @@ -214,9 +214,9 @@ func TestParseEnv(t *testing.T) { m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"MULTI1": "line1line2", "MULTI2": "line1line2"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("multiline with line break", func(t *testing.T) { txt := ` @@ -232,36 +232,36 @@ func TestParseEnv(t *testing.T) { m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"MULTI1": "line1\nline2", "MULTI2": "line1\nline2"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("end with escape", func(t *testing.T) { txt := `FOO=foo\` m, err := zos.ParseEnv([]byte(txt)) want := map[string]string{"FOO": "foo\\"} for k, v := range want { - ztesting.AssertEqual(t, "value not match", v, m[k]) + ztesting.AssertEqual(t, v, m[k]) } - ztesting.AssertEqualErr(t, "non nil error returned", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("env not found", func(t *testing.T) { txt := `=foo` m, err := zos.ParseEnv([]byte(txt)) - ztesting.AssertEqual(t, "unexpected value found", 0, len(m)) - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: parsing env failed."}, err) + ztesting.AssertEqual(t, 0, len(m)) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: parsing env failed."}, err) }) t.Run("invalid char", func(t *testing.T) { txt := `***=foo` m, err := zos.ParseEnv([]byte(txt)) - ztesting.AssertEqual(t, "unexpected value found", 0, len(m)) - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: parsing env failed."}, err) + ztesting.AssertEqual(t, 0, len(m)) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: parsing env failed."}, err) }) t.Run("invalid line format", func(t *testing.T) { txt := `foo` m, err := zos.ParseEnv([]byte(txt)) - ztesting.AssertEqual(t, "unexpected value found", 0, len(m)) - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: parsing env failed."}, err) + ztesting.AssertEqual(t, 0, len(m)) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: parsing env failed."}, err) }) t.Run("quotation not closed", func(t *testing.T) { txt := ` @@ -270,13 +270,13 @@ func TestParseEnv(t *testing.T) { line2 ` m, err := zos.ParseEnv([]byte(txt)) - ztesting.AssertEqual(t, "unexpected value found", 0, len(m)) - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: parsing env failed."}, err) + ztesting.AssertEqual(t, 0, len(m)) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: parsing env failed."}, err) }) t.Run("env subst error", func(t *testing.T) { txt := `FOO=${!FOO}` m, err := zos.ParseEnv([]byte(txt)) - ztesting.AssertEqual(t, "unexpected value found", 0, len(m)) - ztesting.AssertEqualErr(t, "error not match", &zos.EnvError{Type: "zos: parsing env failed."}, err) + ztesting.AssertEqual(t, 0, len(m)) + ztesting.AssertEqualErr(t, &zos.EnvError{Type: "zos: parsing env failed."}, err) }) } diff --git a/zos/resolver_test.go b/zos/resolver_test.go index 99b98ca..fd518ad 100644 --- a/zos/resolver_test.go +++ b/zos/resolver_test.go @@ -44,21 +44,21 @@ func TestEnvError(t *testing.T) { t.Run("unwrap", func(t *testing.T) { err := &EnvError{Err: io.EOF} inner := err.Unwrap() - ztesting.AssertEqualErr(t, "unwrapped err not match", io.EOF, inner) + ztesting.AssertEqualErr(t, io.EOF, inner) }) t.Run("message", func(t *testing.T) { err := &EnvError{Err: io.EOF, Type: "err type", Info: "err info"} msg := err.Error() - ztesting.AssertEqual(t, "err massage not match", "err type err info [EOF]", msg) + ztesting.AssertEqual(t, "err type err info [EOF]", msg) }) t.Run("errors equal", func(t *testing.T) { err1 := &EnvError{Err: io.EOF, Type: "err type"} err2 := &EnvError{Err: io.EOF, Type: "err type"} - ztesting.AssertEqual(t, "errors not same", true, errors.Is(err1, err2)) + ztesting.AssertEqual(t, true, errors.Is(err1, err2)) }) t.Run("errors not equal", func(t *testing.T) { err := &EnvError{Type: "err type"} - ztesting.AssertEqual(t, "errors are same", false, errors.Is(err, io.EOF)) + ztesting.AssertEqual(t, false, errors.Is(err, io.EOF)) }) } @@ -80,9 +80,9 @@ func TestEnv01(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv01", tc.preset) got, err := env01(tc.p) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -106,9 +106,9 @@ func TestEnv02(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv02", tc.preset) got, err := env02(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -132,9 +132,9 @@ func TestEnv03(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv03", tc.preset) got, err := env03(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -158,9 +158,9 @@ func TestEnv04(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv04", tc.preset) got, err := env04(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -184,9 +184,9 @@ func TestEnv05(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv05", tc.preset) got, err := env05(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -210,9 +210,9 @@ func TestEnv06(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv06", tc.preset) got, err := env06(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -236,9 +236,9 @@ func TestEnv07(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv07", tc.preset) got, err := env07(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -262,9 +262,9 @@ func TestEnv08(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv08", tc.preset) got, err := env08(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -288,9 +288,9 @@ func TestEnv09(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv09", tc.preset) got, err := env09(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -322,9 +322,9 @@ func TestEnv10(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv10", tc.preset) got, err := env10(tc.p, tc.o) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -376,9 +376,9 @@ func TestEnv11(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv11", tc.preset) got, err := env11(tc.p, tc.o, tc.l) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -404,9 +404,9 @@ func TestEnv12(t *testing.T) { t.Setenv("TestEnv12_var1", tc.preset) t.Setenv("TestEnv12_var2", tc.preset) got, err := env12(tc.p) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -432,9 +432,9 @@ func TestEnv13(t *testing.T) { t.Setenv("TestEnv13_var1", tc.preset) t.Setenv("TestEnv13_var2", tc.preset) got, err := env13(tc.p) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -459,9 +459,9 @@ func TestEnv14(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv14", tc.preset) got, err := env14(tc.p) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -484,9 +484,9 @@ func TestEnv15(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv15", tc.preset) got, err := env15(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -523,9 +523,9 @@ func TestEnv16(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv16", tc.preset) got, err := env16(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -548,9 +548,9 @@ func TestEnv17(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv17", tc.preset) got, err := env17(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -588,9 +588,9 @@ func TestEnv18(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv18", tc.preset) got, err := env18(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -627,9 +627,9 @@ func TestEnv19(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv19", tc.preset) got, err := env19(tc.p, tc.w, tc.s) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -666,9 +666,9 @@ func TestEnv20(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv20", tc.preset) got, err := env20(tc.p, tc.w, tc.s) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -705,9 +705,9 @@ func TestEnv21(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv21", tc.preset) got, err := env21(tc.p, tc.w, tc.s) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -744,9 +744,9 @@ func TestEnv22(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv22", tc.preset) got, err := env22(tc.p, tc.w, tc.s) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -785,9 +785,9 @@ func TestEnv23(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv23", tc.preset) got, err := env23(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -824,9 +824,9 @@ func TestEnv24(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv24", tc.preset) got, err := env24(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -865,9 +865,9 @@ func TestEnv25(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv25", tc.preset) got, err := env25(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -904,9 +904,9 @@ func TestEnv26(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv26", tc.preset) got, err := env26(tc.p, tc.w) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } @@ -937,9 +937,9 @@ func TestEnv27(t *testing.T) { t.Run(name, func(t *testing.T) { t.Setenv("TestEnv27", tc.preset) got, err := env27(tc.p, tc.o) - ztesting.AssertEqual(t, "invalid resolved value of env.", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) if tc.err != nil { - ztesting.AssertEqual(t, "unexpected error.", tc.err.Error(), err.Error()) + ztesting.AssertEqual(t, tc.err.Error(), err.Error()) } }) } diff --git a/zplugin/plugin_test.go b/zplugin/plugin_test.go index c722fb0..2210e33 100644 --- a/zplugin/plugin_test.go +++ b/zplugin/plugin_test.go @@ -26,8 +26,8 @@ func TestLookup(t *testing.T) { }) defer done() s, err := zplugin.Lookup("test.so", "MyFunc") - ztesting.AssertEqual(t, "symbol not match", nil, s) - ztesting.AssertEqualErr(t, "error not match", openErr, err) + ztesting.AssertEqual(t, nil, s) + ztesting.AssertEqualErr(t, openErr, err) }) t.Run("lookup error", func(t *testing.T) { lookupErr := errors.New("open error") @@ -36,8 +36,8 @@ func TestLookup(t *testing.T) { }) defer done() s, err := zplugin.Lookup("test.so", "MyFunc") - ztesting.AssertEqual(t, "symbol not match", nil, s) - ztesting.AssertEqualErr(t, "error not match", lookupErr, err) + ztesting.AssertEqual(t, nil, s) + ztesting.AssertEqualErr(t, lookupErr, err) }) t.Run("lookup success", func(t *testing.T) { done := zplugin.WithTestOpenFunc(func(path string) (zplugin.Lookupper, error) { @@ -45,8 +45,8 @@ func TestLookup(t *testing.T) { }) defer done() s, err := zplugin.Lookup("test.so", "MyVar") - ztesting.AssertEqual(t, "symbol not match", plugin.Symbol("value"), s) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, plugin.Symbol("value"), s) + ztesting.AssertEqualErr(t, nil, err) }) } @@ -58,8 +58,8 @@ func TestLookupAll(t *testing.T) { }) defer done() ss, err := zplugin.LookupAll("test.so", "MyFunc", "MyVar") - ztesting.AssertEqual(t, "unexpectedly symbol returned", 0, len(ss)) - ztesting.AssertEqualErr(t, "error not match", openErr, err) + ztesting.AssertEqual(t, 0, len(ss)) + ztesting.AssertEqualErr(t, openErr, err) }) t.Run("lookup error", func(t *testing.T) { lookupErr := errors.New("open error") @@ -68,8 +68,8 @@ func TestLookupAll(t *testing.T) { }) defer done() ss, err := zplugin.LookupAll("test.so", "MyFunc", "MyVar") - ztesting.AssertEqual(t, "unexpectedly symbol returned", 0, len(ss)) - ztesting.AssertEqualErr(t, "error not match", lookupErr, err) + ztesting.AssertEqual(t, 0, len(ss)) + ztesting.AssertEqualErr(t, lookupErr, err) }) t.Run("lookup success", func(t *testing.T) { done := zplugin.WithTestOpenFunc(func(path string) (zplugin.Lookupper, error) { @@ -80,9 +80,9 @@ func TestLookupAll(t *testing.T) { }) defer done() ss, err := zplugin.LookupAll("test.so", "MyVar1", "MyVar2") - ztesting.AssertEqual(t, "symbol not match", plugin.Symbol("value1"), ss["MyVar1"]) - ztesting.AssertEqual(t, "symbol not match", plugin.Symbol("value2"), ss["MyVar2"]) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, plugin.Symbol("value1"), ss["MyVar1"]) + ztesting.AssertEqual(t, plugin.Symbol("value2"), ss["MyVar2"]) + ztesting.AssertEqualErr(t, nil, err) }) } @@ -94,9 +94,9 @@ func TestUse(t *testing.T) { }) defer done() s, v, err := zplugin.Use[int]("test.so", "MyVar") - ztesting.AssertEqual(t, "symbol not match", nil, s) - ztesting.AssertEqual(t, "value not match", 0, v) - ztesting.AssertEqualErr(t, "error not match", openErr, err) + ztesting.AssertEqual(t, nil, s) + ztesting.AssertEqual(t, 0, v) + ztesting.AssertEqualErr(t, openErr, err) }) t.Run("lookup error", func(t *testing.T) { lookupErr := errors.New("open error") @@ -105,9 +105,9 @@ func TestUse(t *testing.T) { }) defer done() s, v, err := zplugin.Use[int]("test.so", "MyVar") - ztesting.AssertEqual(t, "symbol not match", nil, s) - ztesting.AssertEqual(t, "value not match", 0, v) - ztesting.AssertEqualErr(t, "error not match", lookupErr, err) + ztesting.AssertEqual(t, nil, s) + ztesting.AssertEqual(t, 0, v) + ztesting.AssertEqualErr(t, lookupErr, err) }) t.Run("type assertion error", func(t *testing.T) { done := zplugin.WithTestOpenFunc(func(path string) (zplugin.Lookupper, error) { @@ -117,9 +117,9 @@ func TestUse(t *testing.T) { }) defer done() s, v, err := zplugin.Use[string]("test.so", "MyVar") - ztesting.AssertEqual(t, "symbol not match", plugin.Symbol(12345), s) - ztesting.AssertEqual(t, "value not match", "", v) - ztesting.AssertEqualErr(t, "error not match", zplugin.ErrAssert, err) + ztesting.AssertEqual(t, plugin.Symbol(12345), s) + ztesting.AssertEqual(t, "", v) + ztesting.AssertEqualErr(t, zplugin.ErrAssert, err) }) t.Run("lookup success", func(t *testing.T) { done := zplugin.WithTestOpenFunc(func(path string) (zplugin.Lookupper, error) { @@ -129,8 +129,8 @@ func TestUse(t *testing.T) { }) defer done() s, v, err := zplugin.Use[int]("test.so", "MyVar") - ztesting.AssertEqual(t, "symbol not match", plugin.Symbol(12345), s) - ztesting.AssertEqual(t, "value not match", 12345, v) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, plugin.Symbol(12345), s) + ztesting.AssertEqual(t, 12345, v) + ztesting.AssertEqualErr(t, nil, err) }) } diff --git a/zruntime/frame_test.go b/zruntime/frame_test.go index b81d1cd..14c1859 100644 --- a/zruntime/frame_test.go +++ b/zruntime/frame_test.go @@ -37,10 +37,10 @@ func TestConvertFrame(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { f := zruntime.ConvertFrame(tc.frame) - ztesting.AssertEqual(t, "pkg value does not match.", tc.want.Pkg, f.Pkg) - ztesting.AssertEqual(t, "file value does not match.", tc.want.File, f.File) - ztesting.AssertEqual(t, "func value does not match.", tc.want.Func, f.Func) - ztesting.AssertEqual(t, "line value does not match.", tc.want.Line, f.Line) + ztesting.AssertEqual(t, tc.want.Pkg, f.Pkg) + ztesting.AssertEqual(t, tc.want.File, f.File) + ztesting.AssertEqual(t, tc.want.Func, f.Func) + ztesting.AssertEqual(t, tc.want.Line, f.Line) }) } } @@ -76,10 +76,10 @@ func TestConvertFrames(t *testing.T) { } for i, f := range fs { w := tc.want[i] - ztesting.AssertEqual(t, "pkg value does not match.", w.Pkg, f.Pkg) - ztesting.AssertEqual(t, "file value does not match.", w.File, f.File) - ztesting.AssertEqual(t, "func value does not match.", w.Func, f.Func) - ztesting.AssertEqual(t, "line value does not match.", w.Line, f.Line) + ztesting.AssertEqual(t, w.Pkg, f.Pkg) + ztesting.AssertEqual(t, w.File, f.File) + ztesting.AssertEqual(t, w.Func, f.Func) + ztesting.AssertEqual(t, w.Line, f.Line) } }) } @@ -90,23 +90,23 @@ func TestCallerFrame(t *testing.T) { t.Run("skip=0", func(t *testing.T) { f := zruntime.CallerFrame(0) - ztesting.AssertEqual(t, "file does not have appropriate suffix.", true, strings.HasSuffix(f.File, "frame_test.go")) - ztesting.AssertEqual(t, "func does not have appropriate suffix.", true, strings.HasSuffix(f.Function, "TestCallerFrame.func1")) - ztesting.AssertEqual(t, "line number is not positive.", true, f.Line > 0) + ztesting.AssertEqual(t, true, strings.HasSuffix(f.File, "frame_test.go")) + ztesting.AssertEqual(t, true, strings.HasSuffix(f.Function, "TestCallerFrame.func1")) + ztesting.AssertEqual(t, true, f.Line > 0) }) t.Run("skip=9999", func(t *testing.T) { f := zruntime.CallerFrame(9999) - ztesting.AssertEqual(t, "file has value.", "", f.File) - ztesting.AssertEqual(t, "func has value.", "", f.Function) - ztesting.AssertEqual(t, "line number is not 0.", 0, f.Line) + ztesting.AssertEqual(t, "", f.File) + ztesting.AssertEqual(t, "", f.Function) + ztesting.AssertEqual(t, 0, f.Line) }) t.Run("skip=-9999", func(t *testing.T) { f := zruntime.CallerFrame(-9999) - ztesting.AssertEqual(t, "file does not have appropriate suffix.", true, strings.HasSuffix(f.File, "runtime/extern.go")) - ztesting.AssertEqual(t, "func does not have appropriate suffix.", true, strings.HasSuffix(f.Function, "runtime.Callers")) - ztesting.AssertEqual(t, "line number is not positive.", true, f.Line > 0) + ztesting.AssertEqual(t, true, strings.HasSuffix(f.File, "runtime/extern.go")) + ztesting.AssertEqual(t, true, strings.HasSuffix(f.Function, "runtime.Callers")) + ztesting.AssertEqual(t, true, f.Line > 0) }) } @@ -115,24 +115,24 @@ func TestCallerFrames(t *testing.T) { t.Run("skip=0", func(t *testing.T) { fs := zruntime.CallerFrames(0) - ztesting.AssertEqual(t, "no frames found.", true, len(fs) > 1) + ztesting.AssertEqual(t, true, len(fs) > 1) f := fs[0] - ztesting.AssertEqual(t, "file does not have appropriate suffix.", true, strings.HasSuffix(f.File, "frame_test.go")) - ztesting.AssertEqual(t, "func does not have appropriate suffix.", true, strings.HasSuffix(f.Function, "TestCallerFrames.func1")) - ztesting.AssertEqual(t, "line number is not positive.", true, f.Line > 0) + ztesting.AssertEqual(t, true, strings.HasSuffix(f.File, "frame_test.go")) + ztesting.AssertEqual(t, true, strings.HasSuffix(f.Function, "TestCallerFrames.func1")) + ztesting.AssertEqual(t, true, f.Line > 0) }) t.Run("skip=9999", func(t *testing.T) { fs := zruntime.CallerFrames(9999) - ztesting.AssertEqual(t, "frames found.", 0, len(fs)) + ztesting.AssertEqual(t, 0, len(fs)) }) t.Run("skip=-9999", func(t *testing.T) { fs := zruntime.CallerFrames(-9999) - ztesting.AssertEqual(t, "no frames found.", true, len(fs) > 1) + ztesting.AssertEqual(t, true, len(fs) > 1) f := fs[0] - ztesting.AssertEqual(t, "file does not have appropriate suffix.", true, strings.HasSuffix(f.File, "runtime/extern.go")) - ztesting.AssertEqual(t, "func does not have appropriate suffix.", true, strings.HasSuffix(f.Function, "runtime.Callers")) - ztesting.AssertEqual(t, "line number is not positive.", true, f.Line > 0) + ztesting.AssertEqual(t, true, strings.HasSuffix(f.File, "runtime/extern.go")) + ztesting.AssertEqual(t, true, strings.HasSuffix(f.Function, "runtime.Callers")) + ztesting.AssertEqual(t, true, f.Line > 0) }) } diff --git a/zruntime/report_test.go b/zruntime/report_test.go index de0e9f6..7b18762 100644 --- a/zruntime/report_test.go +++ b/zruntime/report_test.go @@ -21,12 +21,12 @@ func TestReportErr(t *testing.T) { var buf bytes.Buffer reportTo = &buf ReportErr(nil, "description") - ztesting.AssertEqual(t, "report is not empty", "", buf.String()) + ztesting.AssertEqual(t, "", buf.String()) }) t.Run("report error", func(t *testing.T) { var buf bytes.Buffer reportTo = &buf ReportErr(io.EOF, "description") - ztesting.AssertEqual(t, "report does not contain error", true, strings.Contains(buf.String(), ">> Error : EOF")) + ztesting.AssertEqual(t, true, strings.Contains(buf.String(), ">> Error : EOF")) }) } diff --git a/zruntime/zdebug/debug_internal_test.go b/zruntime/zdebug/debug_internal_test.go index 56b1afc..8bbd3f1 100644 --- a/zruntime/zdebug/debug_internal_test.go +++ b/zruntime/zdebug/debug_internal_test.go @@ -50,7 +50,7 @@ func TestInitDebug(t *testing.T) { initDebug(tc.writeTo, func(dir, pattern string) (*os.File, error) { return os.Stdin, nil }) - ztesting.AssertEqual(t, "writer not matched.", tc.wants, writer) + ztesting.AssertEqual(t, tc.wants, writer) }) } } @@ -60,7 +60,7 @@ func TestInitDebug_panics(t *testing.T) { err := errors.New("file create error") defer func() { rec := recover() - ztesting.AssertEqual(t, "error not matched.", err, rec.(error)) + ztesting.AssertEqual(t, err, rec.(error)) }() initDebug("file", func(dir, pattern string) (*os.File, error) { return nil, err @@ -139,7 +139,7 @@ func TestPrefixWriter(t *testing.T) { w.Write(v) } result := buf.String() - ztesting.AssertEqual(t, " does not match.", tc.wants, result) + ztesting.AssertEqual(t, tc.wants, result) }) } } @@ -152,9 +152,9 @@ func TestDump(t *testing.T) { Dump("", int(123)) result := buf.String() if dumpEnabled { - ztesting.AssertEqual(t, "dump does not contain datetime", true, strings.Contains(result, "1970-01-01 00:00:00 [DUMP]")) + ztesting.AssertEqual(t, true, strings.Contains(result, "1970-01-01 00:00:00 [DUMP]")) } else { - ztesting.AssertEqual(t, "dump should be empty", "", result) + ztesting.AssertEqual(t, "", result) } } @@ -165,6 +165,6 @@ func TestDumpAlways(t *testing.T) { defer func() { writer = tmp }() DumpAlways("", int(123)) result := buf.String() - ztesting.AssertEqual(t, "dump does not contain datetime", true, strings.Contains(result, "1970-01-01 00:00:00 [DUMP]")) + ztesting.AssertEqual(t, true, strings.Contains(result, "1970-01-01 00:00:00 [DUMP]")) } diff --git a/zruntime/zdebug/debug_test.go b/zruntime/zdebug/debug_test.go index fb7a8aa..e58f0d8 100644 --- a/zruntime/zdebug/debug_test.go +++ b/zruntime/zdebug/debug_test.go @@ -55,9 +55,9 @@ func TestDumpTo(t *testing.T) { var buf bytes.Buffer zdebug.DumpTo(&buf, "", tc.a...) result := buf.String() - ztesting.AssertEqual(t, "dump result does not contain date and time.", true, strings.Contains(result, "1970-01-01 00:00:00 [DUMP]")) + ztesting.AssertEqual(t, true, strings.Contains(result, "1970-01-01 00:00:00 [DUMP]")) for _, w := range tc.wants { - ztesting.AssertEqual(t, "expected dump result not output.", true, strings.Contains(result, w)) + ztesting.AssertEqual(t, true, strings.Contains(result, w)) } }) } @@ -67,9 +67,9 @@ func TestHookDumpFunc(t *testing.T) { returnBool := false hookDumpFunc := zdebug.HookDumpFunc zdebug.HookDumpFunc = func(w io.Writer, f zruntime.Frame, a ...any) bool { - ztesting.AssertEqual(t, "length does not match.", 2, len(a)) - ztesting.AssertEqual(t, "unexpected value.", int(0), a[0].(int)) - ztesting.AssertEqual(t, "unexpected value.", int(1), a[1].(int)) + ztesting.AssertEqual(t, 2, len(a)) + ztesting.AssertEqual(t, int(0), a[0].(int)) + ztesting.AssertEqual(t, int(1), a[1].(int)) return returnBool } defer func() { @@ -80,12 +80,12 @@ func TestHookDumpFunc(t *testing.T) { var buf bytes.Buffer returnBool = true // Set value true. zdebug.DumpTo(&buf, "", int(0), int(1)) - ztesting.AssertEqual(t, "dump continued after HookDumpFunc returned true.", "", buf.String()) + ztesting.AssertEqual(t, "", buf.String()) }) t.Run("func returns false", func(t *testing.T) { var buf bytes.Buffer returnBool = false // Set value false. zdebug.DumpTo(&buf, "", int(0), int(1)) - ztesting.AssertEqual(t, "dump should output information.", false, buf.String() == "") + ztesting.AssertEqual(t, false, buf.String() == "") }) } diff --git a/zstrconv/strconv_internal_test.go b/zstrconv/strconv_internal_test.go index b1c9516..b78d093 100644 --- a/zstrconv/strconv_internal_test.go +++ b/zstrconv/strconv_internal_test.go @@ -11,7 +11,7 @@ func TestParseNum(t *testing.T) { t.Parallel() t.Run("unsupported type", func(t *testing.T) { vv, err := paseNum("true", reflect.Bool) - ztesting.AssertEqual(t, "incorrect parse result", nil, vv) - ztesting.AssertEqualErr(t, "non nil error returned", ErrTypeSupported, err) + ztesting.AssertEqual(t, nil, vv) + ztesting.AssertEqualErr(t, ErrTypeSupported, err) }) } diff --git a/zstrconv/strconv_test.go b/zstrconv/strconv_test.go index b4a9e2b..1743e3c 100644 --- a/zstrconv/strconv_test.go +++ b/zstrconv/strconv_test.go @@ -13,115 +13,115 @@ func TestParseNum(t *testing.T) { t.Parallel() t.Run("int", func(t *testing.T) { v, err := zstrconv.ParseNum[int]("123") - ztesting.AssertEqual(t, "incorrect parse result", int(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, int(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[int]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", int(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, int(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("int8", func(t *testing.T) { v, err := zstrconv.ParseNum[int8]("123") - ztesting.AssertEqual(t, "incorrect parse result", int8(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, int8(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[int8]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", int8(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, int8(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("int16", func(t *testing.T) { v, err := zstrconv.ParseNum[int16]("123") - ztesting.AssertEqual(t, "incorrect parse result", int16(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, int16(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[int16]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", int16(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, int16(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("int16", func(t *testing.T) { v, err := zstrconv.ParseNum[int16]("123") - ztesting.AssertEqual(t, "incorrect parse result", int16(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, int16(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[int16]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", int16(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, int16(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("int32", func(t *testing.T) { v, err := zstrconv.ParseNum[int32]("123") - ztesting.AssertEqual(t, "incorrect parse result", int32(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, int32(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[int32]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", int32(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, int32(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("int64", func(t *testing.T) { v, err := zstrconv.ParseNum[int64]("123") - ztesting.AssertEqual(t, "incorrect parse result", int64(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, int64(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[int64]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", int64(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, int64(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("uint", func(t *testing.T) { v, err := zstrconv.ParseNum[uint]("123") - ztesting.AssertEqual(t, "incorrect parse result", uint(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, uint(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[uint]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", uint(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, uint(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("uint8", func(t *testing.T) { v, err := zstrconv.ParseNum[uint8]("123") - ztesting.AssertEqual(t, "incorrect parse result", uint8(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, uint8(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[uint8]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", uint8(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, uint8(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("uint16", func(t *testing.T) { v, err := zstrconv.ParseNum[uint16]("123") - ztesting.AssertEqual(t, "incorrect parse result", uint16(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, uint16(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[uint16]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", uint16(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, uint16(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("uint32", func(t *testing.T) { v, err := zstrconv.ParseNum[uint32]("123") - ztesting.AssertEqual(t, "incorrect parse result", uint32(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, uint32(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[uint32]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", uint32(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, uint32(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("uint64", func(t *testing.T) { v, err := zstrconv.ParseNum[uint64]("123") - ztesting.AssertEqual(t, "incorrect parse result", uint64(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, uint64(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[uint64]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", uint64(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, uint64(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("uintptr", func(t *testing.T) { v, err := zstrconv.ParseNum[uintptr]("123") - ztesting.AssertEqual(t, "incorrect parse result", uintptr(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, uintptr(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[uintptr]("1234567890123456789012345678901234567890") - ztesting.AssertEqual(t, "incorrect parse result", uintptr(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, uintptr(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("float32", func(t *testing.T) { v, err := zstrconv.ParseNum[float32]("123") - ztesting.AssertEqual(t, "incorrect parse result", float32(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, float32(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[float32]("1.23e+10000") - ztesting.AssertEqual(t, "incorrect parse result", float32(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, float32(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) t.Run("float64", func(t *testing.T) { v, err := zstrconv.ParseNum[float64]("123") - ztesting.AssertEqual(t, "incorrect parse result", float64(123), v) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, float64(123), v) + ztesting.AssertEqual(t, nil, err) vv, err := zstrconv.ParseNum[float64]("1.23e+10000") - ztesting.AssertEqual(t, "incorrect parse result", float64(0), vv) - ztesting.AssertEqualErr(t, "non nil error returned", strconv.ErrRange, err) + ztesting.AssertEqual(t, float64(0), vv) + ztesting.AssertEqualErr(t, strconv.ErrRange, err) }) } @@ -171,7 +171,7 @@ func TestFormatAny(t *testing.T) { for name, tc := range testCase { t.Run(name, func(t *testing.T) { got := zstrconv.FormatAny(tc.a) - ztesting.AssertEqual(t, "wrong string expression", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } diff --git a/zstrings/counte_test.go b/zstrings/counte_test.go index 6e4c7c1..73cdd23 100644 --- a/zstrings/counte_test.go +++ b/zstrings/counte_test.go @@ -28,7 +28,7 @@ func TestCountByteRight(t *testing.T) { for _, tc := range testCases { t.Run(tc.s, func(t *testing.T) { matched := zstrings.CountByteRight(tc.s, tc.b) - ztesting.AssertEqual(t, "wrong match count.", tc.n, matched) + ztesting.AssertEqual(t, tc.n, matched) }) } } @@ -54,7 +54,7 @@ func TestCountByteLeft(t *testing.T) { for _, tc := range testCases { t.Run(tc.s, func(t *testing.T) { matched := zstrings.CountByteLeft(tc.s, tc.b) - ztesting.AssertEqual(t, "wrong match count.", tc.n, matched) + ztesting.AssertEqual(t, tc.n, matched) }) } } diff --git a/zstrings/match_test.go b/zstrings/match_test.go index 5d92cae..a933a54 100644 --- a/zstrings/match_test.go +++ b/zstrings/match_test.go @@ -30,8 +30,8 @@ func TestMatch_error(t *testing.T) { for i, tc := range testCases { t.Run(strconv.Itoa(i), func(t *testing.T) { matched, err := Match(tc.pattern, tc.str) - ztesting.AssertEqual(t, "unexpectedly mismatched.", false, matched) - ztesting.AssertEqual(t, "unexpectedly error.", ErrBadPattern, err) + ztesting.AssertEqual(t, false, matched) + ztesting.AssertEqual(t, ErrBadPattern, err) }) } } @@ -79,8 +79,8 @@ func TestMatch(t *testing.T) { for i, tc := range testCases { t.Run(strconv.Itoa(i), func(t *testing.T) { matched, err := Match(tc.pattern, tc.str) - ztesting.AssertEqual(t, "matched mismatch.", tc.matched, matched) - ztesting.AssertEqual(t, "err mismatch.", tc.err, err) + ztesting.AssertEqual(t, tc.matched, matched) + ztesting.AssertEqual(t, tc.err, err) }) } } @@ -119,9 +119,9 @@ func TestScanChunk(t *testing.T) { for i, tc := range testCases { t.Run(strconv.Itoa(i), func(t *testing.T) { star, chunk, rest := scanChunk(tc.pattern) - ztesting.AssertEqual(t, "star mismatch.", tc.star, star) - ztesting.AssertEqual(t, "chunk mismatch.", tc.chunk, chunk) - ztesting.AssertEqual(t, "rest mismatch.", tc.rest, rest) + ztesting.AssertEqual(t, tc.star, star) + ztesting.AssertEqual(t, tc.chunk, chunk) + ztesting.AssertEqual(t, tc.rest, rest) }) } } @@ -164,8 +164,8 @@ func TestMatchChunk(t *testing.T) { for i, tc := range testCases { t.Run(strconv.Itoa(i), func(t *testing.T) { ok, rest := matchChunk(tc.chunk, tc.str) - ztesting.AssertEqual(t, "unexpected match result.", tc.ok, ok) - ztesting.AssertEqual(t, "rest string is wrong.", tc.rest, rest) + ztesting.AssertEqual(t, tc.ok, ok) + ztesting.AssertEqual(t, tc.rest, rest) }) } } diff --git a/zstrings/strings_test.go b/zstrings/strings_test.go index 61e9598..1405578 100644 --- a/zstrings/strings_test.go +++ b/zstrings/strings_test.go @@ -34,9 +34,9 @@ func TestCutLeftByte(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { before, after, found := zstrings.CutLeftByte(tc.s, tc.c) - ztesting.AssertEqual(t, "before not matched.", tc.before, before) - ztesting.AssertEqual(t, "after not matched.", tc.after, after) - ztesting.AssertEqual(t, "found not matched.", tc.found, found) + ztesting.AssertEqual(t, tc.before, before) + ztesting.AssertEqual(t, tc.after, after) + ztesting.AssertEqual(t, tc.found, found) }) } } @@ -67,9 +67,9 @@ func TestCutRightByte(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { before, after, found := zstrings.CutRightByte(tc.s, tc.c) - ztesting.AssertEqual(t, "before not matched.", tc.before, before) - ztesting.AssertEqual(t, "after not matched.", tc.after, after) - ztesting.AssertEqual(t, "found not matched.", tc.found, found) + ztesting.AssertEqual(t, tc.before, before) + ztesting.AssertEqual(t, tc.after, after) + ztesting.AssertEqual(t, tc.found, found) }) } } @@ -106,9 +106,9 @@ func TestCutLeftRune(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { before, after, found := zstrings.CutLeftRune(tc.s, tc.r) - ztesting.AssertEqual(t, "before not matched.", tc.before, before) - ztesting.AssertEqual(t, "after not matched.", tc.after, after) - ztesting.AssertEqual(t, "found not matched.", tc.found, found) + ztesting.AssertEqual(t, tc.before, before) + ztesting.AssertEqual(t, tc.after, after) + ztesting.AssertEqual(t, tc.found, found) }) } } @@ -145,9 +145,9 @@ func TestCutRightRune(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { before, after, found := zstrings.CutRightRune(tc.s, tc.r) - ztesting.AssertEqual(t, "before not matched.", tc.before, before) - ztesting.AssertEqual(t, "after not matched.", tc.after, after) - ztesting.AssertEqual(t, "found not matched.", tc.found, found) + ztesting.AssertEqual(t, tc.before, before) + ztesting.AssertEqual(t, tc.after, after) + ztesting.AssertEqual(t, tc.found, found) }) } } diff --git a/zsync/runner_test.go b/zsync/runner_test.go index 2c97a66..5f9d1f4 100644 --- a/zsync/runner_test.go +++ b/zsync/runner_test.go @@ -42,16 +42,16 @@ func TestRegisterFunc(t *testing.T) { g := &RunGroup{} g.RegisterFunc(nil) err := g.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("register func", func(t *testing.T) { tr := &testRunner{sleepMillis: 1} g := &RunGroup{} g.RegisterFunc(tr.Run) err := g.Run(context.Background()) - ztesting.AssertEqual(t, "run func is not called", true, tr.isEntered) - ztesting.AssertEqual(t, "run func is not exited", true, tr.isExited) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, true, tr.isEntered) + ztesting.AssertEqual(t, true, tr.isExited) + ztesting.AssertEqualErr(t, nil, err) }) } @@ -60,16 +60,16 @@ func TestRegister(t *testing.T) { g := &RunGroup{} g.Register(nil) err := g.Run(context.Background()) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("register runner", func(t *testing.T) { tr := &testRunner{sleepMillis: 1} g := &RunGroup{} g.Register(tr) err := g.Run(context.Background()) - ztesting.AssertEqual(t, "run func is not called", true, tr.isEntered) - ztesting.AssertEqual(t, "run func is not exited", true, tr.isExited) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, true, tr.isEntered) + ztesting.AssertEqual(t, true, tr.isExited) + ztesting.AssertEqualErr(t, nil, err) }) } @@ -77,16 +77,16 @@ func TestRunAndFailFast(t *testing.T) { t.Run("no runners", func(t *testing.T) { g := &RunGroup{} err := g.RunAndFailFast(context.Background()) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("nil context", func(t *testing.T) { tr := &testRunner{sleepMillis: 1} g := &RunGroup{} g.Register(tr) err := g.RunAndFailFast(nil) - ztesting.AssertEqual(t, "runner is not called", true, tr.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr.isExited) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, true, tr.isEntered) + ztesting.AssertEqual(t, true, tr.isExited) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("nil error", func(t *testing.T) { tr1 := &testRunner{sleepMillis: 100} @@ -94,13 +94,13 @@ func TestRunAndFailFast(t *testing.T) { g := &RunGroup{} g.Register(tr1, tr2) err := g.RunAndFailFast(context.Background()) - ztesting.AssertEqual(t, "runner is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "sleep is not completed", true, tr1.isSleepCompleted) - ztesting.AssertEqual(t, "sleep is not completed", true, tr2.isSleepCompleted) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, true, tr1.isSleepCompleted) + ztesting.AssertEqual(t, true, tr2.isSleepCompleted) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("non nil error 1", func(t *testing.T) { tr1 := &testRunner{sleepMillis: 100, runErr: io.EOF} @@ -108,13 +108,13 @@ func TestRunAndFailFast(t *testing.T) { g := &RunGroup{} g.Register(tr1, tr2) err := g.RunAndFailFast(context.Background()) - ztesting.AssertEqual(t, "runner is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "sleep is not completed", true, tr1.isSleepCompleted) - ztesting.AssertEqual(t, "context is not canceled", true, tr2.isContextCanceled) - ztesting.AssertEqualErr(t, "error not match", io.EOF, err) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, true, tr1.isSleepCompleted) + ztesting.AssertEqual(t, true, tr2.isContextCanceled) + ztesting.AssertEqualErr(t, io.EOF, err) }) t.Run("non nil error 2", func(t *testing.T) { tr1 := &testRunner{sleepMillis: 10_000} @@ -122,13 +122,13 @@ func TestRunAndFailFast(t *testing.T) { g := &RunGroup{} g.Register(tr1, tr2) err := g.RunAndFailFast(context.Background()) - ztesting.AssertEqual(t, "runner is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "sleep is not completed", true, tr2.isSleepCompleted) - ztesting.AssertEqual(t, "context is not canceled", true, tr1.isContextCanceled) - ztesting.AssertEqualErr(t, "error not match", io.EOF, err) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, true, tr2.isSleepCompleted) + ztesting.AssertEqual(t, true, tr1.isContextCanceled) + ztesting.AssertEqualErr(t, io.EOF, err) }) t.Run("runner panic", func(t *testing.T) { tr1 := &testRunner{panicErr: io.EOF} @@ -136,16 +136,16 @@ func TestRunAndFailFast(t *testing.T) { g := &RunGroup{} g.Register(tr1, tr2) err := g.RunAndFailFast(context.Background()) - ztesting.AssertEqual(t, "runner1 is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner1 is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner2 is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner2 is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "runner1 sleep is completed", false, tr1.isSleepCompleted) - ztesting.AssertEqual(t, "runner1 context is canceled", false, tr1.isContextCanceled) - ztesting.AssertEqual(t, "runner2 sleep is completed", false, tr2.isSleepCompleted) - ztesting.AssertEqual(t, "runner2 context is not canceled", true, tr2.isContextCanceled) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, false, tr1.isSleepCompleted) + ztesting.AssertEqual(t, false, tr1.isContextCanceled) + ztesting.AssertEqual(t, false, tr2.isSleepCompleted) + ztesting.AssertEqual(t, true, tr2.isContextCanceled) errStr := errors.New("zsync: runner exit with panic. [EOF]") - ztesting.AssertEqualErr(t, "error not match", errStr, err) // Compare in string. + ztesting.AssertEqualErr(t, errStr, err) // Compare in string. }) } @@ -153,16 +153,16 @@ func TestRunAndWaitAll(t *testing.T) { t.Run("no runners", func(t *testing.T) { g := &RunGroup{} err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("nil context", func(t *testing.T) { tr := &testRunner{sleepMillis: 1} g := &RunGroup{} g.Register(tr) err := g.RunAndWaitAll(nil) - ztesting.AssertEqual(t, "runner is not called", true, tr.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr.isExited) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, true, tr.isEntered) + ztesting.AssertEqual(t, true, tr.isExited) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("nil error", func(t *testing.T) { tr1 := &testRunner{sleepMillis: 100} @@ -170,13 +170,13 @@ func TestRunAndWaitAll(t *testing.T) { g := &RunGroup{} g.Register(tr1, tr2) err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqual(t, "runner is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "sleep is not completed", true, tr1.isSleepCompleted) - ztesting.AssertEqual(t, "sleep is not completed", true, tr2.isSleepCompleted) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, true, tr1.isSleepCompleted) + ztesting.AssertEqual(t, true, tr2.isSleepCompleted) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("non nil error 1", func(t *testing.T) { tr1 := &testRunner{sleepMillis: 100, runErr: io.EOF} @@ -184,13 +184,13 @@ func TestRunAndWaitAll(t *testing.T) { g := &RunGroup{} g.Register(tr1, tr2) err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqual(t, "runner1 is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner1 is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner2 is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner2 is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "runner1 sleep is not completed", true, tr1.isSleepCompleted) - ztesting.AssertEqual(t, "runner2 sleep is not completed", true, tr2.isSleepCompleted) - ztesting.AssertEqualErr(t, "error not match", io.EOF, err) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, true, tr1.isSleepCompleted) + ztesting.AssertEqual(t, true, tr2.isSleepCompleted) + ztesting.AssertEqualErr(t, io.EOF, err) }) t.Run("non nil error 2", func(t *testing.T) { tr1 := &testRunner{sleepMillis: 100} @@ -198,13 +198,13 @@ func TestRunAndWaitAll(t *testing.T) { g := &RunGroup{} g.Register(tr1, tr2) err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqual(t, "runner1 is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner1 is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner2 is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner2 is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "runner1 sleep is not completed", true, tr1.isSleepCompleted) - ztesting.AssertEqual(t, "runner2 sleep is not completed", true, tr2.isSleepCompleted) - ztesting.AssertEqualErr(t, "error not match", io.EOF, err) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, true, tr1.isSleepCompleted) + ztesting.AssertEqual(t, true, tr2.isSleepCompleted) + ztesting.AssertEqualErr(t, io.EOF, err) }) t.Run("1 of 2 runner panics", func(t *testing.T) { tr1 := &testRunner{panicErr: io.EOF} @@ -212,16 +212,16 @@ func TestRunAndWaitAll(t *testing.T) { g := &RunGroup{} g.Register(tr1, tr2) err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqual(t, "runner1 is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner1 is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner2 is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner2 is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "runner1 sleep is completed", false, tr1.isSleepCompleted) - ztesting.AssertEqual(t, "runner1 context is canceled", false, tr1.isContextCanceled) - ztesting.AssertEqual(t, "runner2 sleep is not completed", true, tr2.isSleepCompleted) - ztesting.AssertEqual(t, "runner2 context is canceled", false, tr2.isContextCanceled) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, false, tr1.isSleepCompleted) + ztesting.AssertEqual(t, false, tr1.isContextCanceled) + ztesting.AssertEqual(t, true, tr2.isSleepCompleted) + ztesting.AssertEqual(t, false, tr2.isContextCanceled) errStr := errors.New("zsync: runner exit with panic. [EOF]") - ztesting.AssertEqualErr(t, "error not match", errStr, err) // Compare in string. + ztesting.AssertEqualErr(t, errStr, err) // Compare in string. }) } @@ -233,16 +233,16 @@ func TestAwakeRunner(t *testing.T) { OnStart: func(r Runner) { count.Add(1) rr := r.(*testRunner) - ztesting.AssertEqual(t, "runner has already called", false, rr.isEntered) - ztesting.AssertEqual(t, "runner has already exited", false, rr.isExited) + ztesting.AssertEqual(t, false, rr.isEntered) + ztesting.AssertEqual(t, false, rr.isExited) }, } g.Register(tr) err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqual(t, "OnStart is not called", 1, count.Load()) - ztesting.AssertEqual(t, "runner is not called", true, tr.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr.isExited) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 1, count.Load()) + ztesting.AssertEqual(t, true, tr.isEntered) + ztesting.AssertEqual(t, true, tr.isExited) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("OnExit", func(t *testing.T) { tr := &testRunner{sleepMillis: 1} @@ -251,16 +251,16 @@ func TestAwakeRunner(t *testing.T) { OnExit: func(r Runner, err error) { count.Add(1) rr := r.(*testRunner) - ztesting.AssertEqual(t, "runner has not been called", true, rr.isEntered) - ztesting.AssertEqual(t, "runner has not been exited", true, rr.isExited) + ztesting.AssertEqual(t, true, rr.isEntered) + ztesting.AssertEqual(t, true, rr.isExited) }, } g.Register(tr) err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqual(t, "OnExit is not called", 1, count.Load()) - ztesting.AssertEqual(t, "runner is not called", true, tr.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr.isExited) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 1, count.Load()) + ztesting.AssertEqual(t, true, tr.isEntered) + ztesting.AssertEqual(t, true, tr.isExited) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("OnStart 2 runners", func(t *testing.T) { tr1 := &testRunner{sleepMillis: 1} @@ -270,20 +270,20 @@ func TestAwakeRunner(t *testing.T) { OnStart: func(r Runner) { count.Add(1) rr := r.(*testRunner) - ztesting.AssertEqual(t, "runner has already called", false, rr.isEntered) - ztesting.AssertEqual(t, "runner has already exited", false, rr.isExited) + ztesting.AssertEqual(t, false, rr.isEntered) + ztesting.AssertEqual(t, false, rr.isExited) }, } g.Register(tr1, tr2) err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqual(t, "OnStart is not called", 2, count.Load()) - ztesting.AssertEqual(t, "runner is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "sleep is not completed", true, tr1.isSleepCompleted) - ztesting.AssertEqual(t, "sleep is not completed", true, tr2.isSleepCompleted) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 2, count.Load()) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, true, tr1.isSleepCompleted) + ztesting.AssertEqual(t, true, tr2.isSleepCompleted) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("OnExit 2 runners", func(t *testing.T) { tr1 := &testRunner{sleepMillis: 1} @@ -293,20 +293,20 @@ func TestAwakeRunner(t *testing.T) { OnExit: func(r Runner, err error) { count.Add(1) rr := r.(*testRunner) - ztesting.AssertEqual(t, "runner has not been called", true, rr.isEntered) - ztesting.AssertEqual(t, "runner has not been exited", true, rr.isExited) + ztesting.AssertEqual(t, true, rr.isEntered) + ztesting.AssertEqual(t, true, rr.isExited) }, } g.Register(tr1, tr2) err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqual(t, "OnExit is not called", 2, count.Load()) - ztesting.AssertEqual(t, "runner is not called", true, tr1.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr1.isExited) - ztesting.AssertEqual(t, "runner is not called", true, tr2.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr2.isExited) - ztesting.AssertEqual(t, "sleep is not completed", true, tr1.isSleepCompleted) - ztesting.AssertEqual(t, "sleep is not completed", true, tr2.isSleepCompleted) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 2, count.Load()) + ztesting.AssertEqual(t, true, tr1.isEntered) + ztesting.AssertEqual(t, true, tr1.isExited) + ztesting.AssertEqual(t, true, tr2.isEntered) + ztesting.AssertEqual(t, true, tr2.isExited) + ztesting.AssertEqual(t, true, tr1.isSleepCompleted) + ztesting.AssertEqual(t, true, tr2.isSleepCompleted) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("OnExit with panic", func(t *testing.T) { tr := &testRunner{panicErr: io.EOF} // Panics dummy error. @@ -315,29 +315,29 @@ func TestAwakeRunner(t *testing.T) { OnExit: func(r Runner, err error) { count.Add(1) rr := r.(*testRunner) - ztesting.AssertEqual(t, "runner has not been called", true, rr.isEntered) - ztesting.AssertEqual(t, "runner has not been exited", true, rr.isExited) + ztesting.AssertEqual(t, true, rr.isEntered) + ztesting.AssertEqual(t, true, rr.isExited) }, } g.Register(tr) err := g.RunAndWaitAll(context.Background()) - ztesting.AssertEqual(t, "OnExit is not called", 1, count.Load()) - ztesting.AssertEqual(t, "runner is not called", true, tr.isEntered) - ztesting.AssertEqual(t, "runner is not exited", true, tr.isExited) - ztesting.AssertEqualErr(t, "error not match", io.EOF, err) + ztesting.AssertEqual(t, 1, count.Load()) + ztesting.AssertEqual(t, true, tr.isEntered) + ztesting.AssertEqual(t, true, tr.isExited) + ztesting.AssertEqualErr(t, io.EOF, err) }) t.Run("panics string", func(t *testing.T) { g := &RunGroup{} g.RegisterFunc(func(ctx context.Context) error { panic("string panic") }) err := g.RunAndWaitAll(context.Background()) errStr := errors.New("zsync: runner exit with panic. [string panic]") - ztesting.AssertEqualErr(t, "error not match", errStr, err) // Compare in string. + ztesting.AssertEqualErr(t, errStr, err) // Compare in string. }) t.Run("panics error", func(t *testing.T) { g := &RunGroup{} g.RegisterFunc(func(ctx context.Context) error { panic(io.EOF) }) err := g.RunAndWaitAll(context.Background()) errStr := errors.New("zsync: runner exit with panic. [EOF]") - ztesting.AssertEqualErr(t, "error not match", errStr, err) // Compare in string. + ztesting.AssertEqualErr(t, errStr, err) // Compare in string. }) } diff --git a/zsync/store_test.go b/zsync/store_test.go index 59c07b5..b7f2c56 100644 --- a/zsync/store_test.go +++ b/zsync/store_test.go @@ -38,108 +38,108 @@ func TestLoad(t *testing.T) { store := newTestStore() t.Run("not found", func(t *testing.T) { val, ok := zsync.Load[any, string](store, "not found") - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", "", val) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, "", val) }) t.Run("primitive assertion failed", func(t *testing.T) { val, ok := zsync.Load[any, string](store, "nil") - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", "", val) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, "", val) }) t.Run("interface assertion failed", func(t *testing.T) { val, ok := zsync.Load[any, error](store, "nil") - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", nil, val) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, nil, val) }) t.Run("load string", func(t *testing.T) { val, ok := zsync.Load[any, string](store, "string") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", "abc", val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, "abc", val) }) t.Run("load int", func(t *testing.T) { val, ok := zsync.Load[any, int](store, "int") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int(-123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int(-123), val) }) t.Run("load int8", func(t *testing.T) { val, ok := zsync.Load[any, int8](store, "int8") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int8(-123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int8(-123), val) }) t.Run("load int16", func(t *testing.T) { val, ok := zsync.Load[any, int16](store, "int16") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int16(-123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int16(-123), val) }) t.Run("load int32", func(t *testing.T) { val, ok := zsync.Load[any, int32](store, "int32") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int32(-123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int32(-123), val) }) t.Run("load int64", func(t *testing.T) { val, ok := zsync.Load[any, int64](store, "int64") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int64(-123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int64(-123), val) }) t.Run("load uint", func(t *testing.T) { val, ok := zsync.Load[any, uint](store, "uint") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint(123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint(123), val) }) t.Run("load uint8", func(t *testing.T) { val, ok := zsync.Load[any, uint8](store, "uint8") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint8(123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint8(123), val) }) t.Run("load uint16", func(t *testing.T) { val, ok := zsync.Load[any, uint16](store, "uint16") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint16(123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint16(123), val) }) t.Run("load uint32", func(t *testing.T) { val, ok := zsync.Load[any, uint32](store, "uint32") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint32(123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint32(123), val) }) t.Run("load uint64", func(t *testing.T) { val, ok := zsync.Load[any, uint64](store, "uint64") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint64(123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint64(123), val) }) t.Run("load uintptr", func(t *testing.T) { val, ok := zsync.Load[any, uintptr](store, "uintptr") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uintptr(123), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uintptr(123), val) }) t.Run("load float32", func(t *testing.T) { val, ok := zsync.Load[any, float32](store, "float32") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", float32(123.45), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, float32(123.45), val) }) t.Run("load float64", func(t *testing.T) { val, ok := zsync.Load[any, float64](store, "float64") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", float64(123.45), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, float64(123.45), val) }) t.Run("load complex64", func(t *testing.T) { val, ok := zsync.Load[any, complex64](store, "complex64") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", complex64(1+2i), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, complex64(1+2i), val) }) t.Run("load complex128", func(t *testing.T) { val, ok := zsync.Load[any, complex128](store, "complex128") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", complex128(1+2i), val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, complex128(1+2i), val) }) t.Run("load error", func(t *testing.T) { val, ok := zsync.Load[any, error](store, "EOF") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", io.EOF, val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, io.EOF, val) }) t.Run("load struct", func(t *testing.T) { val, ok := zsync.Load[any, struct{}](store, "struct") - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", struct{}{}, val) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, struct{}{}, val) }) } @@ -148,173 +148,173 @@ func TestSwap(t *testing.T) { store := newTestStore() t.Run("not found", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, string](store, "not found", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", false, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", "", prev) + ztesting.AssertEqual(t, false, loaded) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, "", prev) v, _ := store.Load("not found") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("primitive assertion failed", func(t *testing.T) { store.Store("nil", nil) prev, loaded, ok := zsync.Swap[any, string](store, "nil", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", "", prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, "", prev) v, _ := store.Load("nil") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("interface assertion failed", func(t *testing.T) { store.Store("nil", nil) prev, loaded, ok := zsync.Swap[any, error](store, "nil", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", nil, prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, nil, prev) v, _ := store.Load("nil") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap string", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, string](store, "string", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", "abc", prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, "abc", prev) v, _ := store.Load("string") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap int", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, int](store, "int", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int(-123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int(-123), prev) v, _ := store.Load("int") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap int8", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, int8](store, "int8", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int8(-123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int8(-123), prev) v, _ := store.Load("int8") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap int16", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, int16](store, "int16", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int16(-123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int16(-123), prev) v, _ := store.Load("int16") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap int32", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, int32](store, "int32", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int32(-123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int32(-123), prev) v, _ := store.Load("int32") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap int64", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, int64](store, "int64", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int64(-123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int64(-123), prev) v, _ := store.Load("int64") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap uint", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, uint](store, "uint", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint(123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint(123), prev) v, _ := store.Load("uint") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap uint8", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, uint8](store, "uint8", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint8(123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint8(123), prev) v, _ := store.Load("uint8") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap uint16", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, uint16](store, "uint16", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint16(123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint16(123), prev) v, _ := store.Load("uint16") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap uint32", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, uint32](store, "uint32", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint32(123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint32(123), prev) v, _ := store.Load("uint32") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap uint64", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, uint64](store, "uint64", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint64(123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint64(123), prev) v, _ := store.Load("uint64") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap uintptr", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, uintptr](store, "uintptr", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uintptr(123), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uintptr(123), prev) v, _ := store.Load("uintptr") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap float32", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, float32](store, "float32", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", float32(123.45), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, float32(123.45), prev) v, _ := store.Load("float32") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap float64", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, float64](store, "float64", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", float64(123.45), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, float64(123.45), prev) v, _ := store.Load("float64") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap complex64", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, complex64](store, "complex64", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", complex64(1+2i), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, complex64(1+2i), prev) v, _ := store.Load("complex64") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap complex128", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, complex128](store, "complex128", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", complex128(1+2i), prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, complex128(1+2i), prev) v, _ := store.Load("complex128") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap error", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, error](store, "EOF", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", io.EOF, prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, io.EOF, prev) v, _ := store.Load("EOF") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) t.Run("swap struct", func(t *testing.T) { prev, loaded, ok := zsync.Swap[any, struct{}](store, "struct", "swapped") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", struct{}{}, prev) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, struct{}{}, prev) v, _ := store.Load("struct") - ztesting.AssertEqual(t, "value matched.", "swapped", v) + ztesting.AssertEqual(t, "swapped", v) }) } @@ -323,173 +323,173 @@ func TestLoadAndDelete(t *testing.T) { store := newTestStore() t.Run("not found", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, string](store, "not found") - ztesting.AssertEqual(t, "wrong result of loaded.", false, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", "", val) + ztesting.AssertEqual(t, false, loaded) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, "", val) _, found := store.Load("not found") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("primitive assertion failed", func(t *testing.T) { store.Store("nil", nil) val, loaded, ok := zsync.LoadAndDelete[any, string](store, "nil") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", "", val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, "", val) _, found := store.Load("nil") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("interface assertion failed", func(t *testing.T) { store.Store("nil", nil) val, loaded, ok := zsync.LoadAndDelete[any, error](store, "nil") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", nil, val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, nil, val) _, found := store.Load("nil") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("string", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, string](store, "string") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", "abc", val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, "abc", val) _, found := store.Load("string") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("int", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, int](store, "int") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int(-123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int(-123), val) _, found := store.Load("int") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("int8", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, int8](store, "int8") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int8(-123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int8(-123), val) _, found := store.Load("int8") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("int16", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, int16](store, "int16") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int16(-123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int16(-123), val) _, found := store.Load("int16") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("int32", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, int32](store, "int32") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int32(-123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int32(-123), val) _, found := store.Load("int32") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("int64", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, int64](store, "int64") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int64(-123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int64(-123), val) _, found := store.Load("nil") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("uint", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, uint](store, "uint") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint(123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint(123), val) _, found := store.Load("nil") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("uint8", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, uint8](store, "uint8") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint8(123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint8(123), val) _, found := store.Load("uint8") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("uint16", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, uint16](store, "uint16") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint16(123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint16(123), val) _, found := store.Load("uint16") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("uint32", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, uint32](store, "uint32") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint32(123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint32(123), val) _, found := store.Load("uint32") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("uint64", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, uint64](store, "uint64") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint64(123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint64(123), val) _, found := store.Load("uint64") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("uintptr", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, uintptr](store, "uintptr") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uintptr(123), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uintptr(123), val) _, found := store.Load("uintptr") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("float32", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, float32](store, "float32") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", float32(123.45), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, float32(123.45), val) _, found := store.Load("float32") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("float64", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, float64](store, "float64") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", float64(123.45), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, float64(123.45), val) _, found := store.Load("float64") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("complex64", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, complex64](store, "complex64") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", complex64(1+2i), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, complex64(1+2i), val) _, found := store.Load("complex64") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("complex128", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, complex128](store, "complex128") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", complex128(1+2i), val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, complex128(1+2i), val) _, found := store.Load("complex128") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("error", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, error](store, "EOF") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", io.EOF, val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, io.EOF, val) _, found := store.Load("EOF") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("struct", func(t *testing.T) { val, loaded, ok := zsync.LoadAndDelete[any, struct{}](store, "struct") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", struct{}{}, val) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, struct{}{}, val) _, found := store.Load("struct") - ztesting.AssertEqual(t, "value not deleted.", false, found) + ztesting.AssertEqual(t, false, found) }) } @@ -498,172 +498,172 @@ func TestLoadOrStore(t *testing.T) { store := newTestStore() t.Run("not found", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, string](store, "not found", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", false, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", "", actual) + ztesting.AssertEqual(t, false, loaded) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, "", actual) v, _ := store.Load("not found") - ztesting.AssertEqual(t, "value matched.", "stored", v) + ztesting.AssertEqual(t, "stored", v) }) t.Run("primitive assertion failed", func(t *testing.T) { store.Store("nil", nil) actual, loaded, ok := zsync.LoadOrStore[any, string](store, "nil", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", "", actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, "", actual) v, _ := store.Load("nil") - ztesting.AssertEqual(t, "value matched.", nil, v) + ztesting.AssertEqual(t, nil, v) }) t.Run("interface assertion failed", func(t *testing.T) { store.Store("nil", nil) actual, loaded, ok := zsync.LoadOrStore[any, error](store, "nil", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", false, ok) - ztesting.AssertEqual(t, "value matched.", nil, actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, nil, actual) v, _ := store.Load("nil") - ztesting.AssertEqual(t, "value matched.", nil, v) + ztesting.AssertEqual(t, nil, v) }) t.Run("string", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, string](store, "string", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", "abc", actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, "abc", actual) v, _ := store.Load("string") - ztesting.AssertEqual(t, "value matched.", "abc", v) + ztesting.AssertEqual(t, "abc", v) }) t.Run("int", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, int](store, "int", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int(-123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int(-123), actual) v, _ := store.Load("int") - ztesting.AssertEqual(t, "value matched.", any(int(-123)), v) + ztesting.AssertEqual(t, any(int(-123)), v) }) t.Run("int8", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, int8](store, "int8", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int8(-123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int8(-123), actual) v, _ := store.Load("int8") - ztesting.AssertEqual(t, "value matched.", any(int8(-123)), v) + ztesting.AssertEqual(t, any(int8(-123)), v) }) t.Run("int16", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, int16](store, "int16", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int16(-123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int16(-123), actual) v, _ := store.Load("int16") - ztesting.AssertEqual(t, "value matched.", any(int16(-123)), v) + ztesting.AssertEqual(t, any(int16(-123)), v) }) t.Run("int32", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, int32](store, "int32", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int32(-123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int32(-123), actual) v, _ := store.Load("int32") - ztesting.AssertEqual(t, "value matched.", any(int32(-123)), v) + ztesting.AssertEqual(t, any(int32(-123)), v) }) t.Run("int64", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, int64](store, "int64", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", int64(-123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, int64(-123), actual) v, _ := store.Load("int64") - ztesting.AssertEqual(t, "value matched.", any(int64(-123)), v) + ztesting.AssertEqual(t, any(int64(-123)), v) }) t.Run("uint", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, uint](store, "uint", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint(123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint(123), actual) v, _ := store.Load("uint") - ztesting.AssertEqual(t, "value matched.", any(uint(123)), v) + ztesting.AssertEqual(t, any(uint(123)), v) }) t.Run("uint8", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, uint8](store, "uint8", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint8(123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint8(123), actual) v, _ := store.Load("uint8") - ztesting.AssertEqual(t, "value matched.", any(uint8(123)), v) + ztesting.AssertEqual(t, any(uint8(123)), v) }) t.Run("uint16", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, uint16](store, "uint16", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint16(123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint16(123), actual) v, _ := store.Load("uint16") - ztesting.AssertEqual(t, "value matched.", any(uint16(123)), v) + ztesting.AssertEqual(t, any(uint16(123)), v) }) t.Run("uint32", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, uint32](store, "uint32", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint32(123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint32(123), actual) v, _ := store.Load("uint32") - ztesting.AssertEqual(t, "value matched.", any(uint32(123)), v) + ztesting.AssertEqual(t, any(uint32(123)), v) }) t.Run("uint64", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, uint64](store, "uint64", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uint64(123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uint64(123), actual) v, _ := store.Load("uint64") - ztesting.AssertEqual(t, "value matched.", any(uint64(123)), v) + ztesting.AssertEqual(t, any(uint64(123)), v) }) t.Run("uintptr", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, uintptr](store, "uintptr", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", uintptr(123), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, uintptr(123), actual) v, _ := store.Load("uintptr") - ztesting.AssertEqual(t, "value matched.", any(uintptr(123)), v) + ztesting.AssertEqual(t, any(uintptr(123)), v) }) t.Run("float32", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, float32](store, "float32", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", float32(123.45), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, float32(123.45), actual) v, _ := store.Load("float32") - ztesting.AssertEqual(t, "value matched.", any(float32(123.45)), v) + ztesting.AssertEqual(t, any(float32(123.45)), v) }) t.Run("float64", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, float64](store, "float64", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", float64(123.45), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, float64(123.45), actual) v, _ := store.Load("float64") - ztesting.AssertEqual(t, "value matched.", any(float64(123.45)), v) + ztesting.AssertEqual(t, any(float64(123.45)), v) }) t.Run("complex64", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, complex64](store, "complex64", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", complex64(1+2i), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, complex64(1+2i), actual) v, _ := store.Load("complex64") - ztesting.AssertEqual(t, "value matched.", any(complex64(1+2i)), v) + ztesting.AssertEqual(t, any(complex64(1+2i)), v) }) t.Run("complex128", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, complex128](store, "complex128", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", complex128(1+2i), actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, complex128(1+2i), actual) v, _ := store.Load("complex128") - ztesting.AssertEqual(t, "value matched.", any(complex128(1+2i)), v) + ztesting.AssertEqual(t, any(complex128(1+2i)), v) }) t.Run("error", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, error](store, "EOF", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", io.EOF, actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, io.EOF, actual) v, _ := store.Load("EOF") - ztesting.AssertEqual(t, "value matched.", any(io.EOF), v) + ztesting.AssertEqual(t, any(io.EOF), v) }) t.Run("struct", func(t *testing.T) { actual, loaded, ok := zsync.LoadOrStore[any, struct{}](store, "struct", "stored") - ztesting.AssertEqual(t, "wrong result of loaded.", true, loaded) - ztesting.AssertEqual(t, "wrong result of ok.", true, ok) - ztesting.AssertEqual(t, "value matched.", struct{}{}, actual) + ztesting.AssertEqual(t, true, loaded) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, struct{}{}, actual) v, _ := store.Load("struct") - ztesting.AssertEqual(t, "value matched.", any(struct{}{}), v) + ztesting.AssertEqual(t, any(struct{}{}), v) }) } diff --git a/zsyscall/sockopt_linux_test.go b/zsyscall/sockopt_linux_test.go index be35505..fe99b6a 100644 --- a/zsyscall/sockopt_linux_test.go +++ b/zsyscall/sockopt_linux_test.go @@ -30,7 +30,7 @@ func TestSockSOOption_Controllers(t *testing.T) { SendBufferForce: 18, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 14, len(cs)) + ztesting.AssertEqual(t, 14, len(cs)) } func TestSockIPOption_Controllers(t *testing.T) { @@ -44,7 +44,7 @@ func TestSockIPOption_Controllers(t *testing.T) { TTL: 12, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 5, len(cs)) + ztesting.AssertEqual(t, 5, len(cs)) } func TestSockIPV6Option_Controllers(t *testing.T) { @@ -53,7 +53,7 @@ func TestSockIPV6Option_Controllers(t *testing.T) { V6Only: true, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 1, len(cs)) + ztesting.AssertEqual(t, 1, len(cs)) } func TestSockTCPOption_Controllers(t *testing.T) { @@ -75,7 +75,7 @@ func TestSockTCPOption_Controllers(t *testing.T) { FastOpenConnect: true, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 14, len(cs)) + ztesting.AssertEqual(t, 14, len(cs)) } func TestSockUDPOption_Controllers(t *testing.T) { @@ -86,7 +86,7 @@ func TestSockUDPOption_Controllers(t *testing.T) { GRO: true, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 3, len(cs)) + ztesting.AssertEqual(t, 3, len(cs)) } func TestSoBindToIFindex(t *testing.T) { @@ -95,17 +95,17 @@ func TestSoBindToIFindex(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soBindToIFindex(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", SO_BINDTOIFINDEX, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, SO_BINDTOIFINDEX, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soBindToIFindex(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -113,7 +113,7 @@ func TestSoBindToIFindex(t *testing.T) { } c := soBindToIFindex(1) want := &SocketError{Opts: "SOL_SOCKET.SO_BINDTOIFINDEX"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -123,17 +123,17 @@ func TestSoBindToDevice(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soBindToDevice("") - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptString = func(fd int, level, opt int, s string) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_BINDTODEVICE, opt) - ztesting.AssertEqual(t, "value not match", "eth0", s) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_BINDTODEVICE, opt) + ztesting.AssertEqual(t, "eth0", s) return nil } c := soBindToDevice("eth0") - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptString = func(fd int, level, opt int, s string) (err error) { @@ -141,7 +141,7 @@ func TestSoBindToDevice(t *testing.T) { } c := soBindToDevice("eth0") want := &SocketError{Opts: "SOL_SOCKET.SO_BINDTODEVICE"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -151,17 +151,17 @@ func TestSoDebug(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soDebug(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_DEBUG, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_DEBUG, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soDebug(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -169,7 +169,7 @@ func TestSoDebug(t *testing.T) { } c := soDebug(true) want := &SocketError{Opts: "SOL_SOCKET.SO_DEBUG"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -179,17 +179,17 @@ func TestSoKeepAlive(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soKeepAlive(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_KEEPALIVE, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_KEEPALIVE, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soKeepAlive(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -197,7 +197,7 @@ func TestSoKeepAlive(t *testing.T) { } c := soKeepAlive(true) want := &SocketError{Opts: "SOL_SOCKET.SO_KEEPALIVE"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -207,29 +207,29 @@ func TestSoLinger(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soLinger(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("on", func(t *testing.T) { setsockoptLinger = func(fd int, level, opt int, l *syscall.Linger) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_LINGER, opt) - ztesting.AssertEqual(t, "onoff not match", 1, l.Onoff) - ztesting.AssertEqual(t, "linger not match", 9, l.Linger) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_LINGER, opt) + ztesting.AssertEqual(t, 1, l.Onoff) + ztesting.AssertEqual(t, 9, l.Linger) return nil } c := soLinger(9) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("off", func(t *testing.T) { setsockoptLinger = func(fd int, level, opt int, l *syscall.Linger) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_LINGER, opt) - ztesting.AssertEqual(t, "onoff not match", 0, l.Onoff) - ztesting.AssertEqual(t, "linger not match", 0, l.Linger) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_LINGER, opt) + ztesting.AssertEqual(t, 0, l.Onoff) + ztesting.AssertEqual(t, 0, l.Linger) return nil } c := soLinger(-9) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptLinger = func(fd int, level, opt int, l *syscall.Linger) (err error) { @@ -237,7 +237,7 @@ func TestSoLinger(t *testing.T) { } c := soLinger(9) want := &SocketError{Opts: "SOL_SOCKET.SO_LINGER"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -247,17 +247,17 @@ func TestSoMark(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soMark(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_MARK, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_MARK, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soMark(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -265,7 +265,7 @@ func TestSoMark(t *testing.T) { } c := soMark(1) want := &SocketError{Opts: "SOL_SOCKET.SO_MARK"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -275,17 +275,17 @@ func TestSoRcvbuf(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soRcvbuf(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_RCVBUF, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_RCVBUF, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soRcvbuf(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -293,7 +293,7 @@ func TestSoRcvbuf(t *testing.T) { } c := soRcvbuf(1) want := &SocketError{Opts: "SOL_SOCKET.SO_RCVBUF"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -303,17 +303,17 @@ func TestSoRcvbufForce(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soRcvbufForce(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_RCVBUFFORCE, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_RCVBUFFORCE, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soRcvbufForce(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -321,7 +321,7 @@ func TestSoRcvbufForce(t *testing.T) { } c := soRcvbufForce(1) want := &SocketError{Opts: "SOL_SOCKET.SO_RCVBUFFORCE"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -331,17 +331,17 @@ func TestSoSndbuf(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soSndbuf(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_SNDBUF, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_SNDBUF, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soSndbuf(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -349,7 +349,7 @@ func TestSoSndbuf(t *testing.T) { } c := soSndbuf(1) want := &SocketError{Opts: "SOL_SOCKET.SO_SNDBUF"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -359,17 +359,17 @@ func TestSoSndbufForce(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soSndbufForce(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_SNDBUFFORCE, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_SNDBUFFORCE, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soSndbufForce(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -377,7 +377,7 @@ func TestSoSndbufForce(t *testing.T) { } c := soSndbufForce(1) want := &SocketError{Opts: "SOL_SOCKET.SO_SNDBUFFORCE"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -387,17 +387,17 @@ func TestSoSndtimeo(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soSndtimeo(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptTimeval = func(fd int, level, opt int, tv *syscall.Timeval) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_SNDTIMEO, opt) - ztesting.AssertEqual(t, "value not match", syscall.NsecToTimeval(int64(time.Second)), *tv) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_SNDTIMEO, opt) + ztesting.AssertEqual(t, syscall.NsecToTimeval(int64(time.Second)), *tv) return nil } c := soSndtimeo(time.Second) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptTimeval = func(fd int, level, opt int, tv *syscall.Timeval) (err error) { @@ -405,7 +405,7 @@ func TestSoSndtimeo(t *testing.T) { } c := soSndtimeo(time.Second) want := &SocketError{Opts: "SOL_SOCKET.SO_SNDTIMEO"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -415,17 +415,17 @@ func TestSoRcvtimeo(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soRcvtimeo(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptTimeval = func(fd int, level, opt int, tv *syscall.Timeval) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_RCVTIMEO, opt) - ztesting.AssertEqual(t, "value not match", syscall.NsecToTimeval(int64(time.Second)), *tv) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_RCVTIMEO, opt) + ztesting.AssertEqual(t, syscall.NsecToTimeval(int64(time.Second)), *tv) return nil } c := soRcvtimeo(time.Second) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptTimeval = func(fd int, level, opt int, tv *syscall.Timeval) (err error) { @@ -433,7 +433,7 @@ func TestSoRcvtimeo(t *testing.T) { } c := soRcvtimeo(time.Second) want := &SocketError{Opts: "SOL_SOCKET.SO_RCVTIMEO"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -443,17 +443,17 @@ func TestSoReuseaddr(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soReuseaddr(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_REUSEADDR, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_REUSEADDR, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soReuseaddr(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -461,7 +461,7 @@ func TestSoReuseaddr(t *testing.T) { } c := soReuseaddr(true) want := &SocketError{Opts: "SOL_SOCKET.SO_REUSEADDR"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -471,17 +471,17 @@ func TestSoReuseport(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soReuseport(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", SO_REUSEPORT, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, SO_REUSEPORT, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soReuseport(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -489,7 +489,7 @@ func TestSoReuseport(t *testing.T) { } c := soReuseport(true) want := &SocketError{Opts: "SOL_SOCKET.SO_REUSEPORT"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -499,17 +499,17 @@ func TestIPBindAddressNoPort(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := ipBindAddressNoPort(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_IP, level) - ztesting.AssertEqual(t, "option not match", IP_BIND_ADDRESS_NO_PORT, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_IP, level) + ztesting.AssertEqual(t, IP_BIND_ADDRESS_NO_PORT, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := ipBindAddressNoPort(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -517,7 +517,7 @@ func TestIPBindAddressNoPort(t *testing.T) { } c := ipBindAddressNoPort(true) want := &SocketError{Opts: "IPPROTO_IP.IP_BIND_ADDRESS_NO_PORT"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -527,17 +527,17 @@ func TestIPFreeBind(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := ipFreeBind(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_IP, level) - ztesting.AssertEqual(t, "option not match", syscall.IP_FREEBIND, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_IP, level) + ztesting.AssertEqual(t, syscall.IP_FREEBIND, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := ipFreeBind(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -545,7 +545,7 @@ func TestIPFreeBind(t *testing.T) { } c := ipFreeBind(true) want := &SocketError{Opts: "IPPROTO_IP.IP_FREEBIND"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -555,17 +555,17 @@ func TestIPLocalPortRange(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := ipLocalPortRange(0, 0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_IP, level) - ztesting.AssertEqual(t, "option not match", IP_LOCAL_PORT_RANGE, opt) - ztesting.AssertEqual(t, "value not match", int(uint32(2048)<<16|uint32(2000)), value) + ztesting.AssertEqual(t, syscall.IPPROTO_IP, level) + ztesting.AssertEqual(t, IP_LOCAL_PORT_RANGE, opt) + ztesting.AssertEqual(t, int(uint32(2048)<<16|uint32(2000)), value) return nil } c := ipLocalPortRange(2048, 2000) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -573,7 +573,7 @@ func TestIPLocalPortRange(t *testing.T) { } c := ipLocalPortRange(2048, 2000) want := &SocketError{Opts: "IPPROTO_IP.IP_LOCAL_PORT_RANGE"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -583,17 +583,17 @@ func TestIPTransparent(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := ipTransparent(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_IP, level) - ztesting.AssertEqual(t, "option not match", syscall.IP_TRANSPARENT, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_IP, level) + ztesting.AssertEqual(t, syscall.IP_TRANSPARENT, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := ipTransparent(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -601,7 +601,7 @@ func TestIPTransparent(t *testing.T) { } c := ipTransparent(true) want := &SocketError{Opts: "IPPROTO_IP.IP_TRANSPARENT"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -611,17 +611,17 @@ func TestIPTTL(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := ipTTL(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_IP, level) - ztesting.AssertEqual(t, "option not match", syscall.IP_TTL, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_IP, level) + ztesting.AssertEqual(t, syscall.IP_TTL, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := ipTTL(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -629,7 +629,7 @@ func TestIPTTL(t *testing.T) { } c := ipTTL(1) want := &SocketError{Opts: "IPPROTO_IP.IP_TTL"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -639,17 +639,17 @@ func TestIPV6V6Only(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := ipv6V6Only(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_IPV6, level) - ztesting.AssertEqual(t, "option not match", syscall.IPV6_V6ONLY, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_IPV6, level) + ztesting.AssertEqual(t, syscall.IPV6_V6ONLY, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := ipv6V6Only(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -657,7 +657,7 @@ func TestIPV6V6Only(t *testing.T) { } c := ipv6V6Only(true) want := &SocketError{Opts: "IPPROTO_IPV6.IPV6_V6ONLY"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -667,17 +667,17 @@ func TestTCPCORK(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpCORK(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_CORK, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_CORK, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpCORK(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -685,7 +685,7 @@ func TestTCPCORK(t *testing.T) { } c := tcpCORK(true) want := &SocketError{Opts: "IPPROTO_TCP.TCP_CORK"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -695,17 +695,17 @@ func TestTCPDeferAccept(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpDeferAccept(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_DEFER_ACCEPT, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_DEFER_ACCEPT, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpDeferAccept(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -713,7 +713,7 @@ func TestTCPDeferAccept(t *testing.T) { } c := tcpDeferAccept(1) want := &SocketError{Opts: "IPPROTO_TCP.TCP_DEFER_ACCEPT"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -723,17 +723,17 @@ func TestTCPKeepCount(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpKeepCount(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_KEEPCNT, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_KEEPCNT, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpKeepCount(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -741,7 +741,7 @@ func TestTCPKeepCount(t *testing.T) { } c := tcpKeepCount(1) want := &SocketError{Opts: "IPPROTO_TCP.TCP_KEEPCNT"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -751,17 +751,17 @@ func TestTCPKeepIdle(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpKeepIdle(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_KEEPIDLE, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_KEEPIDLE, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpKeepIdle(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -769,7 +769,7 @@ func TestTCPKeepIdle(t *testing.T) { } c := tcpKeepIdle(1) want := &SocketError{Opts: "IPPROTO_TCP.TCP_KEEPIDLE"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -779,17 +779,17 @@ func TestTCPKeepInterval(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpKeepInterval(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_KEEPINTVL, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_KEEPINTVL, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpKeepInterval(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -797,7 +797,7 @@ func TestTCPKeepInterval(t *testing.T) { } c := tcpKeepInterval(1) want := &SocketError{Opts: "IPPROTO_TCP.TCP_KEEPINTVL"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -807,29 +807,29 @@ func TestTCPLinger2(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpLinger2(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("on", func(t *testing.T) { setsockoptLinger = func(fd int, level, opt int, l *syscall.Linger) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_LINGER2, opt) - ztesting.AssertEqual(t, "onoff not match", 1, l.Onoff) - ztesting.AssertEqual(t, "linger not match", 9, l.Linger) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_LINGER2, opt) + ztesting.AssertEqual(t, 1, l.Onoff) + ztesting.AssertEqual(t, 9, l.Linger) return nil } c := tcpLinger2(9) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("off", func(t *testing.T) { setsockoptLinger = func(fd int, level, opt int, l *syscall.Linger) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_LINGER2, opt) - ztesting.AssertEqual(t, "onoff not match", 0, l.Onoff) - ztesting.AssertEqual(t, "linger not match", 0, l.Linger) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_LINGER2, opt) + ztesting.AssertEqual(t, 0, l.Onoff) + ztesting.AssertEqual(t, 0, l.Linger) return nil } c := tcpLinger2(-9) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptLinger = func(fd int, level, opt int, l *syscall.Linger) (err error) { @@ -837,7 +837,7 @@ func TestTCPLinger2(t *testing.T) { } c := tcpLinger2(9) want := &SocketError{Opts: "IPPROTO_TCP.TCP_LINGER2"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -847,17 +847,17 @@ func TestTCPMaxSegment(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpMaxSegment(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_MAXSEG, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_MAXSEG, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpMaxSegment(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -865,7 +865,7 @@ func TestTCPMaxSegment(t *testing.T) { } c := tcpMaxSegment(1) want := &SocketError{Opts: "IPPROTO_TCP.TCP_MAXSEG"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -875,17 +875,17 @@ func TestTCPNoDelay(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpNoDelay(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_NODELAY, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_NODELAY, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpNoDelay(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -893,7 +893,7 @@ func TestTCPNoDelay(t *testing.T) { } c := tcpNoDelay(true) want := &SocketError{Opts: "IPPROTO_TCP.TCP_NODELAY"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -903,17 +903,17 @@ func TestTCPQuickAck(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpQuickAck(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_QUICKACK, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_QUICKACK, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpQuickAck(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -921,7 +921,7 @@ func TestTCPQuickAck(t *testing.T) { } c := tcpQuickAck(true) want := &SocketError{Opts: "IPPROTO_TCP.TCP_QUICKACK"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -931,17 +931,17 @@ func TestTCPSynCount(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpSynCount(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_SYNCNT, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_SYNCNT, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpSynCount(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -949,7 +949,7 @@ func TestTCPSynCount(t *testing.T) { } c := tcpSynCount(1) want := &SocketError{Opts: "IPPROTO_TCP.TCP_SYNCNT"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -959,17 +959,17 @@ func TestTCPUserTimeout(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpUserTimeout(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", TCP_USER_TIMEOUT, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, TCP_USER_TIMEOUT, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpUserTimeout(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -977,7 +977,7 @@ func TestTCPUserTimeout(t *testing.T) { } c := tcpUserTimeout(1) want := &SocketError{Opts: "IPPROTO_TCP.TCP_USER_TIMEOUT"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -987,17 +987,17 @@ func TestTCPWindowClamp(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpWindowClamp(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_WINDOW_CLAMP, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_WINDOW_CLAMP, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpWindowClamp(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -1005,7 +1005,7 @@ func TestTCPWindowClamp(t *testing.T) { } c := tcpWindowClamp(1) want := &SocketError{Opts: "IPPROTO_TCP.TCP_WINDOW_CLAMP"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -1015,17 +1015,17 @@ func TestTCPFastOpen(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpFastOpen(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", TCP_FASTOPEN, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, TCP_FASTOPEN, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpFastOpen(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -1033,7 +1033,7 @@ func TestTCPFastOpen(t *testing.T) { } c := tcpFastOpen(true) want := &SocketError{Opts: "IPPROTO_TCP.TCP_FASTOPEN"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -1043,17 +1043,17 @@ func TestTCPFastOpenConnect(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpFastOpenConnect(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", TCP_FASTOPEN_CONNECT, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, TCP_FASTOPEN_CONNECT, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpFastOpenConnect(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -1061,7 +1061,7 @@ func TestTCPFastOpenConnect(t *testing.T) { } c := tcpFastOpenConnect(true) want := &SocketError{Opts: "IPPROTO_TCP.TCP_FASTOPEN_CONNECT"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -1071,17 +1071,17 @@ func TestUDPCORK(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := udpCORK(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_UDP, level) - ztesting.AssertEqual(t, "option not match", UDP_CORK, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_UDP, level) + ztesting.AssertEqual(t, UDP_CORK, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := udpCORK(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -1089,7 +1089,7 @@ func TestUDPCORK(t *testing.T) { } c := udpCORK(true) want := &SocketError{Opts: "IPPROTO_UDP.UDP_CORK"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -1099,17 +1099,17 @@ func TestUDPSegment(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := udpSegment(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_UDP, level) - ztesting.AssertEqual(t, "option not match", UDP_SEGMENT, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_UDP, level) + ztesting.AssertEqual(t, UDP_SEGMENT, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := udpSegment(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -1117,7 +1117,7 @@ func TestUDPSegment(t *testing.T) { } c := udpSegment(1) want := &SocketError{Opts: "IPPROTO_UDP.UDP_SEGMENT"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -1127,17 +1127,17 @@ func TestUDPGRO(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := udpGRO(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_UDP, level) - ztesting.AssertEqual(t, "option not match", UDP_GRO, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_UDP, level) + ztesting.AssertEqual(t, UDP_GRO, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := udpGRO(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd int, level, opt, value int) (err error) { @@ -1145,6 +1145,6 @@ func TestUDPGRO(t *testing.T) { } c := udpGRO(true) want := &SocketError{Opts: "IPPROTO_UDP.UDP_GRO"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } diff --git a/zsyscall/sockopt_others_test.go b/zsyscall/sockopt_others_test.go index 38d1605..7997012 100644 --- a/zsyscall/sockopt_others_test.go +++ b/zsyscall/sockopt_others_test.go @@ -27,7 +27,7 @@ func TestSockSOOption_Controllers(t *testing.T) { SendBufferForce: 18, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 0, len(cs)) + ztesting.AssertEqual(t, 0, len(cs)) } func TestSockIPOption_Controllers(t *testing.T) { @@ -41,7 +41,7 @@ func TestSockIPOption_Controllers(t *testing.T) { TTL: 12, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 0, len(cs)) + ztesting.AssertEqual(t, 0, len(cs)) } func TestSockIPV6Option_Controllers(t *testing.T) { @@ -50,7 +50,7 @@ func TestSockIPV6Option_Controllers(t *testing.T) { V6Only: true, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 0, len(cs)) + ztesting.AssertEqual(t, 0, len(cs)) } func TestSockTCPOption_Controllers(t *testing.T) { @@ -72,7 +72,7 @@ func TestSockTCPOption_Controllers(t *testing.T) { FastOpenConnect: true, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 0, len(cs)) + ztesting.AssertEqual(t, 0, len(cs)) } func TestSockUDPOption_Controllers(t *testing.T) { @@ -83,5 +83,5 @@ func TestSockUDPOption_Controllers(t *testing.T) { GRO: true, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 0, len(cs)) + ztesting.AssertEqual(t, 0, len(cs)) } diff --git a/zsyscall/sockopt_test.go b/zsyscall/sockopt_test.go index 2ba7acf..9f01c5e 100644 --- a/zsyscall/sockopt_test.go +++ b/zsyscall/sockopt_test.go @@ -13,42 +13,42 @@ func TestSockOption_ControlFunc(t *testing.T) { t.Run("nil option", func(t *testing.T) { var o *SockOption f := o.ControlFunc(0) - ztesting.AssertEqual(t, "control func is not nil", true, f == nil) + ztesting.AssertEqual(t, true, f == nil) }) t.Run("non-nil option", func(t *testing.T) { o := &SockOption{} f := o.ControlFunc(0) - ztesting.AssertEqual(t, "control func is not nil", true, f == nil) + ztesting.AssertEqual(t, true, f == nil) }) t.Run("non-nil option", func(t *testing.T) { o := &SockOption{} f := o.ControlFunc(0) - ztesting.AssertEqual(t, "control func is not nil", true, f == nil) + ztesting.AssertEqual(t, true, f == nil) }) t.Run("so option", func(t *testing.T) { o := &SockOption{SO: &SockSOOption{}} f := o.ControlFunc(SockOptSO) - ztesting.AssertEqual(t, "control func is not nil", true, f == nil) + ztesting.AssertEqual(t, true, f == nil) }) t.Run("ip option", func(t *testing.T) { o := &SockOption{IP: &SockIPOption{}} f := o.ControlFunc(SockOptIP) - ztesting.AssertEqual(t, "control func is not nil", true, f == nil) + ztesting.AssertEqual(t, true, f == nil) }) t.Run("ipv6 option", func(t *testing.T) { o := &SockOption{IPV6: &SockIPV6Option{}} f := o.ControlFunc(SockOptIPV6) - ztesting.AssertEqual(t, "control func is not nil", true, f == nil) + ztesting.AssertEqual(t, true, f == nil) }) t.Run("tcp option", func(t *testing.T) { o := &SockOption{TCP: &SockTCPOption{}} f := o.ControlFunc(SockOptTCP) - ztesting.AssertEqual(t, "control func is not nil", true, f == nil) + ztesting.AssertEqual(t, true, f == nil) }) t.Run("udp option", func(t *testing.T) { o := &SockOption{UDP: &SockUDPOption{}} f := o.ControlFunc(SockOptUDP) - ztesting.AssertEqual(t, "control func is not nil", true, f == nil) + ztesting.AssertEqual(t, true, f == nil) }) } @@ -68,7 +68,7 @@ func TestControllers(t *testing.T) { t.Run("nil", func(t *testing.T) { cs := controllers([]Controller{}) err := cs.control("network", "address", &testRawConn{}) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("1 control func", func(t *testing.T) { count := 0 @@ -76,8 +76,8 @@ func TestControllers(t *testing.T) { func(fd uintptr) error { count++; return nil }, }) err := cs.control("network", "address", &testRawConn{}) - ztesting.AssertEqual(t, "count not match", 1, count) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 1, count) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("2 control func", func(t *testing.T) { count := 0 @@ -86,8 +86,8 @@ func TestControllers(t *testing.T) { func(fd uintptr) error { count++; return nil }, }) err := cs.control("network", "address", &testRawConn{}) - ztesting.AssertEqual(t, "count not match", 2, count) - ztesting.AssertEqualErr(t, "error not match", nil, err) + ztesting.AssertEqual(t, 2, count) + ztesting.AssertEqualErr(t, nil, err) }) t.Run("control func error", func(t *testing.T) { count := 0 @@ -96,8 +96,8 @@ func TestControllers(t *testing.T) { func(fd uintptr) error { count++; return nil }, }) err := cs.control("network", "address", &testRawConn{}) - ztesting.AssertEqual(t, "count not match", 1, count) - ztesting.AssertEqualErr(t, "error not match", io.EOF, err) + ztesting.AssertEqual(t, 1, count) + ztesting.AssertEqualErr(t, io.EOF, err) }) t.Run("conn error", func(t *testing.T) { count := 0 @@ -106,8 +106,8 @@ func TestControllers(t *testing.T) { func(fd uintptr) error { count++; return nil }, }) err := cs.control("network", "address", &testRawConn{err: io.EOF}) // Return dummy error. - ztesting.AssertEqual(t, "count not match", 2, count) - ztesting.AssertEqualErr(t, "error not match", io.EOF, err) + ztesting.AssertEqual(t, 2, count) + ztesting.AssertEqualErr(t, io.EOF, err) }) } @@ -115,9 +115,9 @@ func TestAppendNonNil(t *testing.T) { t.Parallel() arr := []Controller{} arr = appendNonNil(arr, nil) - ztesting.AssertEqual(t, "nil should not be appended", 0, len(arr)) + ztesting.AssertEqual(t, 0, len(arr)) arr = appendNonNil(arr, func(fd uintptr) error { return nil }) - ztesting.AssertEqual(t, "non-nil should be appended", 1, len(arr)) + ztesting.AssertEqual(t, 1, len(arr)) } func TestSocketError(t *testing.T) { @@ -126,29 +126,29 @@ func TestSocketError(t *testing.T) { err := &SocketError{Err: io.EOF, Opts: "FOO.BAR"} msg := err.Error() want := "zsyscall: fail to apply socket option FOO.BAR [EOF]" - ztesting.AssertEqual(t, "error message not match", want, msg) + ztesting.AssertEqual(t, want, msg) }) t.Run("same error", func(t *testing.T) { err1 := &SocketError{Opts: "FOO.BAR"} err2 := &SocketError{Opts: "FOO.BAR"} is := err1.Is(err2) - ztesting.AssertEqual(t, "error not match", true, is) + ztesting.AssertEqual(t, true, is) }) t.Run("different error", func(t *testing.T) { err1 := &SocketError{Opts: "FOO.BAR"} err2 := &SocketError{Opts: "FOO.BAZ"} is := err1.Is(err2) - ztesting.AssertEqual(t, "error not match", false, is) + ztesting.AssertEqual(t, false, is) }) t.Run("non socket error", func(t *testing.T) { err1 := &SocketError{Opts: "FOO.BAR"} is := err1.Is(io.EOF) - ztesting.AssertEqual(t, "error not match", false, is) + ztesting.AssertEqual(t, false, is) }) t.Run("nil error", func(t *testing.T) { err1 := &SocketError{Opts: "FOO.BAR"} is := err1.Is(nil) - ztesting.AssertEqual(t, "error not match", false, is) + ztesting.AssertEqual(t, false, is) }) } diff --git a/zsyscall/sockopt_windows_test.go b/zsyscall/sockopt_windows_test.go index 276b894..2976618 100644 --- a/zsyscall/sockopt_windows_test.go +++ b/zsyscall/sockopt_windows_test.go @@ -29,7 +29,7 @@ func TestSockSOOption_Controllers(t *testing.T) { SendBufferForce: 18, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 6, len(cs)) + ztesting.AssertEqual(t, 6, len(cs)) } func TestSockIPOption_Controllers(t *testing.T) { @@ -43,7 +43,7 @@ func TestSockIPOption_Controllers(t *testing.T) { TTL: 12, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 1, len(cs)) + ztesting.AssertEqual(t, 1, len(cs)) } func TestSockIPV6Option_Controllers(t *testing.T) { @@ -52,7 +52,7 @@ func TestSockIPV6Option_Controllers(t *testing.T) { V6Only: true, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 0, len(cs)) + ztesting.AssertEqual(t, 0, len(cs)) } func TestSockTCPOption_Controllers(t *testing.T) { @@ -74,7 +74,7 @@ func TestSockTCPOption_Controllers(t *testing.T) { FastOpenConnect: true, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 1, len(cs)) + ztesting.AssertEqual(t, 1, len(cs)) } func TestSockUDPOption_Controllers(t *testing.T) { @@ -85,7 +85,7 @@ func TestSockUDPOption_Controllers(t *testing.T) { GRO: true, } cs := opt.Controllers() - ztesting.AssertEqual(t, "number of controllers not match", 0, len(cs)) + ztesting.AssertEqual(t, 0, len(cs)) } func TestSoDebug(t *testing.T) { @@ -94,17 +94,17 @@ func TestSoDebug(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soDebug(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", SO_DEBUG, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, SO_DEBUG, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soDebug(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { @@ -112,7 +112,7 @@ func TestSoDebug(t *testing.T) { } c := soDebug(true) want := &SocketError{Opts: "SOL_SOCKET.SO_DEBUG"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -122,17 +122,17 @@ func TestSoKeepAlive(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soKeepAlive(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_KEEPALIVE, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_KEEPALIVE, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soKeepAlive(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { @@ -140,7 +140,7 @@ func TestSoKeepAlive(t *testing.T) { } c := soKeepAlive(true) want := &SocketError{Opts: "SOL_SOCKET.SO_KEEPALIVE"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -150,29 +150,29 @@ func TestSoLinger(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soLinger(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("on", func(t *testing.T) { setsockoptLinger = func(fd syscall.Handle, level, opt int, l *syscall.Linger) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_LINGER, opt) - ztesting.AssertEqual(t, "onoff not match", 1, l.Onoff) - ztesting.AssertEqual(t, "linger not match", 9, l.Linger) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_LINGER, opt) + ztesting.AssertEqual(t, 1, l.Onoff) + ztesting.AssertEqual(t, 9, l.Linger) return nil } c := soLinger(9) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("off", func(t *testing.T) { setsockoptLinger = func(fd syscall.Handle, level, opt int, l *syscall.Linger) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_LINGER, opt) - ztesting.AssertEqual(t, "onoff not match", 0, l.Onoff) - ztesting.AssertEqual(t, "linger not match", 0, l.Linger) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_LINGER, opt) + ztesting.AssertEqual(t, 0, l.Onoff) + ztesting.AssertEqual(t, 0, l.Linger) return nil } c := soLinger(-9) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptLinger = func(fd syscall.Handle, level, opt int, l *syscall.Linger) (err error) { @@ -180,7 +180,7 @@ func TestSoLinger(t *testing.T) { } c := soLinger(9) want := &SocketError{Opts: "SOL_SOCKET.SO_LINGER"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -190,17 +190,17 @@ func TestSoRcvbuf(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soRcvbuf(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_RCVBUF, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_RCVBUF, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soRcvbuf(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { @@ -208,7 +208,7 @@ func TestSoRcvbuf(t *testing.T) { } c := soRcvbuf(1) want := &SocketError{Opts: "SOL_SOCKET.SO_RCVBUF"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -218,17 +218,17 @@ func TestSoSndbuf(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soSndbuf(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_SNDBUF, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_SNDBUF, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soSndbuf(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { @@ -236,7 +236,7 @@ func TestSoSndbuf(t *testing.T) { } c := soSndbuf(1) want := &SocketError{Opts: "SOL_SOCKET.SO_SNDBUF"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -246,17 +246,17 @@ func TestSoReuseaddr(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := soReuseaddr(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.SOL_SOCKET, level) - ztesting.AssertEqual(t, "option not match", syscall.SO_REUSEADDR, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.SOL_SOCKET, level) + ztesting.AssertEqual(t, syscall.SO_REUSEADDR, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := soReuseaddr(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { @@ -264,7 +264,7 @@ func TestSoReuseaddr(t *testing.T) { } c := soReuseaddr(true) want := &SocketError{Opts: "SOL_SOCKET.SO_REUSEADDR"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -274,17 +274,17 @@ func TestIPTTL(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := ipTTL(0) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_IP, level) - ztesting.AssertEqual(t, "option not match", syscall.IP_TTL, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_IP, level) + ztesting.AssertEqual(t, syscall.IP_TTL, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := ipTTL(1) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { @@ -292,7 +292,7 @@ func TestIPTTL(t *testing.T) { } c := ipTTL(1) want := &SocketError{Opts: "IPPROTO_IP.IP_TTL"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } @@ -302,17 +302,17 @@ func TestTCPNoDelay(t *testing.T) { }() t.Run("disabled", func(t *testing.T) { c := tcpNoDelay(false) - ztesting.AssertEqual(t, "controller should be nil", true, c == nil) + ztesting.AssertEqual(t, true, c == nil) }) t.Run("enabled", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { - ztesting.AssertEqual(t, "level not match", syscall.IPPROTO_TCP, level) - ztesting.AssertEqual(t, "option not match", syscall.TCP_NODELAY, opt) - ztesting.AssertEqual(t, "value not match", 1, value) + ztesting.AssertEqual(t, syscall.IPPROTO_TCP, level) + ztesting.AssertEqual(t, syscall.TCP_NODELAY, opt) + ztesting.AssertEqual(t, 1, value) return nil } c := tcpNoDelay(true) - ztesting.AssertEqualErr(t, "error not match", nil, c(0)) + ztesting.AssertEqualErr(t, nil, c(0)) }) t.Run("error", func(t *testing.T) { setsockoptInt = func(fd syscall.Handle, level, opt, value int) (err error) { @@ -320,6 +320,6 @@ func TestTCPNoDelay(t *testing.T) { } c := tcpNoDelay(true) want := &SocketError{Opts: "IPPROTO_TCP.TCP_NODELAY"} - ztesting.AssertEqualErr(t, "error not match", want, c(0)) + ztesting.AssertEqualErr(t, want, c(0)) }) } diff --git a/ztesting/assert.go b/ztesting/assert.go index 1289a54..ad4d223 100644 --- a/ztesting/assert.go +++ b/ztesting/assert.go @@ -18,15 +18,15 @@ type test interface { var mocT test // AssertEqual checks if the given two values are the same. -// AssertEqual compares want and got using [reflect.DeepEqual]. +// AssertEqual compares want and got with [reflect.DeepEqual]. // See https://go.dev/wiki/TestComments -func AssertEqual[T any](t *testing.T, msg string, want, got T) { +func AssertEqual[T any](t *testing.T, want, got T) { tt := cmp.Or(mocT, test(t)) // Use mocT to test this func. tt.Helper() if reflect.DeepEqual(want, got) { return } - msg += "\n" + msg := "Values not matched.\n" msg += "-want: " + spew.Sdump(want) msg += "+got: " + spew.Sdump(got) tt.Error(msg) @@ -36,17 +36,13 @@ func AssertEqual[T any](t *testing.T, msg string, want, got T) { // Errors are checked by following order and considered the same // when one of them returned true. // -// - Compare pointer: want == got // - Compare error: errors.Is(got, want) // - Compare message: want.Error() == got.Error() // // See https://go.dev/wiki/TestComments -func AssertEqualErr(t *testing.T, errReason string, want, got error) { +func AssertEqualErr(t *testing.T, want, got error) { tt := cmp.Or(mocT, test(t)) // Use mocT to test this func itself. tt.Helper() - if want == got { - return // nil == nil is also here. - } if errors.Is(got, want) { return } @@ -55,8 +51,8 @@ func AssertEqualErr(t *testing.T, errReason string, want, got error) { return } } - errReason += "\n" - errReason += "-want: " + spew.Sdump(want) - errReason += "+got: " + spew.Sdump(got) - tt.Error(errReason) + msg := "Errors not matched.\n" + msg += "-want: " + spew.Sdump(want) + msg += "+got: " + spew.Sdump(got) + tt.Error(msg) } diff --git a/ztesting/assert_test.go b/ztesting/assert_test.go index a0cb842..408b4d6 100644 --- a/ztesting/assert_test.go +++ b/ztesting/assert_test.go @@ -19,18 +19,18 @@ func TestAssertEqual(t *testing.T) { t.Run("equal", func(t *testing.T) { tt := &testT{} mocT = tt - AssertEqual(t, "error message", "foo", "foo") + AssertEqual(t, "foo", "foo") mocT = nil // Reset moc - AssertEqual(t, "helper is not called", true, tt.helperCalled) - AssertEqual(t, "length of args not match", 0, len(tt.gotArgs)) + AssertEqual(t, true, tt.helperCalled) + AssertEqual(t, 0, len(tt.gotArgs)) }) t.Run("not equal", func(t *testing.T) { tt := &testT{} mocT = tt - AssertEqual(t, "error message", "foo", "bar") + AssertEqual(t, "foo", "bar") mocT = nil // Reset moc - AssertEqual(t, "helper is not called", true, tt.helperCalled) - AssertEqual(t, "length of args not match", 1, len(tt.gotArgs)) + AssertEqual(t, true, tt.helperCalled) + AssertEqual(t, 1, len(tt.gotArgs)) }) } @@ -39,33 +39,33 @@ func TestAssertEqualErr(t *testing.T) { t.Run("equal pointer", func(t *testing.T) { tt := &testT{} mocT = tt - AssertEqualErr(t, "error message", io.EOF, io.EOF) + AssertEqualErr(t, io.EOF, io.EOF) mocT = nil // Reset moc - AssertEqual(t, "helper is not called", true, tt.helperCalled) - AssertEqual(t, "length of args not match", 0, len(tt.gotArgs)) + AssertEqual(t, true, tt.helperCalled) + AssertEqual(t, 0, len(tt.gotArgs)) }) t.Run("equal by is", func(t *testing.T) { tt := &testT{} mocT = tt - AssertEqualErr(t, "error message", io.EOF, fmt.Errorf("wrap [%w]", io.EOF)) + AssertEqualErr(t, io.EOF, fmt.Errorf("wrap [%w]", io.EOF)) mocT = nil // Reset moc - AssertEqual(t, "helper is not called", true, tt.helperCalled) - AssertEqual(t, "length of args not match", 0, len(tt.gotArgs)) + AssertEqual(t, true, tt.helperCalled) + AssertEqual(t, 0, len(tt.gotArgs)) }) t.Run("equal by message", func(t *testing.T) { tt := &testT{} mocT = tt - AssertEqualErr(t, "error message", io.EOF, fmt.Errorf("EOF")) + AssertEqualErr(t, io.EOF, fmt.Errorf("EOF")) mocT = nil // Reset moc - AssertEqual(t, "helper is not called", true, tt.helperCalled) - AssertEqual(t, "length of args not match", 0, len(tt.gotArgs)) + AssertEqual(t, true, tt.helperCalled) + AssertEqual(t, 0, len(tt.gotArgs)) }) t.Run("not equal", func(t *testing.T) { tt := &testT{} mocT = tt - AssertEqualErr(t, "error message", io.EOF, io.ErrUnexpectedEOF) + AssertEqualErr(t, io.EOF, io.ErrUnexpectedEOF) mocT = nil // Reset moc - AssertEqual(t, "helper is not called", true, tt.helperCalled) - AssertEqual(t, "length of args not match", 1, len(tt.gotArgs)) + AssertEqual(t, true, tt.helperCalled) + AssertEqual(t, 1, len(tt.gotArgs)) }) } diff --git a/ztesting/replace_test.go b/ztesting/replace_test.go index 25416c9..0a30263 100644 --- a/ztesting/replace_test.go +++ b/ztesting/replace_test.go @@ -14,9 +14,9 @@ func TestReplaceRandReader(t *testing.T) { defer done() b := make([]byte, 5) n, err := rand.Read(b) - ztesting.AssertEqual(t, "read content not match", "12345", string(b)) - ztesting.AssertEqual(t, "read bytes not match", 5, n) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, "12345", string(b)) + ztesting.AssertEqual(t, 5, n) + ztesting.AssertEqual(t, nil, err) } func TestReplaceStdout(t *testing.T) { @@ -25,9 +25,9 @@ func TestReplaceStdout(t *testing.T) { os.Stdout.Write([]byte("12345")) b := make([]byte, 5) n, err := r.Read(b) - ztesting.AssertEqual(t, "written content not match", "12345", string(b)) - ztesting.AssertEqual(t, "written bytes not match", 5, n) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, "12345", string(b)) + ztesting.AssertEqual(t, 5, n) + ztesting.AssertEqual(t, nil, err) } func TestReplaceStderr(t *testing.T) { @@ -36,9 +36,9 @@ func TestReplaceStderr(t *testing.T) { os.Stderr.Write([]byte("12345")) b := make([]byte, 5) n, err := r.Read(b) - ztesting.AssertEqual(t, "written content not match", "12345", string(b)) - ztesting.AssertEqual(t, "written bytes not match", 5, n) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, "12345", string(b)) + ztesting.AssertEqual(t, 5, n) + ztesting.AssertEqual(t, nil, err) } func TestReplaceStdin(t *testing.T) { @@ -47,7 +47,7 @@ func TestReplaceStdin(t *testing.T) { w.Write([]byte("12345")) b := make([]byte, 5) n, err := os.Stdin.Read(b) - ztesting.AssertEqual(t, "read content not match", "12345", string(b)) - ztesting.AssertEqual(t, "read bytes not match", 5, n) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, "12345", string(b)) + ztesting.AssertEqual(t, 5, n) + ztesting.AssertEqual(t, nil, err) } diff --git a/ztesting/ziotest/reader.go b/ztesting/ziotest/reader.go index b3fe769..24acae3 100644 --- a/ztesting/ziotest/reader.go +++ b/ztesting/ziotest/reader.go @@ -12,12 +12,12 @@ var ( 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, } - CharsetAscii = string(ASCII) - CharsetDigit = "0123456789" - CharsetLetter1 = "abcdefghijklmnopqrstuvwxyz" - CharsetLetter2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - CharsetLetter = CharsetLetter1 + CharsetLetter2 - CharsetSymbol = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" + CharsetAscii = string(ASCII) + CharsetDigit = "0123456789" + CharsetLetterLower = "abcdefghijklmnopqrstuvwxyz" + CharsetLetterUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + CharsetLetter = CharsetLetterLower + CharsetLetterUpper + CharsetSymbol = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" ) // CharsetReader returns [io.Reader] that reads from the given charset. diff --git a/ztesting/ziotest/reader_test.go b/ztesting/ziotest/reader_test.go index afbc430..56ce05c 100644 --- a/ztesting/ziotest/reader_test.go +++ b/ztesting/ziotest/reader_test.go @@ -16,9 +16,9 @@ func TestCharsetReader(t *testing.T) { cr := ziotest.CharsetReader("", false) buf := make([]byte, 3) n, err := cr.Read(buf) - ztesting.AssertEqual(t, "invalid read bytes.", 0, n) - ztesting.AssertEqual(t, "invalid returned error.", io.EOF, err) - ztesting.AssertEqual(t, "invalid read string.", "\x00\x00\x00", string(buf)) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, io.EOF, err) + ztesting.AssertEqual(t, "\x00\x00\x00", string(buf)) }) t.Run("read chart without loop", func(t *testing.T) { @@ -29,16 +29,16 @@ func TestCharsetReader(t *testing.T) { // Read first buf1 := make([]byte, 3) n, err = cr.Read(buf1) - ztesting.AssertEqual(t, "invalid read bytes.", 3, n) - ztesting.AssertEqual(t, "invalid returned error.", nil, err) - ztesting.AssertEqual(t, "invalid read string.", "123", string(buf1)) + ztesting.AssertEqual(t, 3, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "123", string(buf1)) // Read second buf2 := make([]byte, 3) n, err = cr.Read(buf2) - ztesting.AssertEqual(t, "invalid read bytes.", 2, n) - ztesting.AssertEqual(t, "invalid returned error.", io.EOF, err) - ztesting.AssertEqual(t, "invalid read string.", "45\x00", string(buf2)) + ztesting.AssertEqual(t, 2, n) + ztesting.AssertEqual(t, io.EOF, err) + ztesting.AssertEqual(t, "45\x00", string(buf2)) }) t.Run("read chart with loop", func(t *testing.T) { @@ -49,16 +49,16 @@ func TestCharsetReader(t *testing.T) { // Read first buf1 := make([]byte, 3) n, err = cr.Read(buf1) - ztesting.AssertEqual(t, "invalid read bytes.", 3, n) - ztesting.AssertEqual(t, "invalid returned error.", nil, err) - ztesting.AssertEqual(t, "invalid read string.", "123", string(buf1)) + ztesting.AssertEqual(t, 3, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "123", string(buf1)) // Read second buf2 := make([]byte, 3) n, err = cr.Read(buf2) - ztesting.AssertEqual(t, "invalid read bytes.", 3, n) - ztesting.AssertEqual(t, "invalid returned error.", nil, err) - ztesting.AssertEqual(t, "invalid read string.", "451", string(buf2)) + ztesting.AssertEqual(t, 3, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "451", string(buf2)) }) } @@ -69,18 +69,18 @@ func TestErrReader(t *testing.T) { er := ziotest.ErrReader(strings.NewReader("123456789"), -10) buf := make([]byte, 3) n, err := er.Read(buf) - ztesting.AssertEqual(t, "invalid read bytes.", 0, n) - ztesting.AssertEqual(t, "invalid returned error.", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "invalid read string.", "\x00\x00\x00", string(buf)) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "\x00\x00\x00", string(buf)) }) t.Run("read 0", func(t *testing.T) { er := ziotest.ErrReader(strings.NewReader("123456789"), 0) buf := make([]byte, 3) n, err := er.Read(buf) - ztesting.AssertEqual(t, "invalid read bytes.", 0, n) - ztesting.AssertEqual(t, "invalid returned error.", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "invalid read string.", "\x00\x00\x00", string(buf)) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "\x00\x00\x00", string(buf)) }) t.Run("read more than n", func(t *testing.T) { @@ -91,16 +91,16 @@ func TestErrReader(t *testing.T) { // Read first buf1 := make([]byte, 3) n, err = er.Read(buf1) - ztesting.AssertEqual(t, "invalid read bytes.", 3, n) - ztesting.AssertEqual(t, "invalid returned error.", nil, err) - ztesting.AssertEqual(t, "invalid read string.", "123", string(buf1)) + ztesting.AssertEqual(t, 3, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "123", string(buf1)) // Read second buf2 := make([]byte, 3) n, err = er.Read(buf2) - ztesting.AssertEqual(t, "invalid read bytes.", 2, n) - ztesting.AssertEqual(t, "invalid returned error.", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "invalid read string.", "45\x00", string(buf2)) + ztesting.AssertEqual(t, 2, n) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "45\x00", string(buf2)) }) t.Run("read exactly n", func(t *testing.T) { @@ -111,15 +111,15 @@ func TestErrReader(t *testing.T) { // Read first buf1 := make([]byte, 3) n, err = er.Read(buf1) - ztesting.AssertEqual(t, "invalid read bytes.", 3, n) - ztesting.AssertEqual(t, "invalid returned error.", nil, err) - ztesting.AssertEqual(t, "invalid read string.", "123", string(buf1)) + ztesting.AssertEqual(t, 3, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "123", string(buf1)) // Read second buf2 := make([]byte, 3) n, err = er.Read(buf2) - ztesting.AssertEqual(t, "invalid read bytes.", 3, n) - ztesting.AssertEqual(t, "invalid returned error.", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "invalid read string.", "456", string(buf2)) + ztesting.AssertEqual(t, 3, n) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "456", string(buf2)) }) } diff --git a/ztesting/ziotest/writer_test.go b/ztesting/ziotest/writer_test.go index 0e6ec09..d0df540 100644 --- a/ztesting/ziotest/writer_test.go +++ b/ztesting/ziotest/writer_test.go @@ -16,18 +16,18 @@ func TestErrWriter(t *testing.T) { var buf bytes.Buffer ew := ziotest.ErrWriter(&buf, -10) n, err := ew.Write([]byte("1234")) - ztesting.AssertEqual(t, "invalid written bytes.", 0, n) - ztesting.AssertEqual(t, "invalid returned error.", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "invalid written string.", "", buf.String()) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "", buf.String()) }) t.Run("n is 0", func(t *testing.T) { var buf bytes.Buffer ew := ziotest.ErrWriter(&buf, 0) n, err := ew.Write([]byte("1234")) - ztesting.AssertEqual(t, "invalid written bytes.", 0, n) - ztesting.AssertEqual(t, "invalid returned error.", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "invalid written string.", "", buf.String()) + ztesting.AssertEqual(t, 0, n) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "", buf.String()) }) t.Run("write more than n", func(t *testing.T) { @@ -38,21 +38,21 @@ func TestErrWriter(t *testing.T) { // First write. n, err = ew.Write([]byte("1234")) - ztesting.AssertEqual(t, "invalid written bytes.", 4, n) - ztesting.AssertEqual(t, "invalid returned error.", nil, err) - ztesting.AssertEqual(t, "invalid written string.", "1234", buf.String()) + ztesting.AssertEqual(t, 4, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "1234", buf.String()) // Second write. n, err = ew.Write([]byte("5678")) - ztesting.AssertEqual(t, "invalid written bytes.", 4, n) - ztesting.AssertEqual(t, "invalid returned error.", nil, err) - ztesting.AssertEqual(t, "invalid written string.", "12345678", buf.String()) + ztesting.AssertEqual(t, 4, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "12345678", buf.String()) // Third write. n, err = ew.Write([]byte("9012")) - ztesting.AssertEqual(t, "invalid written bytes.", 1, n) - ztesting.AssertEqual(t, "invalid returned error.", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "invalid written string.", "123456789", buf.String()) + ztesting.AssertEqual(t, 1, n) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "123456789", buf.String()) }) t.Run("write exactly 8", func(t *testing.T) { @@ -63,23 +63,23 @@ func TestErrWriter(t *testing.T) { // First write. n, err = ew.Write([]byte("1234")) - ztesting.AssertEqual(t, "invalid written bytes.", 4, n) - ztesting.AssertEqual(t, "invalid returned error.", nil, err) - ztesting.AssertEqual(t, "invalid written string.", "1234", buf.String()) + ztesting.AssertEqual(t, 4, n) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "1234", buf.String()) // Second write. n, err = ew.Write([]byte("5678")) - ztesting.AssertEqual(t, "invalid written bytes.", 4, n) - ztesting.AssertEqual(t, "invalid returned error.", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "invalid written string.", "12345678", buf.String()) + ztesting.AssertEqual(t, 4, n) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "12345678", buf.String()) }) t.Run("inner writer error", func(t *testing.T) { var buf bytes.Buffer ew := ziotest.ErrWriter(ziotest.ErrWriter(&buf, 2), 4) n, err := ew.Write([]byte("123")) - ztesting.AssertEqual(t, "invalid written bytes.", 2, n) - ztesting.AssertEqual(t, "invalid returned error.", io.ErrClosedPipe, err) - ztesting.AssertEqual(t, "invalid written string.", "12", buf.String()) + ztesting.AssertEqual(t, 2, n) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) + ztesting.AssertEqual(t, "12", buf.String()) }) } diff --git a/ztext/template_test.go b/ztext/template_test.go index 1383fad..81b8e8c 100644 --- a/ztext/template_test.go +++ b/ztext/template_test.go @@ -18,14 +18,14 @@ func TestTemplate_WithTagFunc(t *testing.T) { tpl.WithTagFunc("a", func(s string) []byte { return []byte("A") }) tpl.WithTagFunc("b", func(s string) []byte { return []byte("B") }) got := tpl.ExecuteString(nil) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=B", got) + ztesting.AssertEqual(t, "a=A b=B", got) }) t.Run("key not found", func(t *testing.T) { tpl := NewTemplate("a={a} b={b}", "{", "}") tpl.WithTagFunc("a", func(s string) []byte { return []byte("A") }) got := tpl.ExecuteString(nil) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", got) + ztesting.AssertEqual(t, "a=A b=", got) }) t.Run("empty tag", func(t *testing.T) { @@ -33,7 +33,7 @@ func TestTemplate_WithTagFunc(t *testing.T) { tpl.WithTagFunc("a", func(s string) []byte { return []byte("A") }) tpl.WithTagFunc("", func(s string) []byte { return []byte("B") }) got := tpl.ExecuteString(nil) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", got) + ztesting.AssertEqual(t, "a=A b=", got) }) t.Run("nil func", func(t *testing.T) { @@ -41,7 +41,7 @@ func TestTemplate_WithTagFunc(t *testing.T) { tpl.WithTagFunc("a", func(s string) []byte { return []byte("A") }) tpl.WithTagFunc("b", nil) got := tpl.ExecuteString(nil) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", got) + ztesting.AssertEqual(t, "a=A b=", got) }) } @@ -53,17 +53,17 @@ func TestTemplate_Execute(t *testing.T) { t.Run("key found", func(t *testing.T) { got := tpl.Execute(map[string]any{"b": "B"}) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=B", string(got)) + ztesting.AssertEqual(t, "a=A b=B", string(got)) }) t.Run("key not found", func(t *testing.T) { got := tpl.Execute(map[string]any{"c": "C"}) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", string(got)) + ztesting.AssertEqual(t, "a=A b=", string(got)) }) t.Run("nil map", func(t *testing.T) { got := tpl.Execute(nil) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", string(got)) + ztesting.AssertEqual(t, "a=A b=", string(got)) }) } @@ -75,17 +75,17 @@ func TestTemplate_ExecuteString(t *testing.T) { t.Run("key found", func(t *testing.T) { got := tpl.ExecuteString(map[string]any{"b": "B"}) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=B", got) + ztesting.AssertEqual(t, "a=A b=B", got) }) t.Run("key not found", func(t *testing.T) { got := tpl.ExecuteString(map[string]any{"c": "C"}) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", got) + ztesting.AssertEqual(t, "a=A b=", got) }) t.Run("nil map", func(t *testing.T) { got := tpl.ExecuteString(nil) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", got) + ztesting.AssertEqual(t, "a=A b=", got) }) } @@ -97,12 +97,12 @@ func TestTemplate_ExecuteFunc(t *testing.T) { t.Run("non-nil func", func(t *testing.T) { got := tpl.ExecuteFunc(func(s string) []byte { return []byte(strings.ToUpper(s)) }) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=B", string(got)) + ztesting.AssertEqual(t, "a=A b=B", string(got)) }) t.Run("nil func", func(t *testing.T) { got := tpl.ExecuteFunc(nil) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", string(got)) + ztesting.AssertEqual(t, "a=A b=", string(got)) }) } @@ -115,28 +115,28 @@ func TestTemplate_ExecuteWriter(t *testing.T) { t.Run("key found", func(t *testing.T) { var buf bytes.Buffer err := tpl.ExecuteWriter(&buf, map[string]any{"b": "B"}) - ztesting.AssertEqual(t, "unexpected error returned.", nil, err) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=B", buf.String()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "a=A b=B", buf.String()) }) t.Run("key not found", func(t *testing.T) { var buf bytes.Buffer err := tpl.ExecuteWriter(&buf, map[string]any{"c": "C"}) - ztesting.AssertEqual(t, "unexpected error returned.", nil, err) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", buf.String()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "a=A b=", buf.String()) }) t.Run("nil map", func(t *testing.T) { var buf bytes.Buffer err := tpl.ExecuteWriter(&buf, nil) - ztesting.AssertEqual(t, "unexpected error returned.", nil, err) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", buf.String()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "a=A b=", buf.String()) }) t.Run("write error", func(t *testing.T) { buf := ziotest.ErrWriter(nil, 0) err := tpl.ExecuteWriter(buf, map[string]any{"b": "B"}) - ztesting.AssertEqual(t, "unexpected error returned.", io.ErrClosedPipe, err) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) }) } @@ -149,21 +149,21 @@ func TestTemplate_ExecuteWriterFunc(t *testing.T) { t.Run("non-nil func", func(t *testing.T) { var buf bytes.Buffer err := tpl.ExecuteWriterFunc(&buf, func(s string) []byte { return []byte(strings.ToUpper(s)) }) - ztesting.AssertEqual(t, "unexpected error returned.", nil, err) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=B", buf.String()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "a=A b=B", buf.String()) }) t.Run("nil func", func(t *testing.T) { var buf bytes.Buffer err := tpl.ExecuteWriterFunc(&buf, nil) - ztesting.AssertEqual(t, "unexpected error returned.", nil, err) - ztesting.AssertEqual(t, "wrong result of template.", "a=A b=", buf.String()) + ztesting.AssertEqual(t, nil, err) + ztesting.AssertEqual(t, "a=A b=", buf.String()) }) t.Run("write error", func(t *testing.T) { buf := ziotest.ErrWriter(nil, 0) err := tpl.ExecuteWriterFunc(buf, func(s string) []byte { return []byte(strings.ToUpper(s)) }) - ztesting.AssertEqual(t, "unexpected error returned.", io.ErrClosedPipe, err) + ztesting.AssertEqual(t, io.ErrClosedPipe, err) }) } @@ -207,7 +207,7 @@ func TestMapValue(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := tc.mv.value(tc.tag) - ztesting.AssertEqual(t, "wrong result of template.", string(tc.expect), string(got)) + ztesting.AssertEqual(t, string(tc.expect), string(got)) }) } }) diff --git a/ztime/zbackoff/backoff_test.go b/ztime/zbackoff/backoff_test.go index 338d325..34fbb70 100644 --- a/ztime/zbackoff/backoff_test.go +++ b/ztime/zbackoff/backoff_test.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "math" - "strconv" "testing" "time" @@ -17,18 +16,18 @@ func TestBackoffError(t *testing.T) { e1 := &BackoffError{Type: "foo", Info: "bar"} e2 := &BackoffError{Type: "foo", Info: "bar"} e3 := &BackoffError{Type: "bar", Info: "foo"} - ztesting.AssertEqual(t, "error is not the same", true, errors.Is(e1, e2)) - ztesting.AssertEqual(t, "error is the same", false, errors.Is(e1, e3)) - ztesting.AssertEqual(t, "error is the same", false, errors.Is(e1, nil)) + ztesting.AssertEqual(t, true, errors.Is(e1, e2)) + ztesting.AssertEqual(t, false, errors.Is(e1, e3)) + ztesting.AssertEqual(t, false, errors.Is(e1, nil)) }) t.Run("wrapped error equality", func(t *testing.T) { e1 := &BackoffError{Type: "foo", Info: "bar"} e2 := fmt.Errorf("this is e2 [%w]", &BackoffError{Type: "foo", Info: "bar"}) e3 := fmt.Errorf("this is e3 [%w]", &BackoffError{Type: "bar", Info: "foo"}) e4 := fmt.Errorf("this is e4 [%w]", nil) - ztesting.AssertEqual(t, "error is not the same", true, errors.Is(e1, e2)) - ztesting.AssertEqual(t, "error is the same", false, errors.Is(e1, e3)) - ztesting.AssertEqual(t, "error is the same", false, errors.Is(e1, e4)) + ztesting.AssertEqual(t, true, errors.Is(e1, e2)) + ztesting.AssertEqual(t, false, errors.Is(e1, e3)) + ztesting.AssertEqual(t, false, errors.Is(e1, e4)) }) } @@ -38,7 +37,7 @@ func TestFixedBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "value must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewFixedBackoff(-1) }) @@ -68,7 +67,7 @@ func TestFixedBackoff(t *testing.T) { t.Run(name, func(t *testing.T) { backoff := NewFixedBackoff(tc.value) got := backoff.Attempt(tc.attempt) - ztesting.AssertEqual(t, "wrong backoff duration for attempt="+strconv.Itoa(tc.attempt), tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -79,7 +78,7 @@ func TestRandomBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewRandomBackoff(-1, 1) }) @@ -87,7 +86,7 @@ func TestRandomBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "fluctuation must be positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewRandomBackoff(1, 0) }) @@ -95,7 +94,7 @@ func TestRandomBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "fluctuation must be positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewRandomBackoff(1, 0) }) @@ -103,7 +102,7 @@ func TestRandomBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset+fluctuation must be under MaxInt64 (9,223,372,036,854,775,807)"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewRandomBackoff(math.MaxInt64, 1) }) @@ -133,7 +132,7 @@ func TestRandomBackoff(t *testing.T) { backoff := NewRandomBackoff(tc.offset, tc.fluctuation) got := backoff.Attempt(tc.attempt) inRange := (got - tc.offset) <= tc.fluctuation - ztesting.AssertEqual(t, "wrong backoff duration range for attempt="+strconv.Itoa(tc.attempt), true, inRange) + ztesting.AssertEqual(t, true, inRange) }) } } @@ -144,7 +143,7 @@ func TestLinearBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewLinearBackoff(-1, 1, 1) }) @@ -152,7 +151,7 @@ func TestLinearBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "fluctuation must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewLinearBackoff(1, -1, 1) }) @@ -160,7 +159,7 @@ func TestLinearBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "coeff must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewLinearBackoff(1, 1, -1) }) @@ -168,7 +167,7 @@ func TestLinearBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset+fluctuation must be under MaxInt64 (9,223,372,036,854,775,807)"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewLinearBackoff(math.MaxInt64, 1, 1) }) @@ -198,7 +197,7 @@ func TestLinearBackoff(t *testing.T) { t.Run(name, func(t *testing.T) { backoff := NewLinearBackoff(tc.offset, tc.fluctuation, tc.coeff) got := backoff.Attempt(tc.attempt) - ztesting.AssertEqual(t, "wrong backoff duration for attempt="+strconv.Itoa(tc.attempt), tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -209,7 +208,7 @@ func TestPolynomialBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewPolynomialBackoff(-1, 1, 1, 1) }) @@ -217,7 +216,7 @@ func TestPolynomialBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "fluctuation must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewPolynomialBackoff(1, -1, 1, 1) }) @@ -225,7 +224,7 @@ func TestPolynomialBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "coeff must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewPolynomialBackoff(1, 1, -1, 1) }) @@ -233,7 +232,7 @@ func TestPolynomialBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset+fluctuation must be under MaxInt64 (9,223,372,036,854,775,807)"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewPolynomialBackoff(math.MaxInt64, 1, 1, 1) }) @@ -273,7 +272,7 @@ func TestPolynomialBackoff(t *testing.T) { t.Run(name, func(t *testing.T) { backoff := NewPolynomialBackoff(tc.offset, tc.fluctuation, tc.coeff, tc.exponent) got := backoff.Attempt(tc.attempt) - ztesting.AssertEqual(t, "wrong backoff duration for attempt="+strconv.Itoa(tc.attempt), tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -284,7 +283,7 @@ func TestExponentialBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoff(-1, 1, 1) }) @@ -292,7 +291,7 @@ func TestExponentialBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "fluctuation must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoff(1, -1, 1) }) @@ -300,7 +299,7 @@ func TestExponentialBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "coeff must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoff(1, 1, -1) }) @@ -308,7 +307,7 @@ func TestExponentialBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset+fluctuation must be under MaxInt64 (9,223,372,036,854,775,807)"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoff(math.MaxInt64, 1, 1) }) @@ -341,7 +340,7 @@ func TestExponentialBackoff(t *testing.T) { t.Run(name, func(t *testing.T) { backoff := NewExponentialBackoff(tc.offset, tc.fluctuation, tc.coeff) got := backoff.Attempt(tc.attempt) - ztesting.AssertEqual(t, "wrong backoff duration for attempt="+strconv.Itoa(tc.attempt), tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -352,7 +351,7 @@ func TestExponentialBackoffFullJitter(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoffFullJitter(-1, 1, 1) }) @@ -360,7 +359,7 @@ func TestExponentialBackoffFullJitter(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "fluctuation must be positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoffFullJitter(1, -1, 1) }) @@ -368,7 +367,7 @@ func TestExponentialBackoffFullJitter(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "coeff must be positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoffFullJitter(1, 1, -1) }) @@ -376,7 +375,7 @@ func TestExponentialBackoffFullJitter(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset+fluctuation must be under MaxInt64 (9,223,372,036,854,775,807)"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoffFullJitter(math.MaxInt64, 1, 1) }) @@ -415,7 +414,7 @@ func TestExponentialBackoffFullJitter(t *testing.T) { backoff := NewExponentialBackoffFullJitter(tc.offset, tc.fluctuation, tc.coeff) got := backoff.Attempt(tc.attempt) inRange := (got - tc.offset) <= tc.fluctuation - ztesting.AssertEqual(t, "wrong backoff duration range for attempt="+strconv.Itoa(tc.attempt), true, inRange) + ztesting.AssertEqual(t, true, inRange) }) } } @@ -426,7 +425,7 @@ func TestExponentialBackoffEqualJitter(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoffEqualJitter(-1, 1, 1) }) @@ -434,7 +433,7 @@ func TestExponentialBackoffEqualJitter(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "fluctuation must be positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoffEqualJitter(1, -1, 1) }) @@ -442,7 +441,7 @@ func TestExponentialBackoffEqualJitter(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "coeff must be positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoffEqualJitter(1, 1, -1) }) @@ -450,7 +449,7 @@ func TestExponentialBackoffEqualJitter(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset+fluctuation must be under MaxInt64 (9,223,372,036,854,775,807)"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewExponentialBackoffEqualJitter(math.MaxInt64, 1, 1) }) @@ -489,7 +488,7 @@ func TestExponentialBackoffEqualJitter(t *testing.T) { backoff := NewExponentialBackoffEqualJitter(tc.offset, tc.fluctuation, tc.coeff) got := backoff.Attempt(tc.attempt) inRange := (got - tc.offset - tc.fluctuation/2) <= tc.fluctuation - ztesting.AssertEqual(t, "wrong backoff duration range for attempt="+strconv.Itoa(tc.attempt), true, inRange) + ztesting.AssertEqual(t, true, inRange) }) } } @@ -500,7 +499,7 @@ func TestFibonacciBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewFibonacciBackoff(-1, 1, 1) }) @@ -508,7 +507,7 @@ func TestFibonacciBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "fluctuation must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewFibonacciBackoff(1, -1, 1) }) @@ -516,7 +515,7 @@ func TestFibonacciBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "coeff must be zero or positive"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewFibonacciBackoff(1, 1, -1) }) @@ -524,7 +523,7 @@ func TestFibonacciBackoff(t *testing.T) { defer func() { got, _ := recover().(error) want := &BackoffError{Type: errPram, Info: "offset+fluctuation must be under MaxInt64 (9,223,372,036,854,775,807)"} - ztesting.AssertEqualErr(t, "error not matched", want, got) + ztesting.AssertEqualErr(t, want, got) }() NewFibonacciBackoff(math.MaxInt64, 1, 1) }) @@ -563,7 +562,7 @@ func TestFibonacciBackoff(t *testing.T) { t.Run(name, func(t *testing.T) { backoff := NewFibonacciBackoff(tc.offset, tc.fluctuation, tc.coeff) got := backoff.Attempt(tc.attempt) - ztesting.AssertEqual(t, "wrong backoff duration for attempt="+strconv.Itoa(tc.attempt), tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -591,7 +590,7 @@ func TestFibonacci(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := fibonacci(tc.input) - ztesting.AssertEqual(t, "wrong fibonacci for "+strconv.Itoa(tc.input), tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } diff --git a/ztime/zcron/cron_test.go b/ztime/zcron/cron_test.go index f07c18e..83fb246 100644 --- a/ztime/zcron/cron_test.go +++ b/ztime/zcron/cron_test.go @@ -15,21 +15,21 @@ func TestNewCron(t *testing.T) { t.Parallel() t.Run("nil config", func(t *testing.T) { cron, err := NewCron(nil) - ztesting.AssertEqual(t, "non nil cron returned", nil, cron) - ztesting.AssertEqualErr(t, "error not match", ErrNilConfig, err) + ztesting.AssertEqual(t, nil, cron) + ztesting.AssertEqualErr(t, ErrNilConfig, err) }) t.Run("nil job", func(t *testing.T) { cron, err := NewCron(&Config{}) - ztesting.AssertEqual(t, "non nil cron returned", nil, cron) - ztesting.AssertEqualErr(t, "error not match", ErrNilJob, err) + ztesting.AssertEqual(t, nil, cron) + ztesting.AssertEqualErr(t, ErrNilJob, err) }) t.Run("cron parse error", func(t *testing.T) { cron, err := NewCron(&Config{ Crontab: "INVALID", JobFunc: func(ctx context.Context) error { return nil }, }) - ztesting.AssertEqual(t, "non nil cron returned", nil, cron) - ztesting.AssertEqualErr(t, "error not match", &ParseError{What: "number of fields"}, err) + ztesting.AssertEqual(t, nil, cron) + ztesting.AssertEqualErr(t, &ParseError{What: "number of fields"}, err) }) } @@ -50,7 +50,7 @@ func TestCron(t *testing.T) { go cron.Start() wg.Wait() cron.Stop() - ztesting.AssertEqual(t, "call count mismatch", 1, count.Load()) + ztesting.AssertEqual(t, 1, count.Load()) }) t.Run("already running", func(t *testing.T) { var wg sync.WaitGroup @@ -69,7 +69,7 @@ func TestCron(t *testing.T) { go cron.Start() wg.Wait() cron.Stop() - ztesting.AssertEqual(t, "call count mismatch", 1, count.Load()) + ztesting.AssertEqual(t, 1, count.Load()) }) t.Run("calibrate", func(t *testing.T) { var wg sync.WaitGroup @@ -97,9 +97,9 @@ func TestCron(t *testing.T) { go cron.Start() wg.Wait() cron.Stop() - ztesting.AssertEqual(t, "call count mismatch", 1, count.Load()) - ztesting.AssertEqual(t, "duration invalid", 9*time.Minute+30*time.Second, durations[0]) - ztesting.AssertEqual(t, "duration invalid", time.Second, durations[1]) + ztesting.AssertEqual(t, 1, count.Load()) + ztesting.AssertEqual(t, 9*time.Minute+30*time.Second, durations[0]) + ztesting.AssertEqual(t, time.Second, durations[1]) }) } @@ -126,7 +126,7 @@ func TestRunner(t *testing.T) { r.Run() // Run 2. Should not run r.Run() // Run 3. Should not run wg.Wait() - ztesting.AssertEqual(t, "call count mismatch", 1, count.Load()) + ztesting.AssertEqual(t, 1, count.Load()) }) t.Run("queue=2", func(t *testing.T) { var wg sync.WaitGroup @@ -149,7 +149,7 @@ func TestRunner(t *testing.T) { r.Run() // Run 2. Should run r.Run() // Run 3. Should not run wg.Wait() - ztesting.AssertEqual(t, "call count mismatch", 2, count.Load()) + ztesting.AssertEqual(t, 2, count.Load()) }) t.Run("queue=3", func(t *testing.T) { var wg sync.WaitGroup @@ -172,7 +172,7 @@ func TestRunner(t *testing.T) { r.Run() // Run 2. Should run r.Run() // Run 3. Should run wg.Wait() - ztesting.AssertEqual(t, "call count mismatch", 3, count.Load()) + ztesting.AssertEqual(t, 3, count.Load()) }) t.Run("job error", func(t *testing.T) { var wg sync.WaitGroup @@ -194,7 +194,7 @@ func TestRunner(t *testing.T) { } r.Run() wg.Wait() - ztesting.AssertEqualErr(t, "unexpected error", io.EOF, err) + ztesting.AssertEqualErr(t, io.EOF, err) }) t.Run("job panic", func(t *testing.T) { var wg sync.WaitGroup @@ -216,7 +216,7 @@ func TestRunner(t *testing.T) { } r.Run() wg.Wait() - ztesting.AssertEqualErr(t, "unexpected error", io.EOF, err) + ztesting.AssertEqualErr(t, io.EOF, err) }) t.Run("run with context", func(t *testing.T) { var wg sync.WaitGroup @@ -225,7 +225,7 @@ func TestRunner(t *testing.T) { jobFunc: func(ctx context.Context) error { defer wg.Done() val := ctx.Value("foo") - ztesting.AssertEqual(t, "context value not match", any("bar"), val) + ztesting.AssertEqual(t, any("bar"), val) return nil }, withContext: func() context.Context { diff --git a/ztime/zcron/crontab_test.go b/ztime/zcron/crontab_test.go index 31e3dd2..3dd38c7 100644 --- a/ztime/zcron/crontab_test.go +++ b/ztime/zcron/crontab_test.go @@ -2,7 +2,6 @@ package zcron import ( "errors" - "fmt" "io" "testing" "time" @@ -14,17 +13,17 @@ func TestCrontab(t *testing.T) { t.Parallel() t.Run("nil time func", func(t *testing.T) { ct, err := Parse("* * * * *") - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) ct.WithTimeFunc(nil) ct.Next() // No panic. }) t.Run("non nil time func", func(t *testing.T) { ct, err := Parse("* * * * *") - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) now := time.Now().Add(time.Hour) ct.WithTimeFunc(func() time.Time { return now }) got := ct.Now() - ztesting.AssertEqual(t, "time not match", 0, now.Compare(got)) + ztesting.AssertEqual(t, 0, now.Compare(got)) }) } @@ -124,9 +123,9 @@ func TestCrontab_NextAfter(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { ct, err := Parse(tc.cron) - ztesting.AssertEqual(t, "non nil error returned", nil, err) + ztesting.AssertEqual(t, nil, err) got := ct.NextAfter(tc.t) - ztesting.AssertEqual(t, "time not match", 0, tc.want.Compare(got)) + ztesting.AssertEqual(t, 0, tc.want.Compare(got)) t.Log(tc.want, got) }) } @@ -150,7 +149,7 @@ func TestNextTime(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := nextTime(tc.targets, tc.now, tc.max) - ztesting.AssertEqual(t, "invalid result", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -163,24 +162,24 @@ func TestParseError(t *testing.T) { What: "what", Value: "val", } - ztesting.AssertEqual(t, "message mismatch", "ztime/zcron: parse error. invalid what(got:val)", err.Error()) - ztesting.AssertEqual(t, "inner error mismatch", nil, err.Unwrap()) + ztesting.AssertEqual(t, "ztime/zcron: parse error. invalid what(got:val)", err.Error()) + ztesting.AssertEqual(t, nil, err.Unwrap()) }) t.Run("with inner error", func(t *testing.T) { err := &ParseError{ Err: io.EOF, What: "what", } - ztesting.AssertEqual(t, "message mismatch", "ztime/zcron: parse error. invalid what[EOF]", err.Error()) - ztesting.AssertEqual(t, "inner error mismatch", io.EOF, err.Unwrap()) + ztesting.AssertEqual(t, "ztime/zcron: parse error. invalid what[EOF]", err.Error()) + ztesting.AssertEqual(t, io.EOF, err.Unwrap()) }) t.Run("compare", func(t *testing.T) { err1 := &ParseError{Err: nil, What: "what"} err2 := &ParseError{Err: io.EOF, What: "what"} - ztesting.AssertEqual(t, "error not equal", true, errors.Is(err1, err2)) - ztesting.AssertEqual(t, "error not equal", true, errors.Is(err2, err1)) - ztesting.AssertEqual(t, "error not equal", true, errors.Is(err2, io.EOF)) - ztesting.AssertEqual(t, "error equal", false, errors.Is(err1, io.EOF)) + ztesting.AssertEqual(t, true, errors.Is(err1, err2)) + ztesting.AssertEqual(t, true, errors.Is(err2, err1)) + ztesting.AssertEqual(t, true, errors.Is(err2, io.EOF)) + ztesting.AssertEqual(t, false, errors.Is(err1, io.EOF)) }) } @@ -334,17 +333,17 @@ func TestParse(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { ct, err := Parse(tc.exp) - ztesting.AssertEqualErr(t, "error mismatched", tc.err, err) + ztesting.AssertEqualErr(t, tc.err, err) if tc.err != nil { - ztesting.AssertEqual(t, "non nil crontab", nil, ct) + ztesting.AssertEqual(t, nil, ct) return } - ztesting.AssertEqual(t, "wrong second"+fmt.Sprintf("%b", ct.second), tc.ct.second, ct.second) - ztesting.AssertEqual(t, "wrong minute"+fmt.Sprintf("%b", ct.minute), tc.ct.minute, ct.minute) - ztesting.AssertEqual(t, "wrong hour"+fmt.Sprintf("%b", ct.hour), tc.ct.hour, ct.hour) - ztesting.AssertEqual(t, "wrong day"+fmt.Sprintf("%b", ct.day), tc.ct.day, ct.day) - ztesting.AssertEqual(t, "wrong month"+fmt.Sprintf("%b", ct.month), tc.ct.month, ct.month) - ztesting.AssertEqual(t, "wrong week"+fmt.Sprintf("%b", ct.week), tc.ct.week, ct.week) + ztesting.AssertEqual(t, tc.ct.second, ct.second) + ztesting.AssertEqual(t, tc.ct.minute, ct.minute) + ztesting.AssertEqual(t, tc.ct.hour, ct.hour) + ztesting.AssertEqual(t, tc.ct.day, ct.day) + ztesting.AssertEqual(t, tc.ct.month, ct.month) + ztesting.AssertEqual(t, tc.ct.week, ct.week) }) } } @@ -398,7 +397,7 @@ func TestReplaceAlias(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := replaceAlias(tc.exp) - ztesting.AssertEqual(t, "wrong normalization", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -422,7 +421,7 @@ func TestNormalizeMonth(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := normalizeMonth(tc.exp) - ztesting.AssertEqual(t, "wrong normalization", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -446,7 +445,7 @@ func TestNormalizeWeek(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got := normalizeWeek(tc.exp) - ztesting.AssertEqual(t, "wrong normalization", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -495,8 +494,8 @@ func TestParseValue(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { cron, ok := parseValue(tc.exp, tc.min, tc.max) - ztesting.AssertEqual(t, "invalid cron: "+fmt.Sprintf("%b", cron), tc.cron, cron) - ztesting.AssertEqual(t, "wrong bool value returned", tc.ok, ok) + ztesting.AssertEqual(t, tc.cron, cron) + ztesting.AssertEqual(t, tc.ok, ok) }) } } @@ -538,9 +537,9 @@ func TestParseRange(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { under, upper, ok := parseRange(tc.exp, tc.min, tc.max) - ztesting.AssertEqual(t, "minimum value invalid", tc.under, under) - ztesting.AssertEqual(t, "maximum value invalid", tc.upper, upper) - ztesting.AssertEqual(t, "wrong bool value returned", tc.ok, ok) + ztesting.AssertEqual(t, tc.under, under) + ztesting.AssertEqual(t, tc.upper, upper) + ztesting.AssertEqual(t, tc.ok, ok) }) } } diff --git a/ztime/zrate/bucket_test.go b/ztime/zrate/bucket_test.go index c7eec2a..f4db281 100644 --- a/ztime/zrate/bucket_test.go +++ b/ztime/zrate/bucket_test.go @@ -15,27 +15,27 @@ func TestNewFixedWindowLimiterWidth(t *testing.T) { lim := NewFixedWindowLimiter(-1) for range 5 { // Token always should be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("bucketSize=0", func(t *testing.T) { lim := NewFixedWindowLimiter(0) for range 5 { // Token always should be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("bucketSize=1", func(t *testing.T) { lim := NewFixedWindowLimiter(1) token1, token2 := lim.Accept(context.Background()), lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token1.OK()) - ztesting.AssertEqual(t, "incorrect token status", false, token2.OK()) + ztesting.AssertEqual(t, true, token1.OK()) + ztesting.AssertEqual(t, false, token2.OK()) }) t.Run("fillInterval=0", func(t *testing.T) { lim := NewFixedWindowLimiterWidth(1, 0) for range 5 { // Token always should be true. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) } }) } @@ -46,27 +46,27 @@ func TestNewTokenBucketInterval(t *testing.T) { lim := NewTokenBucketLimiter(-1, 1) for range 5 { // Token always should be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("bucketSize=0", func(t *testing.T) { lim := NewTokenBucketLimiter(0, 1) for range 5 { // Token always should be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("bucketSize=1", func(t *testing.T) { lim := NewTokenBucketLimiter(1, 1) token1, token2 := lim.Accept(context.Background()), lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token1.OK()) - ztesting.AssertEqual(t, "incorrect token status", false, token2.OK()) + ztesting.AssertEqual(t, true, token1.OK()) + ztesting.AssertEqual(t, false, token2.OK()) }) t.Run("fillInterval=0", func(t *testing.T) { lim := NewTokenBucketInterval(1, 1, 0) for range 5 { // Token always should be true. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) } }) } @@ -79,7 +79,7 @@ func TestNewLimiter(t *testing.T) { } for range 5 { // Token always should be false. token := lim.AllowNow() - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) } @@ -92,7 +92,7 @@ func TestBucketLimiter(t *testing.T) { } for range 5 { // Token always should be false. token := lim.AllowNow() - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("AllowNow returns OK token", func(t *testing.T) { @@ -101,7 +101,7 @@ func TestBucketLimiter(t *testing.T) { } for range 5 { // Token always should be true. token := lim.AllowNow() - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) } }) t.Run("WaitNow returns OK token", func(t *testing.T) { @@ -110,11 +110,11 @@ func TestBucketLimiter(t *testing.T) { } for range 5 { // Token always should be true. token := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) } for range 5 { // Token always should be false. token := lim.AllowNow() - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("retry after worked", func(t *testing.T) { @@ -124,12 +124,12 @@ func TestBucketLimiter(t *testing.T) { getToken: getTokenFunc(1, 1, time.Second, func() time.Time { return *now }), } token := lim.AllowNow() // Remove first token. - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) token = lim.AllowNow() // Now token should be false. - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) time.AfterFunc(time.Second, func() { *now = (*now).Add(time.Second) }) // Forward time after 1sec. token = lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) }) t.Run("context canceled", func(t *testing.T) { now := time.Now() @@ -137,12 +137,12 @@ func TestBucketLimiter(t *testing.T) { getToken: getTokenFunc(1, 1, time.Second, func() time.Time { return now }), } token := lim.AllowNow() // Remove first token. - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Second)) defer cancel() token = lim.WaitNow(ctx) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) - ztesting.AssertEqual(t, "incorrect error", context.DeadlineExceeded, token.Err()) + ztesting.AssertEqual(t, false, token.OK()) + ztesting.AssertEqual(t, context.DeadlineExceeded, token.Err()) }) } @@ -151,74 +151,74 @@ func TestBucket(t *testing.T) { t.Run("bucketSize=-1", func(t *testing.T) { getToken := getTokenFunc(-1, 10, time.Second, time.Now) ok, after := getToken() - ztesting.AssertEqual(t, "token unexpectedly true", false, ok) - ztesting.AssertEqual(t, "retry after time incorrect", math.MaxInt64, after) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, math.MaxInt64, after) }) t.Run("bucketSize=0", func(t *testing.T) { getToken := getTokenFunc(0, 10, time.Second, time.Now) ok, after := getToken() - ztesting.AssertEqual(t, "token unexpectedly true", false, ok) - ztesting.AssertEqual(t, "retry after time incorrect", math.MaxInt64, after) + ztesting.AssertEqual(t, false, ok) + ztesting.AssertEqual(t, math.MaxInt64, after) }) t.Run("interval=-1", func(t *testing.T) { getToken := getTokenFunc(1, 10, -1, time.Now) ok, after := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, 0, after) }) t.Run("interval=0", func(t *testing.T) { getToken := getTokenFunc(1, 10, 0, time.Now) ok, after := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after) + ztesting.AssertEqual(t, true, ok) + ztesting.AssertEqual(t, 0, after) }) t.Run("fillRate=-1", func(t *testing.T) { now := time.Now() getToken := getTokenFunc(1, -1, time.Hour, func() time.Time { return now }) ok1, after1 := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok1) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after1) + ztesting.AssertEqual(t, true, ok1) + ztesting.AssertEqual(t, 0, after1) ok2, after2 := getToken() - ztesting.AssertEqual(t, "token unexpectedly true", false, ok2) - ztesting.AssertEqual(t, "retry after time incorrect", time.Hour, after2) + ztesting.AssertEqual(t, false, ok2) + ztesting.AssertEqual(t, time.Hour, after2) }) t.Run("fillRate=0", func(t *testing.T) { now := time.Now() getToken := getTokenFunc(1, 0, time.Hour, func() time.Time { return now }) ok1, after1 := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok1) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after1) + ztesting.AssertEqual(t, true, ok1) + ztesting.AssertEqual(t, 0, after1) ok2, after2 := getToken() - ztesting.AssertEqual(t, "token unexpectedly true", false, ok2) - ztesting.AssertEqual(t, "retry after time incorrect", time.Hour, after2) + ztesting.AssertEqual(t, false, ok2) + ztesting.AssertEqual(t, time.Hour, after2) }) t.Run("fillRate=1", func(t *testing.T) { nowTime := time.Now() now := &nowTime getToken := getTokenFunc(1, 1, time.Second, func() time.Time { return *now }) ok1, after1 := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok1) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after1) + ztesting.AssertEqual(t, true, ok1) + ztesting.AssertEqual(t, 0, after1) *now = (*now).Add(time.Second) // Forward 1 sec. ok2, after2 := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok2) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after2) + ztesting.AssertEqual(t, true, ok2) + ztesting.AssertEqual(t, 0, after2) }) t.Run("fillRate=1,try3times", func(t *testing.T) { nowTime := time.Now() now := &nowTime getToken := getTokenFunc(1, 1, time.Second, func() time.Time { return *now }) ok1, after1 := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok1) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after1) + ztesting.AssertEqual(t, true, ok1) + ztesting.AssertEqual(t, 0, after1) *now = (*now).Add(time.Second) // Forward 1 sec. ok2, after2 := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok2) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after2) + ztesting.AssertEqual(t, true, ok2) + ztesting.AssertEqual(t, 0, after2) *now = (*now).Add(100 * time.Millisecond) // Forward 0.1 sec. ok3, after3 := getToken() - ztesting.AssertEqual(t, "token unexpectedly true", false, ok3) - ztesting.AssertEqual(t, "retry after time incorrect", 900*time.Millisecond, after3) + ztesting.AssertEqual(t, false, ok3) + ztesting.AssertEqual(t, 900*time.Millisecond, after3) }) t.Run("fillRate=2", func(t *testing.T) { nowTime := time.Now() @@ -227,14 +227,14 @@ func TestBucket(t *testing.T) { _, _ = getToken() // Remove first token. _, _ = getToken() // Remove second token. Now the bucket is empty. ok1, after1 := getToken() - ztesting.AssertEqual(t, "token unexpectedly true", false, ok1) - ztesting.AssertEqual(t, "retry after time incorrect", time.Second, after1) + ztesting.AssertEqual(t, false, ok1) + ztesting.AssertEqual(t, time.Second, after1) *now = (*now).Add(time.Second) // Forward 1 sec. ok2, after2 := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok2) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after2) + ztesting.AssertEqual(t, true, ok2) + ztesting.AssertEqual(t, 0, after2) ok3, after3 := getToken() - ztesting.AssertEqual(t, "token unexpectedly false", true, ok3) - ztesting.AssertEqual(t, "retry after time incorrect", 0, after3) + ztesting.AssertEqual(t, true, ok3) + ztesting.AssertEqual(t, 0, after3) }) } diff --git a/ztime/zrate/concurrent_test.go b/ztime/zrate/concurrent_test.go index fb0a0f9..1aeab2d 100644 --- a/ztime/zrate/concurrent_test.go +++ b/ztime/zrate/concurrent_test.go @@ -14,22 +14,22 @@ func TestNewConcurrentLimiter(t *testing.T) { lim := NewConcurrentLimiter(-1) for range 5 { // Token should always be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("limit=0", func(t *testing.T) { lim := NewConcurrentLimiter(0) for range 5 { // Token should always be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("limit=1", func(t *testing.T) { lim := NewConcurrentLimiter(1).(*ConcurrentLimiter) t1 := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "process allowed", false, t2.OK()) + ztesting.AssertEqual(t, false, t2.OK()) }) } @@ -38,30 +38,30 @@ func TestConcurrentLimiter_AllowNow(t *testing.T) { t.Run("limit=1", func(t *testing.T) { lim := NewConcurrentLimiter(1).(*ConcurrentLimiter) t1 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.AllowNow() - ztesting.AssertEqual(t, "process allowed", false, t2.OK()) + ztesting.AssertEqual(t, false, t2.OK()) }) t.Run("limit=2", func(t *testing.T) { lim := NewConcurrentLimiter(2).(*ConcurrentLimiter) t1 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t2.OK()) + ztesting.AssertEqual(t, true, t2.OK()) t3 := lim.AllowNow() - ztesting.AssertEqual(t, "process allowed", false, t3.OK()) + ztesting.AssertEqual(t, false, t3.OK()) }) t.Run("limit=2 and release", func(t *testing.T) { lim := NewConcurrentLimiter(2).(*ConcurrentLimiter) t1 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t2.OK()) + ztesting.AssertEqual(t, true, t2.OK()) t3 := lim.AllowNow() - ztesting.AssertEqual(t, "process allowed", false, t3.OK()) + ztesting.AssertEqual(t, false, t3.OK()) t1.Release() t4 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t4.OK()) + ztesting.AssertEqual(t, true, t4.OK()) }) } @@ -70,33 +70,33 @@ func TestConcurrentLimiter_WaitNow(t *testing.T) { t.Run("limit=1", func(t *testing.T) { lim := NewConcurrentLimiter(1).(*ConcurrentLimiter) t1 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) dc, cancel := context.WithDeadline(context.Background(), time.Now().Add(100*time.Millisecond)) defer cancel() t2 := lim.WaitNow(dc) - ztesting.AssertEqual(t, "process allowed", false, t2.OK()) - ztesting.AssertEqualErr(t, "wrong error reason", context.DeadlineExceeded, t2.Err()) + ztesting.AssertEqual(t, false, t2.OK()) + ztesting.AssertEqualErr(t, context.DeadlineExceeded, t2.Err()) }) t.Run("limit=2", func(t *testing.T) { lim := NewConcurrentLimiter(2).(*ConcurrentLimiter) t1 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t2.OK()) + ztesting.AssertEqual(t, true, t2.OK()) dc, cancel := context.WithDeadline(context.Background(), time.Now().Add(100*time.Millisecond)) defer cancel() t3 := lim.WaitNow(dc) - ztesting.AssertEqual(t, "process allowed", false, t3.OK()) - ztesting.AssertEqualErr(t, "wrong error reason", context.DeadlineExceeded, t3.Err()) + ztesting.AssertEqual(t, false, t3.OK()) + ztesting.AssertEqualErr(t, context.DeadlineExceeded, t3.Err()) }) t.Run("limit=2 and release", func(t *testing.T) { lim := NewConcurrentLimiter(2).(*ConcurrentLimiter) t1 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t2.OK()) + ztesting.AssertEqual(t, true, t2.OK()) t1.Release() t3 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t3.OK()) + ztesting.AssertEqual(t, true, t3.OK()) }) } diff --git a/ztime/zrate/leaky_test.go b/ztime/zrate/leaky_test.go index dee786b..3489fe2 100644 --- a/ztime/zrate/leaky_test.go +++ b/ztime/zrate/leaky_test.go @@ -15,36 +15,36 @@ func TestNewLeakyBucketLimiter(t *testing.T) { lim := NewLeakyBucketLimiter(-1, time.Second) for range 5 { // Token should always be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("queueSize=0", func(t *testing.T) { lim := NewLeakyBucketLimiter(0, time.Second) for range 5 { // Token should always be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("interval=-1sec", func(t *testing.T) { lim := NewLeakyBucketLimiter(1, -time.Second) for range 5 { // Token should always be true. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) } }) t.Run("interval=0", func(t *testing.T) { lim := NewLeakyBucketLimiter(1, 0) for range 5 { // Token should always be true. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) } }) t.Run("queueSize=1", func(t *testing.T) { lim := NewLeakyBucketLimiter(1, time.Second).(*LeakyBucketLimiter) t1 := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t2.OK()) + ztesting.AssertEqual(t, true, t2.OK()) }) } @@ -53,23 +53,23 @@ func TestLeakyBucketLimiter_AllowNow(t *testing.T) { t.Run("queueSize=1", func(t *testing.T) { lim := NewLeakyBucketLimiter(1, time.Second).(*LeakyBucketLimiter) t1 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.AllowNow() - ztesting.AssertEqual(t, "process allowed", false, t2.OK()) + ztesting.AssertEqual(t, false, t2.OK()) }) t.Run("queueSize=2", func(t *testing.T) { lim := NewLeakyBucketLimiter(2, time.Second).(*LeakyBucketLimiter) t1 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.AllowNow() - ztesting.AssertEqual(t, "process allowed", false, t2.OK()) + ztesting.AssertEqual(t, false, t2.OK()) }) t.Run("queueSize=2", func(t *testing.T) { lim := NewLeakyBucketLimiter(2, time.Second).(*LeakyBucketLimiter) t1 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.AllowNow() - ztesting.AssertEqual(t, "process allowed", false, t2.OK()) + ztesting.AssertEqual(t, false, t2.OK()) }) t.Run("interval passed", func(t *testing.T) { lim := NewLeakyBucketLimiter(2, time.Second).(*LeakyBucketLimiter) @@ -77,10 +77,10 @@ func TestLeakyBucketLimiter_AllowNow(t *testing.T) { now := &tm lim.timeNow = func() time.Time { return *now } t1 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) *now = now.Add(time.Second) t2 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", true, t2.OK()) + ztesting.AssertEqual(t, true, t2.OK()) }) t.Run("someone waiting", func(t *testing.T) { lim := NewLeakyBucketLimiter(5, time.Second).(*LeakyBucketLimiter) @@ -94,7 +94,7 @@ func TestLeakyBucketLimiter_AllowNow(t *testing.T) { } wg.Wait() // All 5 goroutine started. t1 := lim.AllowNow() - ztesting.AssertEqual(t, "process not allowed", false, t1.OK()) + ztesting.AssertEqual(t, false, t1.OK()) }) } @@ -103,19 +103,19 @@ func TestLeakyBucketLimiter_WaitNow(t *testing.T) { t.Run("queueSize=1, wait", func(t *testing.T) { lim := NewLeakyBucketLimiter(1, 100*time.Millisecond).(*LeakyBucketLimiter) t1 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) t2 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t2.OK()) + ztesting.AssertEqual(t, true, t2.OK()) }) t.Run("queueSize=1, context deadline error", func(t *testing.T) { lim := NewLeakyBucketLimiter(1, time.Second).(*LeakyBucketLimiter) t1 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) dc, cancel := context.WithDeadline(context.Background(), time.Now().Add(100*time.Millisecond)) defer cancel() t2 := lim.WaitNow(dc) - ztesting.AssertEqual(t, "process allowed", false, t2.OK()) - ztesting.AssertEqualErr(t, "wrong error reason", context.DeadlineExceeded, t2.Err()) + ztesting.AssertEqual(t, false, t2.OK()) + ztesting.AssertEqualErr(t, context.DeadlineExceeded, t2.Err()) }) t.Run("interval passed", func(t *testing.T) { lim := NewLeakyBucketLimiter(2, time.Second).(*LeakyBucketLimiter) @@ -123,10 +123,10 @@ func TestLeakyBucketLimiter_WaitNow(t *testing.T) { now := &tm lim.timeNow = func() time.Time { return *now } t1 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t1.OK()) + ztesting.AssertEqual(t, true, t1.OK()) *now = now.Add(time.Second) t2 := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "process not allowed", true, t2.OK()) + ztesting.AssertEqual(t, true, t2.OK()) }) t.Run("fully queue", func(t *testing.T) { lim := NewLeakyBucketLimiter(5, time.Second).(*LeakyBucketLimiter) @@ -142,7 +142,7 @@ func TestLeakyBucketLimiter_WaitNow(t *testing.T) { dc, cancel := context.WithDeadline(context.Background(), time.Now().Add(100*time.Millisecond)) defer cancel() t1 := lim.WaitNow(dc) - ztesting.AssertEqual(t, "process allowed", false, t1.OK()) + ztesting.AssertEqual(t, false, t1.OK()) }) t.Run("canceled context", func(t *testing.T) { lim := NewLeakyBucketLimiter(1, time.Minute).(*LeakyBucketLimiter) @@ -150,7 +150,7 @@ func TestLeakyBucketLimiter_WaitNow(t *testing.T) { cancel() lim.AllowNow() // Remove token if exists t1 := lim.WaitNow(dc) - ztesting.AssertEqual(t, "process allowed", false, t1.OK()) - ztesting.AssertEqualErr(t, "wrong error reason", context.DeadlineExceeded, t1.Err()) + ztesting.AssertEqual(t, false, t1.OK()) + ztesting.AssertEqualErr(t, context.DeadlineExceeded, t1.Err()) }) } diff --git a/ztime/zrate/rate_test.go b/ztime/zrate/rate_test.go index 6d50303..9ed3d6e 100644 --- a/ztime/zrate/rate_test.go +++ b/ztime/zrate/rate_test.go @@ -10,13 +10,13 @@ import ( func TestNoopToken(t *testing.T) { t.Parallel() t.Run("true", func(t *testing.T) { - ztesting.AssertEqual(t, "incorrect status of the token", true, TokenOK.OK()) - ztesting.AssertEqual(t, "non nil error returned", nil, TokenOK.Err()) + ztesting.AssertEqual(t, true, TokenOK.OK()) + ztesting.AssertEqual(t, nil, TokenOK.Err()) TokenOK.Release() // Nothing happens. Just for taking coverage. }) t.Run("false", func(t *testing.T) { - ztesting.AssertEqual(t, "incorrect status of the token", false, TokenNG.OK()) - ztesting.AssertEqual(t, "non nil error returned", nil, TokenNG.Err()) + ztesting.AssertEqual(t, false, TokenNG.OK()) + ztesting.AssertEqual(t, nil, TokenNG.Err()) TokenNG.Release() // Nothing happens. Just for taking coverage. }) } @@ -25,15 +25,15 @@ func TestToken(t *testing.T) { t.Parallel() t.Run("ok", func(t *testing.T) { tk := &token{ok: true} - ztesting.AssertEqual(t, "incorrect status of the token", true, tk.OK()) + ztesting.AssertEqual(t, true, tk.OK()) }) t.Run("ng", func(t *testing.T) { tk := &token{ok: false} - ztesting.AssertEqual(t, "incorrect status of the token", false, tk.OK()) + ztesting.AssertEqual(t, false, tk.OK()) }) t.Run("error", func(t *testing.T) { tk := &token{err: io.EOF} - ztesting.AssertEqual(t, "error mismatched", io.EOF, tk.Err()) + ztesting.AssertEqual(t, io.EOF, tk.Err()) }) t.Run("nil release func", func(t *testing.T) { tk := &token{releaseFunc: nil} @@ -42,11 +42,11 @@ func TestToken(t *testing.T) { t.Run("non nil release func", func(t *testing.T) { var callCount int tk := &token{releaseFunc: func() { callCount += 1 }} - ztesting.AssertEqual(t, "incorrect call count", 0, callCount) + ztesting.AssertEqual(t, 0, callCount) tk.Release() - ztesting.AssertEqual(t, "release func not executed", 1, callCount) + ztesting.AssertEqual(t, 1, callCount) tk.Release() tk.Release() - ztesting.AssertEqual(t, "release func called multiple times", 1, callCount) + ztesting.AssertEqual(t, 1, callCount) }) } diff --git a/ztime/zrate/sliding_test.go b/ztime/zrate/sliding_test.go index d03bd8c..0a69901 100644 --- a/ztime/zrate/sliding_test.go +++ b/ztime/zrate/sliding_test.go @@ -14,27 +14,27 @@ func TestNewSlidingWindowLimiterWidth(t *testing.T) { lim := NewSlidingWindowLimiter(-1) for range 5 { // Token always should be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("limit=0", func(t *testing.T) { lim := NewSlidingWindowLimiter(0) for range 5 { // Token always should be false. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("limit=1", func(t *testing.T) { lim := NewSlidingWindowLimiter(1) token1, token2 := lim.Accept(context.Background()), lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token1.OK()) - ztesting.AssertEqual(t, "incorrect token status", false, token2.OK()) + ztesting.AssertEqual(t, true, token1.OK()) + ztesting.AssertEqual(t, false, token2.OK()) }) t.Run("width=0", func(t *testing.T) { lim := NewSlidingWindowLimiterWidth(1, 0) for range 5 { // Token always should be true. token := lim.Accept(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) } }) } @@ -51,7 +51,7 @@ func TestSlidingWindowLimiter(t *testing.T) { } for range 5 { // Token always should be false. token := lim.AllowNow() - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("AllowNow returns OK token", func(t *testing.T) { @@ -62,7 +62,7 @@ func TestSlidingWindowLimiter(t *testing.T) { } for range 5 { // Token always should be true. token := lim.AllowNow() - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) } }) t.Run("WaitNow returns OK token", func(t *testing.T) { @@ -75,12 +75,12 @@ func TestSlidingWindowLimiter(t *testing.T) { for range 5 { // Token always should be true. println(lim.limit, lim.sum) token := lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) } for range 5 { // Token always should be false. println(lim.limit, lim.sum) token := lim.AllowNow() - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) } }) t.Run("retry after worked", func(t *testing.T) { @@ -94,12 +94,12 @@ func TestSlidingWindowLimiter(t *testing.T) { timeNow: func() time.Time { return *now }, } token := lim.AllowNow() // Remove first token. - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) token = lim.AllowNow() // Now token should be false. - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) + ztesting.AssertEqual(t, false, token.OK()) time.AfterFunc(time.Second, func() { *now = (*now).Add(100 * 100 * time.Millisecond) }) // Forward time after 1sec. token = lim.WaitNow(context.Background()) - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) }) t.Run("context canceled", func(t *testing.T) { now := time.Now() @@ -111,11 +111,11 @@ func TestSlidingWindowLimiter(t *testing.T) { timeNow: func() time.Time { return now }, } token := lim.AllowNow() // Remove first token. - ztesting.AssertEqual(t, "incorrect token status", true, token.OK()) + ztesting.AssertEqual(t, true, token.OK()) ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Second)) defer cancel() token = lim.WaitNow(ctx) - ztesting.AssertEqual(t, "incorrect token status", false, token.OK()) - ztesting.AssertEqual(t, "incorrect error", context.DeadlineExceeded, token.Err()) + ztesting.AssertEqual(t, false, token.OK()) + ztesting.AssertEqual(t, context.DeadlineExceeded, token.Err()) }) } diff --git a/zx/zlb/basic_test.go b/zx/zlb/basic_test.go index f350d76..d65cc81 100644 --- a/zx/zlb/basic_test.go +++ b/zx/zlb/basic_test.go @@ -102,17 +102,17 @@ func TestBasicRoundRobin_Get(t *testing.T) { lb := zlb.NewBasicRoundRobin(tc.targets...) if !tc.found { _, found := lb.Get(0) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) return } history := []string{} for range tc.names { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", tc.found, found) - ztesting.AssertEqual(t, "active status not match", true, tt.Active()) + ztesting.AssertEqual(t, tc.found, found) + ztesting.AssertEqual(t, true, tt.Active()) } - ztesting.AssertEqual(t, "history not match", tc.names, history) + ztesting.AssertEqual(t, tc.names, history) }) } } @@ -125,15 +125,15 @@ func TestBasicRoundRobin_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 2, weight: 1, active: true} lb := zlb.NewBasicRoundRobin(t0, t1, t2) lb.Remove(0) - ztesting.AssertEqual(t, "targets not match", []*Target{t1, t2}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t1, t2}, lb.Targets()) history := []string{} want := []string{"t1", "t1", "t2", "t1", "t1", "t2"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) t.Run("remove middle", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 2, active: true} @@ -141,15 +141,15 @@ func TestBasicRoundRobin_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 2, weight: 1, active: true} lb := zlb.NewBasicRoundRobin(t0, t1, t2) lb.Remove(1) - ztesting.AssertEqual(t, "targets not match", []*Target{t0, t2}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t0, t2}, lb.Targets()) history := []string{} want := []string{"t0", "t0", "t2", "t0", "t0", "t2"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) t.Run("remove last", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 1, active: true} @@ -157,15 +157,15 @@ func TestBasicRoundRobin_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 2, weight: 3, active: true} lb := zlb.NewBasicRoundRobin(t0, t1, t2) lb.Remove(2) - ztesting.AssertEqual(t, "targets not match", []*Target{t0, t1}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t0, t1}, lb.Targets()) history := []string{} want := []string{"t0", "t1", "t1", "t0", "t1", "t1"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) t.Run("remove multiple", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 1, active: true} @@ -173,15 +173,15 @@ func TestBasicRoundRobin_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 2, weight: 3, active: true} lb := zlb.NewBasicRoundRobin(t2, t0, t2, t2, t2, t1, t2, t2) lb.Remove(2) - ztesting.AssertEqual(t, "targets not match", []*Target{t0, t1}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t0, t1}, lb.Targets()) history := []string{} want := []string{"t0", "t1", "t1", "t0", "t1", "t1"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) t.Run("remove icurrent", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 1, active: true} @@ -226,15 +226,15 @@ func TestBasicRoundRobin_Remove(t *testing.T) { lb := zlb.NewBasicRoundRobin(t0, t1, t2) _, _ = lb.Get(0) // Current index is 0. lb.Remove(2) // Remove index 2. - ztesting.AssertEqual(t, "targets not match", []*Target{t0, t1}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t0, t1}, lb.Targets()) history := []string{} want := []string{"t1", "t0", "t1", "t0"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) t.Run("remove i=current at the end", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 1, active: true} @@ -245,14 +245,14 @@ func TestBasicRoundRobin_Remove(t *testing.T) { _, _ = lb.Get(0) // Current index is 1. _, _ = lb.Get(0) // Current index is 2. lb.Remove(2) // Remove index 1. - ztesting.AssertEqual(t, "targets not match", []*Target{t0, t1}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t0, t1}, lb.Targets()) history := []string{} want := []string{"t0", "t1", "t0", "t1"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) } diff --git a/zx/zlb/direct_test.go b/zx/zlb/direct_test.go index cfc396c..6b0a07b 100644 --- a/zx/zlb/direct_test.go +++ b/zx/zlb/direct_test.go @@ -123,12 +123,12 @@ func TestDirectHash_Get(t *testing.T) { lb := zlb.NewDirectHash(tc.targets...) lb.MaxRetry = 1 tt, found := lb.Get(tc.key) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) if !tc.found { return } - ztesting.AssertEqual(t, "target not match", tc.name, tt.name) - ztesting.AssertEqual(t, "active status not match", true, tt.Active()) + ztesting.AssertEqual(t, tc.name, tt.name) + ztesting.AssertEqual(t, true, tt.Active()) }) } } @@ -247,12 +247,12 @@ func TestDirectHashW_Get(t *testing.T) { t.Run(name, func(t *testing.T) { lb := zlb.NewDirectHashW(tc.targets...) tt, found := lb.Get(tc.key) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) if !tc.found { return } - ztesting.AssertEqual(t, "target not match", tc.name, tt.name) - ztesting.AssertEqual(t, "active status not match", true, tt.Active()) + ztesting.AssertEqual(t, tc.name, tt.name) + ztesting.AssertEqual(t, true, tt.Active()) }) } } diff --git a/zx/zlb/jump_test.go b/zx/zlb/jump_test.go index f5f54c6..8382f54 100644 --- a/zx/zlb/jump_test.go +++ b/zx/zlb/jump_test.go @@ -123,12 +123,12 @@ func TestJumpHash_Get(t *testing.T) { lb := zlb.NewJumpHash(tc.targets...) lb.MaxRetry = 1 tt, found := lb.Get(tc.key) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) if !tc.found { return } - ztesting.AssertEqual(t, "target not match", tc.name, tt.name) - ztesting.AssertEqual(t, "active status not match", true, tt.Active()) + ztesting.AssertEqual(t, tc.name, tt.name) + ztesting.AssertEqual(t, true, tt.Active()) }) } } diff --git a/zx/zlb/lb_test.go b/zx/zlb/lb_test.go index 5122594..4b81504 100644 --- a/zx/zlb/lb_test.go +++ b/zx/zlb/lb_test.go @@ -36,17 +36,17 @@ func TestBaseLB_Add(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Add(t1) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 1, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) + ztesting.AssertEqual(t, 1, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) }) t.Run("add multiple", func(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Add(t1, t2, t3) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 3, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t2", ts[1].name) - ztesting.AssertEqual(t, "index 2 not match", "t3", ts[2].name) + ztesting.AssertEqual(t, 3, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) + ztesting.AssertEqual(t, "t2", ts[1].name) + ztesting.AssertEqual(t, "t3", ts[2].name) }) } @@ -61,69 +61,69 @@ func TestBaseLB_Remove(t *testing.T) { t.Run("remove from empty", func(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Remove(1) - ztesting.AssertEqual(t, "length not match", 0, len(lb.targets)) + ztesting.AssertEqual(t, 0, len(lb.targets)) }) t.Run("remove not match", func(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Add(t1, t2, t3) lb.Remove(999) - ztesting.AssertEqual(t, "length not match", 3, len(lb.targets)) + ztesting.AssertEqual(t, 3, len(lb.targets)) }) t.Run("remove first", func(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Add(t1, t2, t3) lb.Remove(1) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t2", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t3", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t2", ts[0].name) + ztesting.AssertEqual(t, "t3", ts[1].name) }) t.Run("remove middle", func(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Add(t1, t2, t3) lb.Remove(2) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t3", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) + ztesting.AssertEqual(t, "t3", ts[1].name) }) t.Run("remove last", func(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Add(t1, t2, t3) lb.Remove(3) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t2", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) + ztesting.AssertEqual(t, "t2", ts[1].name) }) t.Run("remove multiple 1", func(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Add(t1, t2, t3, t1) lb.Remove(1) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t2", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t3", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t2", ts[0].name) + ztesting.AssertEqual(t, "t3", ts[1].name) }) t.Run("remove multiple 2", func(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Add(t1, t2, t2, t3) lb.Remove(2) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t3", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) + ztesting.AssertEqual(t, "t3", ts[1].name) }) t.Run("remove complex", func(t *testing.T) { lb := &baseLB[*testTarget]{} lb.Add(t1, t2, t3, t2, t2, t1, t3, t2) lb.Remove(2) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 4, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t3", ts[1].name) - ztesting.AssertEqual(t, "index 2 not match", "t1", ts[2].name) - ztesting.AssertEqual(t, "index 3 not match", "t3", ts[3].name) + ztesting.AssertEqual(t, 4, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) + ztesting.AssertEqual(t, "t3", ts[1].name) + ztesting.AssertEqual(t, "t1", ts[2].name) + ztesting.AssertEqual(t, "t3", ts[3].name) }) }) @@ -131,69 +131,69 @@ func TestBaseLB_Remove(t *testing.T) { t.Run("remove from empty", func(t *testing.T) { lb := &baseLB[*testTarget]{removeMode: 1} lb.Remove(1) - ztesting.AssertEqual(t, "length not match", 0, len(lb.targets)) + ztesting.AssertEqual(t, 0, len(lb.targets)) }) t.Run("remove not match", func(t *testing.T) { lb := &baseLB[*testTarget]{removeMode: 1} lb.Add(t1, t2, t3) lb.Remove(999) - ztesting.AssertEqual(t, "length not match", 3, len(lb.targets)) + ztesting.AssertEqual(t, 3, len(lb.targets)) }) t.Run("remove first", func(t *testing.T) { lb := &baseLB[*testTarget]{removeMode: 1} lb.Add(t1, t2, t3) lb.Remove(1) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t3", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t2", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t3", ts[0].name) + ztesting.AssertEqual(t, "t2", ts[1].name) }) t.Run("remove middle", func(t *testing.T) { lb := &baseLB[*testTarget]{removeMode: 1} lb.Add(t1, t2, t3) lb.Remove(2) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t3", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) + ztesting.AssertEqual(t, "t3", ts[1].name) }) t.Run("remove last", func(t *testing.T) { lb := &baseLB[*testTarget]{removeMode: 1} lb.Add(t1, t2, t3) lb.Remove(3) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t2", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) + ztesting.AssertEqual(t, "t2", ts[1].name) }) t.Run("remove multiple 1", func(t *testing.T) { lb := &baseLB[*testTarget]{removeMode: 1} lb.Add(t1, t2, t3, t1) lb.Remove(1) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t3", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t2", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t3", ts[0].name) + ztesting.AssertEqual(t, "t2", ts[1].name) }) t.Run("remove multiple 2", func(t *testing.T) { lb := &baseLB[*testTarget]{removeMode: 1} lb.Add(t1, t2, t2, t3) lb.Remove(2) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 2, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t3", ts[1].name) + ztesting.AssertEqual(t, 2, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) + ztesting.AssertEqual(t, "t3", ts[1].name) }) t.Run("remove complex", func(t *testing.T) { lb := &baseLB[*testTarget]{removeMode: 1} lb.Add(t1, t2, t3, t2, t2, t1, t3, t2) lb.Remove(2) ts := lb.Targets() - ztesting.AssertEqual(t, "length not match", 4, len(ts)) - ztesting.AssertEqual(t, "index 0 not match", "t1", ts[0].name) - ztesting.AssertEqual(t, "index 1 not match", "t3", ts[1].name) - ztesting.AssertEqual(t, "index 2 not match", "t3", ts[2].name) - ztesting.AssertEqual(t, "index 3 not match", "t1", ts[3].name) + ztesting.AssertEqual(t, 4, len(ts)) + ztesting.AssertEqual(t, "t1", ts[0].name) + ztesting.AssertEqual(t, "t3", ts[1].name) + ztesting.AssertEqual(t, "t3", ts[2].name) + ztesting.AssertEqual(t, "t1", ts[3].name) }) }) } diff --git a/zx/zlb/maglev_internal_test.go b/zx/zlb/maglev_internal_test.go index cd1844e..f05fad9 100644 --- a/zx/zlb/maglev_internal_test.go +++ b/zx/zlb/maglev_internal_test.go @@ -1,7 +1,6 @@ package zlb import ( - "strconv" "testing" "github.com/aileron-projects/go/ztesting" @@ -28,7 +27,7 @@ func TestGenPrimeEuler(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { prime := genPrimeEuler(tc.min) - ztesting.AssertEqual(t, "prime number not match", tc.want, prime) + ztesting.AssertEqual(t, tc.want, prime) }) } @@ -96,7 +95,7 @@ func TestIsPrime(t *testing.T) { t.Run(name, func(t *testing.T) { for _, num := range tc.num { prime := isPrime(num) - ztesting.AssertEqual(t, "isPrime not match: "+strconv.Itoa(num), tc.prime, prime) + ztesting.AssertEqual(t, tc.prime, prime) } }) } diff --git a/zx/zlb/maglev_test.go b/zx/zlb/maglev_test.go index 26a2b70..c8cb160 100644 --- a/zx/zlb/maglev_test.go +++ b/zx/zlb/maglev_test.go @@ -122,12 +122,12 @@ func TestMaglev_Get(t *testing.T) { t.Run(name, func(t *testing.T) { lb := zlb.NewMaglev(tc.targets...) tt, found := lb.Get(tc.key) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) if !tc.found { return } - ztesting.AssertEqual(t, "target not match", tc.name, tt.name) - ztesting.AssertEqual(t, "active status not match", true, tt.Active()) + ztesting.AssertEqual(t, tc.name, tt.name) + ztesting.AssertEqual(t, true, tt.Active()) }) } } @@ -139,12 +139,12 @@ func TestMaglev_Get_stateChanges(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 1, active: true} lb := zlb.NewMaglev(t0, t1, t2) tt, found := lb.Get(12345) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) lb.Remove(999111) tt, found = lb.Get(12345) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t0", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t0", tt.name) } func TestMaglev_Remove(t *testing.T) { @@ -155,12 +155,12 @@ func TestMaglev_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 1, active: true} lb := zlb.NewMaglev(t0, t1, t2) tt, found := lb.Get(1234) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t0", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t0", tt.name) lb.Remove(999000) tt, found = lb.Get(1234) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) }) t.Run("remove middle", func(t *testing.T) { t0 := &Target{name: "t0", id: 999000, weight: 2, active: true} @@ -168,12 +168,12 @@ func TestMaglev_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 1, active: true} lb := zlb.NewMaglev(t0, t1, t2) tt, found := lb.Get(12345678) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) lb.Remove(999111) tt, found = lb.Get(12345678) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t0", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t0", tt.name) }) t.Run("remove last", func(t *testing.T) { t0 := &Target{name: "t0", id: 999000, weight: 1, active: true} @@ -181,11 +181,11 @@ func TestMaglev_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 3, active: true} lb := zlb.NewRingHash(t0, t1, t2) tt, found := lb.Get(123456) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t2", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t2", tt.name) lb.Remove(999222) tt, found = lb.Get(123456) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) }) } diff --git a/zx/zlb/priority_test.go b/zx/zlb/priority_test.go index b242340..059e601 100644 --- a/zx/zlb/priority_test.go +++ b/zx/zlb/priority_test.go @@ -101,11 +101,11 @@ func TestPriority_Get(t *testing.T) { t.Run(name, func(t *testing.T) { lb := zlb.NewRoundRobin(tc.targets...) tt, found := lb.Get(0) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) if !tc.found { return } - ztesting.AssertEqual(t, "target not match", tc.name, tt.name) + ztesting.AssertEqual(t, tc.name, tt.name) }) } } @@ -119,8 +119,8 @@ func TestPriority_Remove(t *testing.T) { lb := zlb.NewPriority(t0, t1, t2) lb.Remove(0) tt, found := lb.Get(0) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) }) t.Run("remove middle", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 2, active: true} @@ -129,8 +129,8 @@ func TestPriority_Remove(t *testing.T) { lb := zlb.NewPriority(t0, t1, t2) lb.Remove(1) tt, found := lb.Get(0) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t0", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t0", tt.name) }) t.Run("remove last", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 1, active: true} @@ -139,7 +139,7 @@ func TestPriority_Remove(t *testing.T) { lb := zlb.NewPriority(t0, t1, t2) lb.Remove(2) tt, found := lb.Get(0) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) }) } diff --git a/zx/zlb/random_test.go b/zx/zlb/random_test.go index 6f81eef..403065b 100644 --- a/zx/zlb/random_test.go +++ b/zx/zlb/random_test.go @@ -75,11 +75,11 @@ func TestRandom_Get(t *testing.T) { lb := zlb.NewRandom(tc.targets...) lb.MaxRetry = 1 tt, found := lb.Get(0) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) if !tc.found { return } - ztesting.AssertEqual(t, "active status not match", true, tt.Active()) + ztesting.AssertEqual(t, true, tt.Active()) }) } } @@ -90,11 +90,11 @@ func TestRandomW_Get(t *testing.T) { t.Run(name, func(t *testing.T) { lb := zlb.NewRandomW(tc.targets...) tt, found := lb.Get(0) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) if !tc.found { return } - ztesting.AssertEqual(t, "active status not match", true, tt.Active()) + ztesting.AssertEqual(t, true, tt.Active()) }) } } diff --git a/zx/zlb/rendezvous_test.go b/zx/zlb/rendezvous_test.go index a9a44a2..6f15937 100644 --- a/zx/zlb/rendezvous_test.go +++ b/zx/zlb/rendezvous_test.go @@ -122,12 +122,12 @@ func TestRendezvousHash_Get(t *testing.T) { t.Run(name, func(t *testing.T) { lb := zlb.NewRendezvousHash(tc.targets...) tt, found := lb.Get(tc.key) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) if !tc.found { return } - ztesting.AssertEqual(t, "target not match", tc.name, tt.name) - ztesting.AssertEqual(t, "active status not match", true, tt.Active()) + ztesting.AssertEqual(t, tc.name, tt.name) + ztesting.AssertEqual(t, true, tt.Active()) }) } } @@ -140,12 +140,12 @@ func TestRendezvousHash_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 1, active: true} lb := zlb.NewRendezvousHash(t0, t1, t2) tt, found := lb.Get(12345) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t0", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t0", tt.name) lb.Remove(999000) tt, found = lb.Get(12345) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) }) t.Run("remove middle", func(t *testing.T) { t0 := &Target{name: "t0", id: 999000, weight: 2, active: true} @@ -153,12 +153,12 @@ func TestRendezvousHash_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 1, active: true} lb := zlb.NewRendezvousHash(t0, t1, t2) tt, found := lb.Get(123456) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) lb.Remove(999111) tt, found = lb.Get(123456) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t0", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t0", tt.name) }) t.Run("remove last", func(t *testing.T) { t0 := &Target{name: "t0", id: 999000, weight: 1, active: true} @@ -166,11 +166,11 @@ func TestRendezvousHash_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 3, active: true} lb := zlb.NewRingHash(t0, t1, t2) tt, found := lb.Get(12345678) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t2", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t2", tt.name) lb.Remove(999222) tt, found = lb.Get(12345678) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) }) } diff --git a/zx/zlb/ring_test.go b/zx/zlb/ring_test.go index 8457a0e..ba81f40 100644 --- a/zx/zlb/ring_test.go +++ b/zx/zlb/ring_test.go @@ -122,12 +122,12 @@ func TestRingHash_Get(t *testing.T) { t.Run(name, func(t *testing.T) { lb := zlb.NewRingHash(tc.targets...) tt, found := lb.Get(tc.key) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) if !tc.found { return } - ztesting.AssertEqual(t, "target not match", tc.name, tt.name) - ztesting.AssertEqual(t, "active status not match", true, tt.Active()) + ztesting.AssertEqual(t, tc.name, tt.name) + ztesting.AssertEqual(t, true, tt.Active()) }) } } @@ -140,13 +140,13 @@ func TestRingHash_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 1, active: true} lb := zlb.NewRingHash(t0, t1, t2) tt, found := lb.Get(123) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t0", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t0", tt.name) lb.Remove(999000) lb.Update() tt, found = lb.Get(123) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t2", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t2", tt.name) }) t.Run("remove middle", func(t *testing.T) { t0 := &Target{name: "t0", id: 999000, weight: 2, active: true} @@ -154,13 +154,13 @@ func TestRingHash_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 1, active: true} lb := zlb.NewRingHash(t0, t1, t2) tt, found := lb.Get(12345) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) lb.Remove(999111) lb.Update() tt, found = lb.Get(12345) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t2", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t2", tt.name) }) t.Run("remove last", func(t *testing.T) { t0 := &Target{name: "t0", id: 999000, weight: 1, active: true} @@ -168,13 +168,13 @@ func TestRingHash_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 999222, weight: 3, active: true} lb := zlb.NewRingHash(t0, t1, t2) tt, found := lb.Get(12345678) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t2", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t2", tt.name) lb.Remove(999222) lb.Update() tt, found = lb.Get(12345678) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) }) } @@ -184,7 +184,7 @@ func TestRingHash_Update(t *testing.T) { lb := zlb.NewRingHash[*Target]() lb.Update() _, found := lb.Get(123) - ztesting.AssertEqual(t, "found not match", false, found) + ztesting.AssertEqual(t, false, found) }) t.Run("same weight", func(t *testing.T) { t0 := &Target{name: "t0", id: 999000, weight: 5, active: true} @@ -193,8 +193,8 @@ func TestRingHash_Update(t *testing.T) { lb := zlb.NewRingHash(t0, t1, t2) lb.Update() tt, found := lb.Get(123) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t1", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t1", tt.name) }) t.Run("same id", func(t *testing.T) { t0 := &Target{name: "t0", id: 123, weight: 2, active: true} @@ -203,10 +203,10 @@ func TestRingHash_Update(t *testing.T) { lb := zlb.NewRingHash(t0, t1, t2) lb.Update() tt, found := lb.Get(123) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t0", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t0", tt.name) tt, found = lb.Get(456) - ztesting.AssertEqual(t, "found not match", true, found) - ztesting.AssertEqual(t, "target not match", "t0", tt.name) + ztesting.AssertEqual(t, true, found) + ztesting.AssertEqual(t, "t0", tt.name) }) } diff --git a/zx/zlb/roundrobin_test.go b/zx/zlb/roundrobin_test.go index 3d968dc..ee6ed8d 100644 --- a/zx/zlb/roundrobin_test.go +++ b/zx/zlb/roundrobin_test.go @@ -102,17 +102,17 @@ func TestRoundRobin_Get(t *testing.T) { lb := zlb.NewRoundRobin(tc.targets...) if !tc.found { _, found := lb.Get(0) - ztesting.AssertEqual(t, "found not match", tc.found, found) + ztesting.AssertEqual(t, tc.found, found) return } history := []string{} for range tc.names { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", tc.found, found) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, tc.found, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", tc.names, history) + ztesting.AssertEqual(t, tc.names, history) }) } } @@ -125,15 +125,15 @@ func TestRoundRobin_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 2, weight: 1, active: true} lb := zlb.NewRoundRobin(t0, t1, t2) lb.Remove(0) - ztesting.AssertEqual(t, "targets not match", []*Target{t1, t2}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t1, t2}, lb.Targets()) history := []string{} want := []string{"t1", "t2", "t1", "t1", "t2"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) t.Run("remove middle", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 2, active: true} @@ -141,15 +141,15 @@ func TestRoundRobin_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 2, weight: 1, active: true} lb := zlb.NewRoundRobin(t0, t1, t2) lb.Remove(1) - ztesting.AssertEqual(t, "targets not match", []*Target{t0, t2}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t0, t2}, lb.Targets()) history := []string{} want := []string{"t0", "t2", "t0", "t0", "t2"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) t.Run("remove last", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 1, active: true} @@ -157,15 +157,15 @@ func TestRoundRobin_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 2, weight: 3, active: true} lb := zlb.NewRoundRobin(t0, t1, t2) lb.Remove(2) - ztesting.AssertEqual(t, "targets not match", []*Target{t0, t1}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t0, t1}, lb.Targets()) history := []string{} want := []string{"t1", "t0", "t1", "t1", "t0"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) t.Run("remove multiple", func(t *testing.T) { t0 := &Target{name: "t0", id: 0, weight: 1, active: true} @@ -173,14 +173,14 @@ func TestRoundRobin_Remove(t *testing.T) { t2 := &Target{name: "t2", id: 2, weight: 3, active: true} lb := zlb.NewRoundRobin(t2, t0, t2, t2, t2, t1, t2, t2) lb.Remove(2) - ztesting.AssertEqual(t, "targets not match", []*Target{t0, t1}, lb.Targets()) + ztesting.AssertEqual(t, []*Target{t0, t1}, lb.Targets()) history := []string{} want := []string{"t1", "t0", "t1", "t1", "t0"} for range want { tt, found := lb.Get(0) history = append(history, tt.name) - ztesting.AssertEqual(t, "found not match", true, found) + ztesting.AssertEqual(t, true, found) } - ztesting.AssertEqual(t, "history not match", want, history) + ztesting.AssertEqual(t, want, history) }) } diff --git a/zx/ztext/ztransform/transform_test.go b/zx/ztext/ztransform/transform_test.go index e22978a..560cf5e 100644 --- a/zx/ztext/ztransform/transform_test.go +++ b/zx/ztext/ztransform/transform_test.go @@ -51,8 +51,8 @@ func TestString(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got, err := ztransform.String(tc.t, tc.input) - ztesting.AssertEqual(t, "string not match", tc.want, got) - ztesting.AssertEqual(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.want, got) + ztesting.AssertEqual(t, tc.err, err) }) } } @@ -84,8 +84,8 @@ func TestBytes(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got, err := ztransform.Bytes(tc.t, []byte(tc.input)) - ztesting.AssertEqual(t, "bytes not match", tc.want, string(got)) - ztesting.AssertEqual(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.want, string(got)) + ztesting.AssertEqual(t, tc.err, err) }) } } @@ -114,12 +114,12 @@ func TestStringSlice(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got, err := ztransform.StringSlice(tc.t, tc.input) - ztesting.AssertEqual(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.err, err) if err != nil { - ztesting.AssertEqual(t, "non zeo length slice returned", 0, len(got)) + ztesting.AssertEqual(t, 0, len(got)) return } - ztesting.AssertEqual(t, "string slice not match", tc.want, got) + ztesting.AssertEqual(t, tc.want, got) }) } } @@ -148,13 +148,13 @@ func TestBytesSlice(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { got, err := ztransform.BytesSlice(tc.t, tc.input) - ztesting.AssertEqual(t, "error not match", tc.err, err) + ztesting.AssertEqual(t, tc.err, err) if err != nil { - ztesting.AssertEqual(t, "non zeo length slice returned", 0, len(got)) + ztesting.AssertEqual(t, 0, len(got)) return } for i := range tc.want { - ztesting.AssertEqual(t, "bytes slice not match", tc.want[i], got[i]) + ztesting.AssertEqual(t, tc.want[i], got[i]) } }) } diff --git a/zx/zuid/context_test.go b/zx/zuid/context_test.go index 882a1ea..0d27c75 100644 --- a/zx/zuid/context_test.go +++ b/zx/zuid/context_test.go @@ -13,17 +13,17 @@ func TestContextWithID(t *testing.T) { t.Run("nil context", func(t *testing.T) { ctx := zuid.ContextWithID(nil, "key", "test-uid") uid := zuid.FromContext(ctx, "key") - ztesting.AssertEqual(t, "uid not match", "test-uid", uid) + ztesting.AssertEqual(t, "test-uid", uid) }) t.Run("non-nil context", func(t *testing.T) { ctx := zuid.ContextWithID(context.Background(), "key", "test-uid") uid := zuid.FromContext(ctx, "key") - ztesting.AssertEqual(t, "uid not match", "test-uid", uid) + ztesting.AssertEqual(t, "test-uid", uid) }) t.Run("key not match", func(t *testing.T) { ctx := zuid.ContextWithID(context.Background(), "key1", "test-uid") uid := zuid.FromContext(ctx, "key2") - ztesting.AssertEqual(t, "uid not match", "", uid) + ztesting.AssertEqual(t, "", uid) }) } @@ -31,20 +31,20 @@ func TestFromContext(t *testing.T) { t.Parallel() t.Run("nil context", func(t *testing.T) { uid := zuid.FromContext(nil, "key") - ztesting.AssertEqual(t, "uid not match", "", uid) + ztesting.AssertEqual(t, "", uid) }) t.Run("no uid", func(t *testing.T) { uid := zuid.FromContext(context.Background(), "key") - ztesting.AssertEqual(t, "uid not match", "", uid) + ztesting.AssertEqual(t, "", uid) }) t.Run("non-nil context", func(t *testing.T) { ctx := zuid.ContextWithID(context.Background(), "key", "test-uid") uid := zuid.FromContext(ctx, "key") - ztesting.AssertEqual(t, "uid not match", "test-uid", uid) + ztesting.AssertEqual(t, "test-uid", uid) }) t.Run("key not match", func(t *testing.T) { ctx := zuid.ContextWithID(context.Background(), "key1", "test-uid") uid := zuid.FromContext(ctx, "key2") - ztesting.AssertEqual(t, "uid not match", "", uid) + ztesting.AssertEqual(t, "", uid) }) } diff --git a/zx/zuid/uid_test.go b/zx/zuid/uid_test.go index 3514583..591da0b 100644 --- a/zx/zuid/uid_test.go +++ b/zx/zuid/uid_test.go @@ -17,15 +17,15 @@ func TestMustFNV1a64Hash(t *testing.T) { t.Parallel() t.Run("nil error", func(t *testing.T) { b := mustFNV1a64Hash("test", nil) - ztesting.AssertEqual(t, "hash not match", "f9e6e6ef197c2b25", hex.EncodeToString(b)) + ztesting.AssertEqual(t, "f9e6e6ef197c2b25", hex.EncodeToString(b)) }) t.Run("non-nil error", func(t *testing.T) { defer func() { err := recover().(error) - ztesting.AssertEqualErr(t, "panicked error not match", io.EOF, err) + ztesting.AssertEqualErr(t, io.EOF, err) }() b := mustFNV1a64Hash("test", io.EOF) - ztesting.AssertEqual(t, "hash not match", "", hex.EncodeToString(b)) + ztesting.AssertEqual(t, "", hex.EncodeToString(b)) }) } @@ -39,8 +39,8 @@ func TestNewTime(t *testing.T) { done := ztesting.ReplaceRandReader(rr) defer done() id := NewTime() - ztesting.AssertEqual(t, "id length not match", 30, len(id)) - ztesting.AssertEqual(t, "time not match", 946684800_000_000, binary.BigEndian.Uint64(id[0:8])) + ztesting.AssertEqual(t, 30, len(id)) + ztesting.AssertEqual(t, 946684800_000_000, binary.BigEndian.Uint64(id[0:8])) } func TestNewHost(t *testing.T) { @@ -54,9 +54,9 @@ func TestNewHost(t *testing.T) { done := ztesting.ReplaceRandReader(rr) defer done() id := NewHost() - ztesting.AssertEqual(t, "id length not match", 30, len(id)) - ztesting.AssertEqual(t, "time not match", 946684800_000_000, binary.BigEndian.Uint64(id[0:8])) - ztesting.AssertEqual(t, "hostname not match", "host1234", string(id[8:16])) + ztesting.AssertEqual(t, 30, len(id)) + ztesting.AssertEqual(t, 946684800_000_000, binary.BigEndian.Uint64(id[0:8])) + ztesting.AssertEqual(t, "host1234", string(id[8:16])) } func TestNewCount(t *testing.T) { @@ -71,7 +71,7 @@ func TestNewCount(t *testing.T) { counter = atomic.Uint64{} counter.Store(math.MaxUint64 - 1) id := NewCount() - ztesting.AssertEqual(t, "id length not match", 30, len(id)) - ztesting.AssertEqual(t, "time not match", 946684800_000_000, binary.BigEndian.Uint64(id[0:8])) - ztesting.AssertEqual(t, "counter not match", uint64(math.MaxUint64), binary.BigEndian.Uint64(id[22:])) + ztesting.AssertEqual(t, 30, len(id)) + ztesting.AssertEqual(t, 946684800_000_000, binary.BigEndian.Uint64(id[0:8])) + ztesting.AssertEqual(t, uint64(math.MaxUint64), binary.BigEndian.Uint64(id[22:])) } From 62738fd3f0e9c03ae5b552533200eea573ffeb72 Mon Sep 17 00:00:00 2001 From: k7a-tomohiro <83070078+k7a-tomohiro@users.noreply.github.com> Date: Tue, 21 Apr 2026 08:54:04 +0900 Subject: [PATCH 2/3] fix lint error --- go.mod | 2 +- zcrypto/zargon2/argon2.go | 12 ++-- zcrypto/zhmac/benchmark_test.go | 2 - zcrypto/zmd4/benchmark_test.go | 26 -------- zcrypto/zmd4/example_test.go | 41 ------------- zcrypto/zmd4/md4.go | 47 --------------- zcrypto/zmd4/md4_test.go | 89 ---------------------------- zcrypto/zpbkdf2/pbkdf2.go | 6 +- zcrypto/zripemd160/benchmark_test.go | 26 -------- zcrypto/zripemd160/example_test.go | 41 ------------- zcrypto/zripemd160/ripemd160.go | 47 --------------- zcrypto/zripemd160/ripemd160_test.go | 89 ---------------------------- zcrypto/zscrypt/scrypt.go | 6 +- zcrypto/zsha3/benchmark_test.go | 14 ----- zcrypto/zsha3/example_test.go | 35 ----------- zcrypto/zsha3/sha3.go | 55 ++++------------- zcrypto/zsha3/sha3_test.go | 6 +- zencoding/zxml/badgerfish_decode.go | 13 ++-- zencoding/zxml/rayfish_decode.go | 13 ++-- zencoding/zxml/simple_decode.go | 13 ++-- zlog/manager.go | 16 ++--- 21 files changed, 57 insertions(+), 542 deletions(-) delete mode 100644 zcrypto/zmd4/benchmark_test.go delete mode 100644 zcrypto/zmd4/example_test.go delete mode 100644 zcrypto/zmd4/md4.go delete mode 100644 zcrypto/zmd4/md4_test.go delete mode 100644 zcrypto/zripemd160/benchmark_test.go delete mode 100644 zcrypto/zripemd160/example_test.go delete mode 100644 zcrypto/zripemd160/ripemd160.go delete mode 100644 zcrypto/zripemd160/ripemd160_test.go diff --git a/go.mod b/go.mod index bc202c6..35cdf6d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/aileron-projects/go -go 1.25 +go 1.26 require ( github.com/davecgh/go-spew v1.1.1 diff --git a/zcrypto/zargon2/argon2.go b/zcrypto/zargon2/argon2.go index a567001..de4feae 100644 --- a/zcrypto/zargon2/argon2.go +++ b/zcrypto/zargon2/argon2.go @@ -80,11 +80,13 @@ func (c *Argon2i) Split(hashedPW []byte) (salt, hash []byte, err error) { // Salt is joined at the left side of the returned sum. // Use [Argon2i.Split] to split salt and the sum of the password. func (c *Argon2i) Sum(password []byte) ([]byte, error) { - salt := make([]byte, c.saltLen) + sum := make([]byte, c.saltLen+int(c.keyLen)) + salt := sum[:c.saltLen] _, err := rand.Read(salt) must.Nil(err) hashed := argon2.Key(password, salt, c.time, c.memory, c.threads, c.keyLen) - return append(salt, hashed...), nil + copy(sum[c.saltLen:], hashed) + return sum, nil } // Equal reports if the given hashed password and the password @@ -171,11 +173,13 @@ func (c *Argon2id) Split(hashedPW []byte) (salt, hash []byte, err error) { // Use [Argon2id.Split] to split salt and the sum of the password. // [Argon2id.Sum] always returns nil as error. func (c *Argon2id) Sum(password []byte) ([]byte, error) { - salt := make([]byte, c.saltLen) + sum := make([]byte, c.saltLen+int(c.keyLen)) + salt := sum[:c.saltLen] _, err := rand.Read(salt) must.Nil(err) hashed := argon2.IDKey(password, salt, c.time, c.memory, c.threads, c.keyLen) - return append(salt, hashed...), nil + copy(sum[c.saltLen:], hashed) + return sum, nil } // Equal reports if the given hashed password and the password diff --git a/zcrypto/zhmac/benchmark_test.go b/zcrypto/zhmac/benchmark_test.go index 4f86e25..6c5d389 100644 --- a/zcrypto/zhmac/benchmark_test.go +++ b/zcrypto/zhmac/benchmark_test.go @@ -7,9 +7,7 @@ import ( _ "github.com/aileron-projects/go/zcrypto/zblake2b" _ "github.com/aileron-projects/go/zcrypto/zblake2s" "github.com/aileron-projects/go/zcrypto/zhmac" - _ "github.com/aileron-projects/go/zcrypto/zmd4" _ "github.com/aileron-projects/go/zcrypto/zmd5" - _ "github.com/aileron-projects/go/zcrypto/zripemd160" _ "github.com/aileron-projects/go/zcrypto/zsha1" _ "github.com/aileron-projects/go/zcrypto/zsha256" _ "github.com/aileron-projects/go/zcrypto/zsha3" diff --git a/zcrypto/zmd4/benchmark_test.go b/zcrypto/zmd4/benchmark_test.go deleted file mode 100644 index 82ba31e..0000000 --- a/zcrypto/zmd4/benchmark_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package zmd4_test - -import ( - "testing" - - "github.com/aileron-projects/go/zcrypto/zmd4" -) - -var ( - msg = []byte("Go is an open source programming language that makes it simple to build secure, scalable systems.") - key = []byte("12345678901234567890123456789012") -) - -func BenchmarkSum(b *testing.B) { - b.ResetTimer() - for b.Loop() { - zmd4.Sum(msg) - } -} - -func BenchmarkHMACSum(b *testing.B) { - b.ResetTimer() - for b.Loop() { - zmd4.HMACSum(msg, key) - } -} diff --git a/zcrypto/zmd4/example_test.go b/zcrypto/zmd4/example_test.go deleted file mode 100644 index c8a60ad..0000000 --- a/zcrypto/zmd4/example_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package zmd4_test - -import ( - "encoding/hex" - "fmt" - - "github.com/aileron-projects/go/zcrypto/zmd4" -) - -func ExampleSum() { - // Calculate MD4 hash. - // Validation data can be generated with: - // - echo -n "Hello Go!" | openssl dgst -md4 - - sum := zmd4.Sum([]byte("Hello Go!")) - encoded := hex.EncodeToString(sum) - fmt.Println(len(sum), encoded) - fmt.Println("`Hello Go!` match?", zmd4.EqualSum([]byte("Hello Go!"), sum)) - fmt.Println("`Bye Go!` match?", zmd4.EqualSum([]byte("Bye Go!"), sum)) - // Output: - // 16 38b77b3efd9016c334cb3b45da2bb00e - // `Hello Go!` match? true - // `Bye Go!` match? false -} - -func ExampleHMACSum() { - // Calculate HMAC-MD4 hash. - // Validation data can be generated with: - // - echo -n "Hello Go!" | openssl dgst -hmac "secret-key" -md4 - - key := []byte("secret-key") - sum := zmd4.HMACSum([]byte("Hello Go!"), key) - encoded := hex.EncodeToString(sum) - fmt.Println(len(sum), encoded) - fmt.Println("`Hello Go!` match?", zmd4.HMACEqualSum([]byte("Hello Go!"), key, sum)) - fmt.Println("`Bye Go!` match?", zmd4.HMACEqualSum([]byte("Bye Go!"), key, sum)) - // Output: - // 16 ac740e3ffa02eabe6ffd06a216bd1447 - // `Hello Go!` match? true - // `Bye Go!` match? false -} diff --git a/zcrypto/zmd4/md4.go b/zcrypto/zmd4/md4.go deleted file mode 100644 index fb4adf9..0000000 --- a/zcrypto/zmd4/md4.go +++ /dev/null @@ -1,47 +0,0 @@ -package zmd4 - -import ( - "bytes" - "crypto/hmac" - - "github.com/aileron-projects/go/zcrypto/internal" - "golang.org/x/crypto/md4" -) - -var ( - _ internal.SumFunc = Sum - _ internal.EqualSumFunc = EqualSum -) - -// Sum returns MD4 hash. -// It uses [golang.org/x/crypto/md4.New]. -func Sum(b []byte) []byte { - h := md4.New() - _, _ = h.Write(b) - return h.Sum(make([]byte, 0, md4.Size)) -} - -// EqualSum compares MD4 hash. -// It returns if the sum matches to the hash of b. -func EqualSum(b []byte, sum []byte) bool { - return bytes.Equal(Sum(b), sum) -} - -var ( - _ internal.HMACSumFunc = HMACSum - _ internal.HMACEqualSumFunc = HMACEqualSum -) - -// HMACSum returns HMAC-MD4 hash. -// It uses [crypto/md4.New]. -func HMACSum(msg, key []byte) []byte { - mac := hmac.New(md4.New, key) - _, _ = mac.Write(msg) - return mac.Sum(make([]byte, 0, md4.Size)) -} - -// HMACEqualSum compares HMAC-MD4 hash. -// It returns if the sum matches to the hash of msg. -func HMACEqualSum(msg, key, sum []byte) bool { - return bytes.Equal(HMACSum(msg, key), sum) -} diff --git a/zcrypto/zmd4/md4_test.go b/zcrypto/zmd4/md4_test.go deleted file mode 100644 index ff04b8a..0000000 --- a/zcrypto/zmd4/md4_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package zmd4_test - -import ( - "encoding/hex" - "slices" - "testing" - - "github.com/aileron-projects/go/zcrypto/zmd4" - "github.com/aileron-projects/go/ztesting" -) - -// hashSum is the msg and sum list. -// Validation data is generated with: -// - echo -n "test" | openssl dgst -md4 -var hashSum = []struct { - name string - sf func(msg []byte) []byte - eqf func(msg, sum []byte) bool - msg string - sum string // Hex encoded sum. -}{ - {"case01", zmd4.Sum, zmd4.EqualSum, "", "31d6cfe0d16ae931b73c59d7e0c089c0"}, - {"case02", zmd4.Sum, zmd4.EqualSum, "test", "db346d691d7acc4dc2625db19f9e3f52"}, -} - -func TestSum(t *testing.T) { - t.Parallel() - for _, tc := range hashSum { - t.Run(tc.msg, func(t *testing.T) { - got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) - }) - } -} - -func TestEqualSum(t *testing.T) { - t.Parallel() - for _, tc := range hashSum { - t.Run(tc.name, func(t *testing.T) { - sum, _ := hex.DecodeString(tc.sum) - equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, true, equal) - slices.Reverse(sum) // Make the sum wrong. - equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, false, equal) - }) - } -} - -// hmacSum is the msg,key and sum list. -// Validation data can be generated with: -// - echo -n "test" | openssl dgst -hmac "key" -md4 -var hmacSum = []struct { - name string - sf func(msg, key []byte) []byte - eqf func(msg, key, sum []byte) bool - msg, key string // Hash - sum string // Hex encoded sum. -}{ - {"case01", zmd4.HMACSum, zmd4.HMACEqualSum, "test", "key", "d6e28d7a7ac0d1a91d1a9bf8c95f7a2a"}, - {"case02", zmd4.HMACSum, zmd4.HMACEqualSum, "", "", "c8d444e3153b538850e7850fa84bb247"}, - {"case03", zmd4.HMACSum, zmd4.HMACEqualSum, "", "key", "1d31e4a9de766cd2d5bbcb2a54ba57ee"}, - {"case04", zmd4.HMACSum, zmd4.HMACEqualSum, "test", "", "49f1bcf2f3278bc0163b558a72352b9d"}, -} - -func TestHMACSum(t *testing.T) { - t.Parallel() - for _, tc := range hmacSum { - t.Run(tc.name, func(t *testing.T) { - sum := tc.sf([]byte(tc.msg), []byte(tc.key)) - got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, tc.sum, got) - }) - } -} - -func TestHMACEqualSum(t *testing.T) { - t.Parallel() - for _, tc := range hmacSum { - t.Run(tc.name, func(t *testing.T) { - sum, _ := hex.DecodeString(tc.sum) - equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, true, equal) - slices.Reverse(sum) // Make the sum wrong. - equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, false, equal) - }) - } -} diff --git a/zcrypto/zpbkdf2/pbkdf2.go b/zcrypto/zpbkdf2/pbkdf2.go index 950b1bc..ee8ce65 100644 --- a/zcrypto/zpbkdf2/pbkdf2.go +++ b/zcrypto/zpbkdf2/pbkdf2.go @@ -93,11 +93,13 @@ func (c *PBKDF2) Split(hashedPW []byte) (salt, hash []byte, err error) { // Use [PBKDF2.Split] to split salt and the sum of the password. // [PBKDF2.Sum] always returns nil as error. func (c *PBKDF2) Sum(password []byte) ([]byte, error) { - salt := make([]byte, c.saltLen) + sum := make([]byte, c.saltLen+c.keyLen) + salt := sum[:c.saltLen] _, err := rand.Read(salt) must.Nil(err) hashed := pbkdf2.Key(password, salt, c.iter, c.keyLen, c.hashFunc) - return append(salt, hashed...), nil + copy(sum[c.saltLen:], hashed) + return sum, nil } // Equal reports if the given hashed password and the password diff --git a/zcrypto/zripemd160/benchmark_test.go b/zcrypto/zripemd160/benchmark_test.go deleted file mode 100644 index 9c4a386..0000000 --- a/zcrypto/zripemd160/benchmark_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package zripemd160_test - -import ( - "testing" - - "github.com/aileron-projects/go/zcrypto/zripemd160" -) - -var ( - msg = []byte("Go is an open source programming language that makes it simple to build secure, scalable systems.") - key = []byte("12345678901234567890123456789012") -) - -func BenchmarkSum(b *testing.B) { - b.ResetTimer() - for b.Loop() { - zripemd160.Sum(msg) - } -} - -func BenchmarkHMACSum(b *testing.B) { - b.ResetTimer() - for b.Loop() { - zripemd160.HMACSum(msg, key) - } -} diff --git a/zcrypto/zripemd160/example_test.go b/zcrypto/zripemd160/example_test.go deleted file mode 100644 index 8b8abcf..0000000 --- a/zcrypto/zripemd160/example_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package zripemd160_test - -import ( - "encoding/hex" - "fmt" - - "github.com/aileron-projects/go/zcrypto/zripemd160" -) - -func ExampleSum() { - // Calculate RIPEMD160 hash. - // Validation data can be generated with: - // - echo -n "Hello Go!" | openssl dgst -ripemd160 - - sum := zripemd160.Sum([]byte("Hello Go!")) - encoded := hex.EncodeToString(sum) - fmt.Println(len(sum), encoded) - fmt.Println("`Hello Go!` match?", zripemd160.EqualSum([]byte("Hello Go!"), sum)) - fmt.Println("`Bye Go!` match?", zripemd160.EqualSum([]byte("Bye Go!"), sum)) - // Output: - // 20 26f145fad89981009615a9af777a10ef700a3bba - // `Hello Go!` match? true - // `Bye Go!` match? false -} - -func ExampleHMACSum() { - // Calculate HMAC-RIPEMD160 hash. - // Validation data can be generated with: - // - echo -n "Hello Go!" | openssl dgst -hmac "secret-key" -ripemd160 - - key := []byte("secret-key") - sum := zripemd160.HMACSum([]byte("Hello Go!"), key) - encoded := hex.EncodeToString(sum) - fmt.Println(len(sum), encoded) - fmt.Println("`Hello Go!` match?", zripemd160.HMACEqualSum([]byte("Hello Go!"), key, sum)) - fmt.Println("`Bye Go!` match?", zripemd160.HMACEqualSum([]byte("Bye Go!"), key, sum)) - // Output: - // 20 3528a42c06620b2162e5ad8311e40a8f5bded07b - // `Hello Go!` match? true - // `Bye Go!` match? false -} diff --git a/zcrypto/zripemd160/ripemd160.go b/zcrypto/zripemd160/ripemd160.go deleted file mode 100644 index c2dfcb4..0000000 --- a/zcrypto/zripemd160/ripemd160.go +++ /dev/null @@ -1,47 +0,0 @@ -package zripemd160 - -import ( - "bytes" - "crypto/hmac" - - "github.com/aileron-projects/go/zcrypto/internal" - "golang.org/x/crypto/ripemd160" -) - -var ( - _ internal.SumFunc = Sum - _ internal.EqualSumFunc = EqualSum -) - -// Sum returns RIPEMD160 hash. -// It uses [crypto/ripemd160.New]. -func Sum(b []byte) []byte { - h := ripemd160.New() - _, _ = h.Write(b) - return h.Sum(make([]byte, 0, ripemd160.Size)) -} - -// EqualSum compares RIPEMD160 hash. -// It returns if the sum matches to the hash of b. -func EqualSum(b []byte, sum []byte) bool { - return bytes.Equal(Sum(b), sum) -} - -var ( - _ internal.HMACSumFunc = HMACSum - _ internal.HMACEqualSumFunc = HMACEqualSum -) - -// HMACSum returns HMAC-RIPEMD160 hash. -// It uses [crypto/ripemd160.New]. -func HMACSum(msg, key []byte) []byte { - mac := hmac.New(ripemd160.New, key) - _, _ = mac.Write(msg) - return mac.Sum(make([]byte, 0, ripemd160.Size)) -} - -// HMACEqualSum compares HMAC-RIPEMD160 hash. -// It returns if the sum matches to the hash of msg. -func HMACEqualSum(msg, key, sum []byte) bool { - return bytes.Equal(HMACSum(msg, key), sum) -} diff --git a/zcrypto/zripemd160/ripemd160_test.go b/zcrypto/zripemd160/ripemd160_test.go deleted file mode 100644 index 65d2c49..0000000 --- a/zcrypto/zripemd160/ripemd160_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package zripemd160_test - -import ( - "encoding/hex" - "slices" - "testing" - - "github.com/aileron-projects/go/zcrypto/zripemd160" - "github.com/aileron-projects/go/ztesting" -) - -// hashSum is the msg and sum list. -// Validation data is generated with: -// - echo -n "test" | openssl dgst -ripemd160 -var hashSum = []struct { - name string - sf func(msg []byte) []byte - eqf func(msg, sum []byte) bool - msg string - sum string // Hex encoded sum. -}{ - {"case01", zripemd160.Sum, zripemd160.EqualSum, "", "9c1185a5c5e9fc54612808977ee8f548b2258d31"}, - {"case02", zripemd160.Sum, zripemd160.EqualSum, "test", "5e52fee47e6b070565f74372468cdc699de89107"}, -} - -func TestSum(t *testing.T) { - t.Parallel() - for _, tc := range hashSum { - t.Run(tc.msg, func(t *testing.T) { - got := tc.sf([]byte(tc.msg)) - ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) - }) - } -} - -func TestEqualSum(t *testing.T) { - t.Parallel() - for _, tc := range hashSum { - t.Run(tc.name, func(t *testing.T) { - sum, _ := hex.DecodeString(tc.sum) - equal := tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, true, equal) - slices.Reverse(sum) // Make the sum wrong. - equal = tc.eqf([]byte(tc.msg), sum) - ztesting.AssertEqual(t, false, equal) - }) - } -} - -// hmacSum is the msg,key and sum list. -// Validation data can be generated with: -// - echo -n "test" | openssl dgst -hmac "key" -ripemd160 -var hmacSum = []struct { - name string - sf func(msg, key []byte) []byte - eqf func(msg, key, sum []byte) bool - msg, key string // Hash - sum string // Hex encoded sum. -}{ - {"case01", zripemd160.HMACSum, zripemd160.HMACEqualSum, "test", "key", "b434297d1e00df816b1e5d056b9f7fed8e1e1a19"}, - {"case02", zripemd160.HMACSum, zripemd160.HMACEqualSum, "", "", "44d86b658a3e7cbc1a2010848b53e35c917720ca"}, - {"case03", zripemd160.HMACSum, zripemd160.HMACEqualSum, "", "key", "eb123f0b89091ba4cb169cc0142520ebe3aa094e"}, - {"case04", zripemd160.HMACSum, zripemd160.HMACEqualSum, "test", "", "0ca12a8497e2b0f588a5e37dfbc3a1615c6bfc0f"}, -} - -func TestHMACSum(t *testing.T) { - t.Parallel() - for _, tc := range hmacSum { - t.Run(tc.name, func(t *testing.T) { - sum := tc.sf([]byte(tc.msg), []byte(tc.key)) - got := hex.EncodeToString(sum) - ztesting.AssertEqual(t, tc.sum, got) - }) - } -} - -func TestHMACEqualSum(t *testing.T) { - t.Parallel() - for _, tc := range hmacSum { - t.Run(tc.name, func(t *testing.T) { - sum, _ := hex.DecodeString(tc.sum) - equal := tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, true, equal) - slices.Reverse(sum) // Make the sum wrong. - equal = tc.eqf([]byte(tc.msg), []byte(tc.key), sum) - ztesting.AssertEqual(t, false, equal) - }) - } -} diff --git a/zcrypto/zscrypt/scrypt.go b/zcrypto/zscrypt/scrypt.go index 9f2d946..11c2544 100644 --- a/zcrypto/zscrypt/scrypt.go +++ b/zcrypto/zscrypt/scrypt.go @@ -76,14 +76,16 @@ func (c *SCrypt) Split(hashedPW []byte) (salt, hash []byte, err error) { // Salt is joined at the left side of the returned sum. // Use [SCrypt.Split] to split salt and the sum of the password. func (c *SCrypt) Sum(password []byte) ([]byte, error) { - salt := make([]byte, c.saltLen) + sum := make([]byte, c.saltLen+c.keyLen) + salt := sum[:c.saltLen] _, err := rand.Read(salt) must.Nil(err) hashed, err := scrypt.Key(password, salt, c.n, c.r, c.p, c.keyLen) if err != nil { return nil, err } - return append(salt, hashed...), nil + copy(sum[c.saltLen:], hashed) + return sum, nil } // Equal reports if the given hashed password and the password diff --git a/zcrypto/zsha3/benchmark_test.go b/zcrypto/zsha3/benchmark_test.go index 7758549..8924f9c 100644 --- a/zcrypto/zsha3/benchmark_test.go +++ b/zcrypto/zsha3/benchmark_test.go @@ -39,20 +39,6 @@ func BenchmarkSum512(b *testing.B) { } } -func BenchmarkSumShake128(b *testing.B) { - b.ResetTimer() - for b.Loop() { - zsha3.SumShake128(msg) - } -} - -func BenchmarkSumShake256(b *testing.B) { - b.ResetTimer() - for b.Loop() { - zsha3.SumShake256(msg) - } -} - func BenchmarkHMACSum224(b *testing.B) { b.ResetTimer() for b.Loop() { diff --git a/zcrypto/zsha3/example_test.go b/zcrypto/zsha3/example_test.go index 499f183..b3f2d58 100644 --- a/zcrypto/zsha3/example_test.go +++ b/zcrypto/zsha3/example_test.go @@ -71,41 +71,6 @@ func ExampleSum512() { // `Bye Go!` match? false } -func ExampleSumShake128() { - // Calculate SHAKE128 hash. - // Validation data can be generated with(-oflen option requires openssl v3): - // - echo -n "Hello Go!" | openssl dgst -shake128 -xoflen 32 - // - https://www.cryptool.org/en/cto/openssl/ - - sum := zsha3.SumShake128([]byte("Hello Go!")) - encoded := hex.EncodeToString(sum) - fmt.Println(len(sum), encoded) - fmt.Println("`Hello Go!` match?", zsha3.EqualSumShake128([]byte("Hello Go!"), sum)) - fmt.Println("`Bye Go!` match?", zsha3.EqualSumShake128([]byte("Bye Go!"), sum)) - // Output: - // 32 d52544db366d156a3ed524fc3d928d489d49a85c10cd268c64c6f0055dce4a5b - // `Hello Go!` match? true - // `Bye Go!` match? false -} - -func ExampleSumShake256() { - // Calculate SHAKE256 hash. - // Validation data can be generated with: - // Validation data can be generated with(-oflen option requires openssl v3): - // - echo -n "Hello Go!" | openssl dgst -shake256 -xoflen 64 - // - https://www.cryptool.org/en/cto/openssl/ - - sum := zsha3.SumShake256([]byte("Hello Go!")) - encoded := hex.EncodeToString(sum) - fmt.Println(len(sum), encoded) - fmt.Println("`Hello Go!` match?", zsha3.EqualSumShake256([]byte("Hello Go!"), sum)) - fmt.Println("`Bye Go!` match?", zsha3.EqualSumShake256([]byte("Bye Go!"), sum)) - // Output: - // 64 755bb7002e7cbd7282cd87f4a702ba9d98573de35378fd78451bcb6a41ebf138c4035ab9b92e4d6f1041c604d0348d6d0009f1db3419560b745f3c31e6bfc463 - // `Hello Go!` match? true - // `Bye Go!` match? false -} - func ExampleHMACSum224() { // Calculate HMAC-SHA3/224 hash. // Validation data can be generated with: diff --git a/zcrypto/zsha3/sha3.go b/zcrypto/zsha3/sha3.go index d72b857..1d0314f 100644 --- a/zcrypto/zsha3/sha3.go +++ b/zcrypto/zsha3/sha3.go @@ -3,9 +3,10 @@ package zsha3 import ( "bytes" "crypto/hmac" + "crypto/sha3" + "hash" "github.com/aileron-projects/go/zcrypto/internal" - "golang.org/x/crypto/sha3" ) var ( @@ -13,20 +14,16 @@ var ( _ internal.SumFunc = Sum256 _ internal.SumFunc = Sum384 _ internal.SumFunc = Sum512 - _ internal.SumFunc = SumShake128 - _ internal.SumFunc = SumShake256 _ internal.EqualSumFunc = EqualSum224 _ internal.EqualSumFunc = EqualSum256 _ internal.EqualSumFunc = EqualSum384 _ internal.EqualSumFunc = EqualSum512 - _ internal.EqualSumFunc = EqualSumShake128 - _ internal.EqualSumFunc = EqualSumShake256 ) // Sum224 returns SHA3/224 hash. // It uses [crypto/sha3.New224]. func Sum224(b []byte) []byte { - h := sha3.New224() + h := hash.Hash(sha3.New224()) _, _ = h.Write(b) return h.Sum(make([]byte, 0, h.Size())) } @@ -34,7 +31,7 @@ func Sum224(b []byte) []byte { // Sum256 returns SHA3/256 hash. // It uses [crypto/sha3.New256]. func Sum256(b []byte) []byte { - h := sha3.New256() + h := hash.Hash(sha3.New256()) _, _ = h.Write(b) return h.Sum(make([]byte, 0, h.Size())) } @@ -42,7 +39,7 @@ func Sum256(b []byte) []byte { // Sum384 returns SHA3/384 hash. // It uses [crypto/sha3.New384]. func Sum384(b []byte) []byte { - h := sha3.New384() + h := hash.Hash(sha3.New384()) _, _ = h.Write(b) return h.Sum(make([]byte, 0, h.Size())) } @@ -50,27 +47,7 @@ func Sum384(b []byte) []byte { // Sum512 returns SHA3/512 hash. // It uses [crypto/sha3.New512]. func Sum512(b []byte) []byte { - h := sha3.New512() - _, _ = h.Write(b) - return h.Sum(make([]byte, 0, h.Size())) -} - -// SumShake128 returns SHAKE128 hash. -// Digest size is fixed to 256 bit. -// Use [crypto/sha3.ShakeHash] directory if variable length digest are necessary. -// It uses [crypto/sha3.NewShake128]. -func SumShake128(b []byte) []byte { - h := sha3.NewShake128() - _, _ = h.Write(b) - return h.Sum(make([]byte, 0, h.Size())) -} - -// SumShake256 returns SHAKE256 hash. -// Digest size is fixed to 512 bit. -// Use [crypto/sha3.ShakeHash] directory if variable length digest are necessary. -// It uses [crypto/sha3.NewShake256]. -func SumShake256(b []byte) []byte { - h := sha3.NewShake256() + h := hash.Hash(sha3.New512()) _, _ = h.Write(b) return h.Sum(make([]byte, 0, h.Size())) } @@ -99,18 +76,6 @@ func EqualSum512(b []byte, sum []byte) bool { return bytes.Equal(Sum512(b), sum) } -// EqualSumShake128 compares SHAKE128 hash. -// It returns if the sum matches to the hash of b. -func EqualSumShake128(b []byte, sum []byte) bool { - return bytes.Equal(SumShake128(b), sum) -} - -// EqualSumShake256 compares SHAKE256 hash. -// It returns if the sum matches to the hash of b. -func EqualSumShake256(b []byte, sum []byte) bool { - return bytes.Equal(SumShake256(b), sum) -} - var ( _ internal.HMACSumFunc = HMACSum224 _ internal.HMACSumFunc = HMACSum256 @@ -125,7 +90,7 @@ var ( // HMACSum224 returns HMAC-SHA3/224 hash. // It uses [crypto/sha3.New224]. func HMACSum224(msg, key []byte) []byte { - mac := hmac.New(sha3.New224, key) + mac := hmac.New(func() hash.Hash { return sha3.New224() }, key) _, _ = mac.Write(msg) return mac.Sum(make([]byte, 0, mac.Size())) } @@ -133,7 +98,7 @@ func HMACSum224(msg, key []byte) []byte { // HMACSum256 returns HMAC-SHA3/256 hash. // It uses [crypto/sha3.New256]. func HMACSum256(msg, key []byte) []byte { - mac := hmac.New(sha3.New256, key) + mac := hmac.New(func() hash.Hash { return sha3.New256() }, key) _, _ = mac.Write(msg) return mac.Sum(make([]byte, 0, mac.Size())) } @@ -141,7 +106,7 @@ func HMACSum256(msg, key []byte) []byte { // HMACSum384 returns HMAC-SHA3/384 hash. // It uses [crypto/sha3.New384]. func HMACSum384(msg, key []byte) []byte { - mac := hmac.New(sha3.New384, key) + mac := hmac.New(func() hash.Hash { return sha3.New384() }, key) _, _ = mac.Write(msg) return mac.Sum(make([]byte, 0, mac.Size())) } @@ -149,7 +114,7 @@ func HMACSum384(msg, key []byte) []byte { // HMACSum512 returns HMAC-SHA3/512 hash. // It uses [crypto/sha3.New512]. func HMACSum512(msg, key []byte) []byte { - mac := hmac.New(sha3.New512, key) + mac := hmac.New(func() hash.Hash { return sha3.New512() }, key) _, _ = mac.Write(msg) return mac.Sum(make([]byte, 0, mac.Size())) } diff --git a/zcrypto/zsha3/sha3_test.go b/zcrypto/zsha3/sha3_test.go index 7b86139..3aad1f5 100644 --- a/zcrypto/zsha3/sha3_test.go +++ b/zcrypto/zsha3/sha3_test.go @@ -32,16 +32,12 @@ var hashSum = []struct { {"case06", zsha3.Sum384, zsha3.EqualSum384, "test", "e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7ff0f1b41eecb9db3ff219007c4e097260d58621bd"}, {"case07", zsha3.Sum512, zsha3.EqualSum512, "", "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26"}, {"case08", zsha3.Sum512, zsha3.EqualSum512, "test", "9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7b710110c0a678288166e7fbe796883a4f2e9b3ca9f484f521d0ce464345cc1aec96779149c14"}, - {"case09", zsha3.SumShake128, zsha3.EqualSumShake128, "", "7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26"}, - {"case10", zsha3.SumShake128, zsha3.EqualSumShake128, "test", "d3b0aa9cd8b7255622cebc631e867d4093d6f6010191a53973c45fec9b07c774"}, - {"case11", zsha3.SumShake256, zsha3.EqualSumShake256, "", "46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be"}, - {"case12", zsha3.SumShake256, zsha3.EqualSumShake256, "test", "b54ff7255705a71ee2925e4a3e30e41aed489a579d5595e0df13e32e1e4dd202a7c7f68b31d6418d9845eb4d757adda6ab189e1bb340db818e5b3bc725d992fa"}, } func TestSum(t *testing.T) { t.Parallel() for _, tc := range hashSum { - t.Run(tc.msg, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { got := tc.sf([]byte(tc.msg)) ztesting.AssertEqual(t, tc.sum, hex.EncodeToString(got)) }) diff --git a/zencoding/zxml/badgerfish_decode.go b/zencoding/zxml/badgerfish_decode.go index 17e4651..b3e4a07 100644 --- a/zencoding/zxml/badgerfish_decode.go +++ b/zencoding/zxml/badgerfish_decode.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/xml" "io" + "strings" ) // Decode decodes XML document read by the decoder into Go values. @@ -54,7 +55,7 @@ func (b *BadgerFish) decode(decoder *xml.Decoder, start xml.StartElement, end xm // Convert attributes into map object. attrs := b.attrsToMap(start.Attr) - var text string + var text strings.Builder var keys []string var children []any @@ -71,9 +72,9 @@ Loop: continue // Ignore text with only space characters. } if b.TrimSpace { - text += string(trimmed) + text.WriteString(string(trimmed)) } else { - text += string(t) + text.WriteString(string(t)) } case xml.StartElement: content, err := b.decode(decoder, t, t.End()) @@ -94,14 +95,14 @@ Loop: // Convert XML text value to JSON value. var val any if b.JSONValue != nil { - v, err := b.JSONValue(text, start) + v, err := b.JSONValue(text.String(), start) if err != nil { return nil, err } val = v } else { - if text != "" { - val = text + if text.String() != "" { + val = text.String() } } diff --git a/zencoding/zxml/rayfish_decode.go b/zencoding/zxml/rayfish_decode.go index 30021e0..10085e2 100644 --- a/zencoding/zxml/rayfish_decode.go +++ b/zencoding/zxml/rayfish_decode.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/xml" "io" + "strings" ) // Decode decodes XML document read by the decoder into Go values. @@ -61,7 +62,7 @@ func (r *RayFish) decode(decoder *xml.Decoder, start xml.StartElement, end xml.E }) } - var text string + var text strings.Builder Loop: for { token, err := decoder.RawToken() @@ -81,9 +82,9 @@ Loop: continue // Ignore text with only space characters. } if r.TrimSpace { - text += string(trimmed) + text.WriteString(string(trimmed)) } else { - text += string(t) + text.WriteString(string(t)) } case xml.EndElement: if t == end { @@ -93,15 +94,15 @@ Loop: } // Convert XML text value to JSON value. - var val any = text + var val any = text.String() if r.JSONValue != nil { - v, err := r.JSONValue(text, start) + v, err := r.JSONValue(text.String(), start) if err != nil { return nil, err } val = v } else { - if text == "" { + if text.String() == "" { val = r.emptyVal } } diff --git a/zencoding/zxml/simple_decode.go b/zencoding/zxml/simple_decode.go index fe41f84..f5bcd15 100644 --- a/zencoding/zxml/simple_decode.go +++ b/zencoding/zxml/simple_decode.go @@ -5,6 +5,7 @@ import ( "encoding/xml" "io" "slices" + "strings" ) // Decode decodes XML document read by the decoder into Go values. @@ -58,7 +59,7 @@ func (s *Simple) parseContent(decoder *xml.Decoder, start xml.StartElement, end attrs[attrName(attr.Name, s.AttrPrefix, s.NamespaceSep)] = attr.Value } - var text string + var text strings.Builder var keys []string var children []any @@ -75,9 +76,9 @@ Loop: continue // Ignore text with only space characters. } if s.TrimSpace { - text += string(trimmed) + text.WriteString(string(trimmed)) } else { - text += string(t) + text.WriteString(string(t)) } case xml.StartElement: content, err := s.parseContent(decoder, t, t.End()) @@ -103,14 +104,14 @@ Loop: // Convert XML text value to JSON value. var val any if s.JSONValue != nil { - v, err := s.JSONValue(text, start) + v, err := s.JSONValue(text.String(), start) if err != nil { return nil, err } val = v } else { - if text != "" { - val = text + if text.String() != "" { + val = text.String() } } diff --git a/zlog/manager.go b/zlog/manager.go index 2389016..d8ebb6c 100644 --- a/zlog/manager.go +++ b/zlog/manager.go @@ -348,21 +348,21 @@ func formatFileName(format string, t time.Time, index int) (str string, ok bool) } switch char { case 'Y': - _, _ = builder.WriteString(fmt.Sprintf("%04d", year)) + _, _ = fmt.Fprintf(&builder, "%04d", year) case 'M': - _, _ = builder.WriteString(fmt.Sprintf("%02d", month)) + _, _ = fmt.Fprintf(&builder, "%02d", month) case 'D': - _, _ = builder.WriteString(fmt.Sprintf("%02d", day)) + _, _ = fmt.Fprintf(&builder, "%02d", day) case 'h': - _, _ = builder.WriteString(fmt.Sprintf("%02d", t.Hour())) + _, _ = fmt.Fprintf(&builder, "%02d", t.Hour()) case 'm': - _, _ = builder.WriteString(fmt.Sprintf("%02d", t.Minute())) + _, _ = fmt.Fprintf(&builder, "%02d", t.Minute()) case 's': - _, _ = builder.WriteString(fmt.Sprintf("%02d", t.Second())) + _, _ = fmt.Fprintf(&builder, "%02d", t.Second()) case 'u': - _, _ = builder.WriteString(strconv.FormatInt(t.Unix(), 10)) + _, _ = fmt.Fprint(&builder, strconv.FormatInt(t.Unix(), 10)) case 'i': - _, _ = builder.WriteString(strconv.Itoa(index)) + _, _ = fmt.Fprint(&builder, strconv.Itoa(index)) default: return "", false // Invalid '%'. } From d0566de406deb039b7eeacb9eb5bcb90def454cb Mon Sep 17 00:00:00 2001 From: k7a-tomohiro <83070078+k7a-tomohiro@users.noreply.github.com> Date: Tue, 21 Apr 2026 09:03:14 +0900 Subject: [PATCH 3/3] fix lint error --- devtools/http-server/main.go | 2 +- znet/internal/server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/http-server/main.go b/devtools/http-server/main.go index f6fa866..1f28d4c 100644 --- a/devtools/http-server/main.go +++ b/devtools/http-server/main.go @@ -31,7 +31,7 @@ func main() { fmt.Fprintln(w, "Hello Go!!") fmt.Fprintln(w, "It's", time.Now()) fmt.Fprintln(w, strings.Repeat("-", 50)) - fmt.Fprintln(w, spew.Sdump(r)) + fmt.Fprintln(w, spew.Sdump(r)) // #nosec G705: XSS via taint analysis (gosec) }), ReadTimeout: 30 * time.Second, } diff --git a/znet/internal/server.go b/znet/internal/server.go index 96ccd04..39aa4c1 100644 --- a/znet/internal/server.go +++ b/znet/internal/server.go @@ -68,7 +68,7 @@ func (r *ServerRunner) Run(sigCtx context.Context) error { if r.ShutdownTimeout > 0 { timeout = r.ShutdownTimeout } - shutdownCtx, cancel := context.WithTimeout(context.Background(), timeout) + shutdownCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), timeout) defer cancel() err := r.Shutdown(shutdownCtx) // Graceful shutdown. if err == context.DeadlineExceeded {