From b201195fa1b2f393f4622abb66256ed403a6eda4 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Mon, 16 Dec 2024 17:41:47 +0800 Subject: [PATCH] common: improve test (#20354) --- common/bytes_test.go | 52 +++++++++++++++++++++++--------------------- common/main_test.go | 25 --------------------- 2 files changed, 27 insertions(+), 50 deletions(-) delete mode 100644 common/main_test.go diff --git a/common/bytes_test.go b/common/bytes_test.go index 97dd34d159dee..7cf6553377fd4 100644 --- a/common/bytes_test.go +++ b/common/bytes_test.go @@ -19,41 +19,43 @@ package common import ( "bytes" "testing" - - checker "gopkg.in/check.v1" ) -type BytesSuite struct{} - -var _ = checker.Suite(&BytesSuite{}) +func TestCopyBytes(t *testing.T) { + input := []byte{1, 2, 3, 4} -func (s *BytesSuite) TestCopyBytes(c *checker.C) { - data1 := []byte{1, 2, 3, 4} - exp1 := []byte{1, 2, 3, 4} - res1 := CopyBytes(data1) - c.Assert(res1, checker.DeepEquals, exp1) + v := CopyBytes(input) + if !bytes.Equal(v, []byte{1, 2, 3, 4}) { + t.Fatal("not equal after copy") + } + v[0] = 99 + if bytes.Equal(v, input) { + t.Fatal("result is not a copy") + } } -func (s *BytesSuite) TestLeftPadBytes(c *checker.C) { - val1 := []byte{1, 2, 3, 4} - exp1 := []byte{0, 0, 0, 0, 1, 2, 3, 4} - - res1 := LeftPadBytes(val1, 8) - res2 := LeftPadBytes(val1, 2) +func TestLeftPadBytes(t *testing.T) { + val := []byte{1, 2, 3, 4} + padded := []byte{0, 0, 0, 0, 1, 2, 3, 4} - c.Assert(res1, checker.DeepEquals, exp1) - c.Assert(res2, checker.DeepEquals, val1) + if r := LeftPadBytes(val, 8); !bytes.Equal(r, padded) { + t.Fatalf("LeftPadBytes(%v, 8) == %v", val, r) + } + if r := LeftPadBytes(val, 2); !bytes.Equal(r, val) { + t.Fatalf("LeftPadBytes(%v, 2) == %v", val, r) + } } -func (s *BytesSuite) TestRightPadBytes(c *checker.C) { +func TestRightPadBytes(t *testing.T) { val := []byte{1, 2, 3, 4} - exp := []byte{1, 2, 3, 4, 0, 0, 0, 0} - - resstd := RightPadBytes(val, 8) - resshrt := RightPadBytes(val, 2) + padded := []byte{1, 2, 3, 4, 0, 0, 0, 0} - c.Assert(resstd, checker.DeepEquals, exp) - c.Assert(resshrt, checker.DeepEquals, val) + if r := RightPadBytes(val, 8); !bytes.Equal(r, padded) { + t.Fatalf("RightPadBytes(%v, 8) == %v", val, r) + } + if r := RightPadBytes(val, 2); !bytes.Equal(r, val) { + t.Fatalf("RightPadBytes(%v, 2) == %v", val, r) + } } func TestFromHex(t *testing.T) { diff --git a/common/main_test.go b/common/main_test.go deleted file mode 100644 index 149d09928a9c1..0000000000000 --- a/common/main_test.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package common - -import ( - "testing" - - checker "gopkg.in/check.v1" -) - -func Test(t *testing.T) { checker.TestingT(t) }