mirror of https://github.com/fatedier/frp.git
test: add test case
parent
30aeaf968e
commit
a0c83bdb78
@ -0,0 +1,18 @@
|
|||||||
|
package udp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUdpPacket(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
buf := []byte("hello world")
|
||||||
|
udpMsg := NewUdpPacket(buf, nil, nil)
|
||||||
|
|
||||||
|
newBuf, err := GetContent(udpMsg)
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.EqualValues(buf, newBuf)
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package errors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPanicToError(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
err := PanicToError(func() {
|
||||||
|
panic("test error")
|
||||||
|
})
|
||||||
|
assert.Contains(err.Error(), "test error")
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package metric
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCounter(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
c := NewCounter()
|
||||||
|
c.Inc(10)
|
||||||
|
assert.EqualValues(10, c.Count())
|
||||||
|
|
||||||
|
c.Dec(5)
|
||||||
|
assert.EqualValues(5, c.Count())
|
||||||
|
|
||||||
|
cTmp := c.Snapshot()
|
||||||
|
assert.EqualValues(5, cTmp.Count())
|
||||||
|
|
||||||
|
c.Clear()
|
||||||
|
assert.EqualValues(0, c.Count())
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package metric
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDateCounter(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
dc := NewDateCounter(3)
|
||||||
|
dc.Inc(10)
|
||||||
|
assert.EqualValues(10, dc.TodayCount())
|
||||||
|
|
||||||
|
dc.Dec(5)
|
||||||
|
assert.EqualValues(5, dc.TodayCount())
|
||||||
|
|
||||||
|
counts := dc.GetLastDaysCount(3)
|
||||||
|
assert.EqualValues(3, len(counts))
|
||||||
|
assert.EqualValues(5, counts[0])
|
||||||
|
assert.EqualValues(0, counts[1])
|
||||||
|
assert.EqualValues(0, counts[2])
|
||||||
|
|
||||||
|
dcTmp := dc.Snapshot()
|
||||||
|
assert.EqualValues(5, dcTmp.TodayCount())
|
||||||
|
}
|
Loading…
Reference in New Issue