assert.Equal 的 msg 参数可选是否填入

pull/200/head
q191201771 6 years ago
parent 0437993a24
commit 60c2d11f78

@ -18,11 +18,11 @@ func TestAmf0_WriteNumber_ReadNumber(t *testing.T) {
for _, item := range cases {
out := &bytes.Buffer{}
err := AMF0.WriteNumber(out, item)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
v, l, err := AMF0.ReadNumber(out.Bytes())
assert.Equal(t, item, v, "fxxk.")
assert.Equal(t, l, 9, "fxxk.")
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, item, v)
assert.Equal(t, l, 9)
assert.Equal(t, nil, err)
}
}
@ -36,21 +36,21 @@ func TestAmf0_WriteString_ReadString(t *testing.T) {
for _, item := range cases {
out := &bytes.Buffer{}
err := AMF0.WriteString(out, item)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
v, l, err := AMF0.ReadString(out.Bytes())
assert.Equal(t, item, v, "fxxk.")
assert.Equal(t, l, len(item)+3, "fxxk.")
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, item, v)
assert.Equal(t, l, len(item)+3)
assert.Equal(t, nil, err)
}
longStr := strings.Repeat("1", 65536)
out := &bytes.Buffer{}
err := AMF0.WriteString(out, longStr)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
v, l, err := AMF0.ReadString(out.Bytes())
assert.Equal(t, longStr, v, "fxxk.")
assert.Equal(t, l, len(longStr)+5, "fxxk.")
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, longStr, v)
assert.Equal(t, l, len(longStr)+5)
assert.Equal(t, nil, err)
}
func TestAmf0_WriteObject_ReadObject(t *testing.T) {
@ -60,21 +60,21 @@ func TestAmf0_WriteObject_ReadObject(t *testing.T) {
{"ban", "cat"},
}
err := AMF0.WriteObject(out, objs)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
v, _, err := AMF0.ReadObject(out.Bytes())
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, 2, len(v), "fxxk.")
assert.Equal(t, float64(3), v["air"], "fxxk.")
assert.Equal(t, "cat", v["ban"], "fxxk.")
assert.Equal(t, nil, err)
assert.Equal(t, 2, len(v))
assert.Equal(t, float64(3), v["air"])
assert.Equal(t, "cat", v["ban"])
}
func TestAmf0_WriteNull_readNull(t *testing.T) {
out := &bytes.Buffer{}
err := AMF0.WriteNull(out)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
l, err := AMF0.ReadNull(out.Bytes())
assert.Equal(t, 1, l, "fxxk.")
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, 1, l)
assert.Equal(t, nil, err)
}
// TODO chef: ReadStringWithoutType ReadLongStringWithoutType ReadBoolean

@ -12,15 +12,15 @@ func TestAll(t *testing.T) {
var hs HandshakeServer
b := &bytes.Buffer{}
err = hc.WriteC0C1(b)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
err = hs.ReadC0C1(b)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
err = hs.WriteS0S1S2(b)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
err = hc.ReadS0S1S2(b)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
err = hc.WriteC2(b)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
err = hs.ReadC2(b)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
}

