本文整理匯總了Golang中github.com/hhkbp2/testify/require.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestErrorRetryDelay
func TestErrorRetryDelay(t *testing.T) {
sleepCount := 0
sleepFunc := func(d time.Duration) {
sleepCount++
time.Sleep(d)
}
maxTries := 2
delay := time.Second * 2
maxDelay := time.Second * 3
retry := NewErrorRetry().
MaxTries(maxTries).
SleepFunc(sleepFunc).
Delay(delay).
MaxDelay(maxDelay)
fnCount := 0
fn := func() error {
fnCount++
return ForceRetryError
}
startTime := time.Now()
err := retry.Do(fn)
require.Equal(t, err, RetryFailedError)
require.Equal(t, fnCount, 2)
require.Equal(t, sleepCount, 2)
require.True(t, time.Since(startTime) > (delay+maxDelay))
}
示例2: TestRotatingFileHandler_AppendWithoutBackup
func TestRotatingFileHandler_AppendWithoutBackup(t *testing.T) {
defer Shutdown()
// clean up the existing log file
if FileExists(testFileName) {
require.Nil(t, os.Remove(testFileName))
}
backupCount := uint32(0)
handler, err := NewRotatingFileHandler(
testFileName,
os.O_APPEND,
testBufferSize,
testBufferFlushTime,
testInputChanSize,
testRotateMaxBytes,
backupCount)
require.Nil(t, err)
logger := GetLogger("rfile2")
logger.AddHandler(handler)
message := strings.Repeat("abcdefghij", 9) + "rstuvwxyz"
size := uint64(len(message) + 1)
totalSize := testRotateMaxBytes * (uint64(testRotateBackupCount) + 2)
times := totalSize / size
require.Equal(t, totalSize, size*times)
for i := uint64(0); i < times; i++ {
logger.Errorf(message)
}
logger.RemoveHandler(handler)
handler.Close()
fileInfo, err := os.Stat(testFileName)
require.Nil(t, err)
require.True(t, uint64(fileInfo.Size()) > testRotateMaxBytes)
require.Equal(t, totalSize, uint64(fileInfo.Size()))
removeFile(t, testFileName)
}
示例3: TestErrorRetryErrors
func TestErrorRetryErrors(t *testing.T) {
sleepCount := 0
sleepFunc := func(d time.Duration) {
sleepCount++
}
e1 := errors.New("test error 1")
e2 := errors.New("test error 2")
e3 := errors.New("test error 3")
retry := NewErrorRetry().
SleepFunc(sleepFunc).
Delay(time.Second).
OnError(e1).
OnError(e2)
triesBeforeSuccess := 3
fnCount := 0
fn := func() error {
fnCount++
if fnCount > triesBeforeSuccess {
return e3
}
switch {
case (fnCount / 2) == 0:
return e1
default:
return e2
}
}
err := retry.Do(fn)
require.Equal(t, err, e3)
require.Equal(t, sleepCount, triesBeforeSuccess)
require.Equal(t, fnCount, triesBeforeSuccess+1)
}
示例4: TestRandomBytes
func TestRandomBytes(t *testing.T) {
length := int64(100)
b1 := RandomBytes(length)
require.Equal(t, length, int64(len(b1)))
b2 := RandomBytes(length)
require.Equal(t, length, int64(len(b2)))
require.NotEqual(t, b1, b2)
}
示例5: runTestHistogramGenerator
func runTestHistogramGenerator(t *testing.T, g IntegerGenerator, times int, area int64) {
for i := 0; i < times; i++ {
last := g.NextInt()
require.True(t, last <= area)
require.Equal(t, g.LastInt(), last)
str := g.NextString()
v, err := strconv.ParseInt(str, 0, 64)
require.Nil(t, err)
require.True(t, v <= area)
require.Equal(t, str, g.LastString())
}
}
示例6: TestToTime
func TestToTime(t *testing.T) {
millisecond := int64(12345)
nanosecond := MillisecondToNanosecond(millisecond)
require.Equal(t, millisecond*1000*1000, nanosecond)
second := MillisecondToSecond(millisecond)
require.Equal(t, millisecond/1000, second)
v := SecondToNanosecond(second)
require.Equal(t, second*1000*1000*1000, v)
v = NanosecondToMicrosecond(nanosecond)
require.Equal(t, nanosecond/1000, v)
v = NanosecondToMillisecond(nanosecond)
require.Equal(t, nanosecond/1000/1000, v)
}
示例7: TestCounterGenerator
func TestCounterGenerator(t *testing.T) {
value := int64(100)
var g IntegerGenerator
g = NewCounterGenerator(value)
require.Equal(t, value-1, g.LastInt())
for i := int64(0); i < 5; i++ {
require.Equal(t, value+i, g.NextInt())
require.Equal(t, value+i, g.LastInt())
}
for i := int64(5); i < 5; i++ {
require.Equal(t, fmt.Sprintf("%d", value+i), g.NextString())
require.Equal(t, fmt.Sprintf("%d", value+i), g.LastString())
}
require.Panics(t, func() { g.Mean() })
}
示例8: TestProperties
func TestProperties(t *testing.T) {
k := "key"
v := "value"
p := NewProperties()
p.Add(k, v)
x := p.Get(k)
require.Equal(t, v, x)
x = p.GetDefault(k, "other")
require.Equal(t, v, x)
k1 := "a"
v1 := "b"
p2 := map[string]string{k1: v1}
p.Merge(p2)
z := p.Get(k1)
require.Equal(t, v1, z)
}
示例9: TestTimedRotatingFileHandler_WithBackup
func TestTimedRotatingFileHandler_WithBackup(t *testing.T) {
defer Shutdown()
cleanupLogFils(t, testFileName)
when := "S"
format := "%Y-%m-%d_%H-%M-%S"
interval := 2
handler, err := NewTimedRotatingFileHandler(
testFileName, when, uint32(interval), testRotateBackupCount, false)
require.Nil(t, err)
logger := GetLogger("trfile")
logger.AddHandler(handler)
message := "test"
lastMessage := "last message"
times := make([]time.Time, 0, testRotateBackupCount)
for i := uint32(0); i < testRotateBackupCount+1; i++ {
logger.Errorf(message)
if i > 0 {
times = append(times, time.Now())
}
time.Sleep(time.Duration(int64(time.Second) * int64(interval)))
}
logger.Errorf(lastMessage)
logger.RemoveHandler(handler)
handler.Close()
for i := uint32(0); i < testRotateBackupCount; i++ {
suffix := strftime.Format(format, times[i])
checkFileContent(t, testFileName+"."+suffix, message+"\n")
}
checkFileContent(t, testFileName, lastMessage+"\n")
require.Equal(t, 2, cleanupLogFils(t, testFileName))
}
示例10: TestUniformIntegerGenerator
func TestUniformIntegerGenerator(t *testing.T) {
lowerBound := int64(1000)
upperBound := int64(2000)
var g IntegerGenerator
uig := NewUniformIntegerGenerator(lowerBound, upperBound)
g = uig
total := 10
for i := 0; i < total; i++ {
last := g.NextInt()
require.True(t, last >= lowerBound && last <= upperBound)
require.Equal(t, last, g.LastInt())
str := g.NextString()
v, err := strconv.ParseInt(str, 0, 64)
require.Nil(t, err)
require.True(t, v >= lowerBound && v <= upperBound)
require.Equal(t, float64((lowerBound+upperBound)/2.0), g.Mean())
}
}
示例11: TestNullHandler
func TestNullHandler(t *testing.T) {
handler := NewNullHandler()
logger := GetLogger("null")
logger.AddHandler(handler)
require.Equal(t, 1, len(logger.GetHandlers()))
message := "test"
logger.Debugf(message)
logger.Fatalf(message)
}
示例12: TestHotspotIntegerGenerator
func TestHotspotIntegerGenerator(t *testing.T) {
lowerBound := int64(1000)
upperBound := int64(2000)
hotsetFraction := float64(0.2)
hotOpnFraction := float64(0.99)
var g IntegerGenerator
hig := NewHotspotIntegerGenerator(lowerBound, upperBound, hotsetFraction, hotOpnFraction)
g = hig
last := g.NextInt()
interval := upperBound - lowerBound
hotsetHigh := lowerBound + int64(float64(interval)*hotsetFraction)
require.True(t, last <= hotsetHigh)
require.Equal(t, last, g.LastInt())
str := g.NextString()
last, err := strconv.ParseInt(str, 0, 64)
require.Nil(t, err)
require.True(t, last <= hotsetHigh)
require.Equal(t, str, g.LastString())
}
示例13: TestDatagramHandler
func TestDatagramHandler(t *testing.T) {
host := "127.0.0.1"
port := uint16(8082)
serverReceived := list.New()
ch := make(chan int)
_testSetupDatagramServer(t, host, port, serverReceived, ch)
require.Equal(t, 0, serverReceived.Len())
handler := NewDatagramHandler(host, port)
logger := GetLogger("datagram")
logger.AddHandler(handler)
message := "test"
logger.Errorf(message)
handler.Close()
<-ch
require.Equal(t, 1, serverReceived.Len())
m, ok := serverReceived.Front().Value.(string)
require.True(t, ok)
require.Equal(t, message, m)
}
示例14: TestExponentGenerator
func TestExponentGenerator(t *testing.T) {
total := 100
recordCount := int64(10000)
percentile := float64(95)
fraction := float64(0.8571428571)
var g IntegerGenerator
eg := NewExponentialGenerator(percentile, float64(recordCount)*fraction)
g = eg
for i := 0; i < total; i++ {
last := g.NextInt()
require.True(t, last >= recordCount)
require.Equal(t, g.LastInt(), last)
str := g.NextString()
v, err := strconv.ParseInt(str, 0, 64)
require.Nil(t, err)
require.True(t, v >= recordCount)
require.Equal(t, g.LastString(), str)
}
}
示例15: TestShutdown
func TestShutdown(t *testing.T) {
defer Shutdown()
handler := NewMockHandler(t)
logger := GetLogger("a")
logger.AddHandler(handler)
message := "abcd"
logger.Errorf(message)
record, err := handler.GetEmitOnTimeout(time.Second * 0)
require.Nil(t, err)
require.Equal(t, message, record.GetMessage())
}