mirror of
https://github.com/fatedier/frp.git
synced 2024-12-12 09:41:19 +01:00
test: add test case
This commit is contained in:
parent
30aeaf968e
commit
a0c83bdb78
@ -2,7 +2,6 @@ sudo: false
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.6.4
|
||||
- 1.7.5
|
||||
- 1.8
|
||||
|
||||
|
@ -17,9 +17,6 @@ package msg
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
18
models/proto/udp/udp_test.go
Normal file
18
models/proto/udp/udp_test.go
Normal file
@ -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)
|
||||
}
|
16
utils/errors/errors_test.go
Normal file
16
utils/errors/errors_test.go
Normal file
@ -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")
|
||||
}
|
23
utils/metric/counter_test.go
Normal file
23
utils/metric/counter_test.go
Normal file
@ -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())
|
||||
}
|
@ -94,10 +94,7 @@ func (c *StandardDateCounter) Dec(count int64) {
|
||||
func (c *StandardDateCounter) Snapshot() DateCounter {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
tmp := &StandardDateCounter{
|
||||
reserveDays: c.reserveDays,
|
||||
counts: make([]int64, c.reserveDays),
|
||||
}
|
||||
tmp := newStandardDateCounter(c.reserveDays)
|
||||
for i := 0; i < int(c.reserveDays); i++ {
|
||||
tmp.counts[i] = c.counts[i]
|
||||
}
|
||||
@ -124,7 +121,7 @@ func (c *StandardDateCounter) rotate(now time.Time) {
|
||||
|
||||
if days <= 0 {
|
||||
return
|
||||
} else if days >= 7 {
|
||||
} else if days >= int(c.reserveDays) {
|
||||
c.counts = make([]int64, c.reserveDays)
|
||||
return
|
||||
}
|
||||
|
27
utils/metric/date_counter_test.go
Normal file
27
utils/metric/date_counter_test.go
Normal file
@ -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
Block a user