@ -13,7 +13,7 @@ type TestingT interface {
Errorf(format string, args ...interface{})
}
func Equal(t TestingT, expected interface{}, actual interface{}, msg string) {
func Equal(t TestingT, expected interface{}, actual interface{}, msg ...string) {
if !equal(expected, actual) {
t.Errorf("%s expected=%+v, actual=%+v", msg, expected, actual)
}

@ -4,23 +4,24 @@ import "testing"
//import aaa "github.com/stretchr/testify/assert"
func TestEqual(t *testing.T) {
Equal(t, nil, nil)
Equal(t, nil, nil, "fxxk.")
Equal(t, 1, 1, "fxxk.")
Equal(t, "aaa", "aaa", "fxxk.")
Equal(t, 1, 1)
Equal(t, "aaa", "aaa")
var ch chan struct{}
Equal(t, nil, ch, "fxxk.")
Equal(t, nil, ch)
var m map[string]string
Equal(t, nil, m, "fxxk.")
Equal(t, nil, m)
var p *int
Equal(t, nil, p, "fxxk.")
Equal(t, nil, p)
var i interface{}
Equal(t, nil, i, "fxxk.")
Equal(t, nil, i)
var b []byte
Equal(t, nil, b, "fxxk.")
Equal(t, nil, b)
Equal(t, true, isNil(nil), "fxxk.")
Equal(t, false, isNil("aaa"), "fxxk.")
Equal(t, false, equal([]byte{}, "aaa"), "fxxk.")
Equal(t, true, equal([]byte{}, []byte{}), "fxxk.")
Equal(t, true, equal([]byte{0, 1, 2}, []byte{0, 1, 2}), "fxxk.")
Equal(t, true, isNil(nil))
Equal(t, false, isNil("aaa"))
Equal(t, false, equal([]byte{}, "aaa"))
Equal(t, true, equal([]byte{}, []byte{}))
Equal(t, true, equal([]byte{0, 1, 2}, []byte{0, 1, 2}))
}

@ -21,7 +21,7 @@ func TestBEUint16(t *testing.T) {
}
for i := 0; i < len(vector); i++ {
assert.Equal(t, vector[i].output, BEUint16(vector[i].input), "fxxk.")
assert.Equal(t, vector[i].output, BEUint16(vector[i].input))
}
}
@ -38,7 +38,7 @@ func TestBEUint24(t *testing.T) {
}
for i := 0; i < len(vector); i++ {
assert.Equal(t, vector[i].output, BEUint24(vector[i].input), "fxxk.")
assert.Equal(t, vector[i].output, BEUint24(vector[i].input))
}
}
@ -55,7 +55,7 @@ func TestBEUint32(t *testing.T) {
}
for i := 0; i < len(vector); i++ {
assert.Equal(t, vector[i].output, BEUint32(vector[i].input), "fxxk.")
assert.Equal(t, vector[i].output, BEUint32(vector[i].input))
}
}
@ -69,8 +69,8 @@ func TestBEFloat64(t *testing.T) {
for i := 0; i < len(vector); i++ {
b := &bytes.Buffer{}
err := binary.Write(b, binary.BigEndian, float64(vector[i]))
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, vector[i], int(BEFloat64(b.Bytes())), "fxxk.")
assert.Equal(t, nil, err)
assert.Equal(t, vector[i], int(BEFloat64(b.Bytes())))
}
}
@ -87,7 +87,7 @@ func TestLEUint32(t *testing.T) {
}
for i := 0; i < len(vector); i++ {
assert.Equal(t, vector[i].output, LEUint32(vector[i].input), "fxxk.")
assert.Equal(t, vector[i].output, LEUint32(vector[i].input))
}
}
@ -106,7 +106,7 @@ func TestBEPutUint24(t *testing.T) {
out := make([]byte, 3)
for i := 0; i < len(vector); i++ {
BEPutUint24(out, vector[i].input)
assert.Equal(t, vector[i].output, out, "fxxk.")
assert.Equal(t, vector[i].output, out)
}
}
@ -125,7 +125,7 @@ func TestBEPutUint32(t *testing.T) {
out := make([]byte, 4)
for i := 0; i < len(vector); i++ {
BEPutUint32(out, vector[i].input)
assert.Equal(t, vector[i].output, out, "fxxk.")
assert.Equal(t, vector[i].output, out)
}
}
@ -144,7 +144,7 @@ func TestLEPutUint32(t *testing.T) {
out := make([]byte, 4)
for i := 0; i < len(vector); i++ {
LEPutUint32(out, vector[i].input)
assert.Equal(t, vector[i].output, out, "fxxk.")
assert.Equal(t, vector[i].output, out)
}
}
@ -163,8 +163,8 @@ func TestWriteBEUint24(t *testing.T) {
for i := 0; i < len(vector); i++ {
out := &bytes.Buffer{}
err := WriteBEUint24(out, vector[i].input)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, vector[i].output, out.Bytes(), "fxxk.")
assert.Equal(t, nil, err)
assert.Equal(t, vector[i].output, out.Bytes())
}
}
@ -179,8 +179,8 @@ func TestWriteBE(t *testing.T) {
for i := 0; i < len(vector); i++ {
out := &bytes.Buffer{}
err := WriteBE(out, vector[i].input)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, vector[i].output, out.Bytes(), "fxxk.")
assert.Equal(t, nil, err)
assert.Equal(t, vector[i].output, out.Bytes())
}
}
@ -195,8 +195,8 @@ func TestWriteLE(t *testing.T) {
for i := 0; i < len(vector); i++ {
out := &bytes.Buffer{}
err := WriteLE(out, vector[i].input)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, vector[i].output, out.Bytes(), "fxxk.")
assert.Equal(t, nil, err)
assert.Equal(t, vector[i].output, out.Bytes())
}
}

@ -13,7 +13,7 @@ func TestLogger(t *testing.T) {
RotateMByte: 10,
}
l, err := New(c)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
l.Debugf("test msg by Debug%s", "f")
l.Infof("test msg by Info%s", "f")
l.Warnf("test msg by Warn%s", "f")
@ -41,7 +41,7 @@ func TestGlobal(t *testing.T) {
RotateMByte: 10,
}
err := Init(c)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
Debugf("test msg by Debug%s", "f")
Infof("test msg by Info%s", "f")
Warnf("test msg by Warn%s", "f")
@ -56,8 +56,8 @@ func TestGlobal(t *testing.T) {
func TestNew(t *testing.T) {
l, err := New(Config{Level:LevelError+1})
assert.Equal(t, nil, l, "fxxk.")
assert.Equal(t, logErr, err, "fxxk.")
assert.Equal(t, nil, l)
assert.Equal(t, logErr, err)
}
func TestRotate(t *testing.T) {
@ -68,7 +68,7 @@ func TestRotate(t *testing.T) {
RotateMByte: 1,
}
err := Init(c)
assert.Equal(t, nil, err, "fxxk.")
assert.Equal(t, nil, err)
b := make([]byte, 1024)
for i := 0; i < 2 * 1024; i++ {
Info(b)
@ -86,7 +86,7 @@ func BenchmarkStdout(b *testing.B) {
RotateMByte: 10,
}
err := Init(c)
assert.Equal(b, nil, err, "fxxk.")
assert.Equal(b, nil, err)
for i := 0; i < b.N; i++ {
Infof("hello %s %d", "world", i)
}

@ -21,5 +21,5 @@ func TestGenUniqueKey(t *testing.T) {
}()
}
wg.Wait()
assert.Equal(t, 1000, len(m), "fxxk.")
assert.Equal(t, 1000, len(m))
}

@ -10,3 +10,5 @@ for d in $(go list ./... | grep -v vendor); do
rm profile.out
fi
done
# go test -race -coverprofile=profile.out -covermode=atomic && go tool cover -html=profile.out -o coverage.html && open coverage.html

Loading…
Cancel
Save