test: add test cases

This commit is contained in:
dapeng 2024-06-14 17:26:47 +08:00
parent 18dc70cf4a
commit 26e19db397
3 changed files with 44 additions and 12 deletions

View File

@ -725,3 +725,41 @@ func Test_cemetery_getGonerContainerByType(t *testing.T) {
assert.Nil(t, err)
})
}
var afterReviveOrder = make([]int, 0)
var startOrder = make([]int, 0)
var stopOrder = make([]int, 0)
type ordered struct {
Flag
order int
}
func (o *ordered) AfterRevive() error {
afterReviveOrder = append(afterReviveOrder, o.order)
return nil
}
func (o *ordered) Start(Cemetery) error {
startOrder = append(startOrder, o.order)
return nil
}
func (o *ordered) Stop(Cemetery) error {
stopOrder = append(stopOrder, o.order)
return nil
}
func TestOrder(t *testing.T) {
Prepare(func(cemetery Cemetery) error {
cemetery.
Bury(&ordered{order: 2}, Order(2)).
Bury(&ordered{order: 1}, Order(1)).
Bury(&ordered{order: 3}, Order(3))
return nil
}).Test(func() {})
assert.Equal(t, []int{1, 2, 3}, afterReviveOrder)
assert.Equal(t, []int{3, 2, 1}, startOrder)
assert.Equal(t, []int{1, 2, 3}, stopOrder)
}

View File

@ -31,9 +31,6 @@ func (l *defaultLogger) Infof(format string, args ...any) {
func (l *defaultLogger) Warnf(format string, args ...any) {
log.Printf(format, args...)
}
func (l *defaultLogger) Warningf(format string, args ...any) {
log.Printf(format, args...)
}
func (l *defaultLogger) Errorf(format string, args ...any) {
log.Printf(format, args...)
@ -51,9 +48,7 @@ func (l *defaultLogger) Info(args ...any) {
func (l *defaultLogger) Warn(args ...any) {
log.Print(args...)
}
func (l *defaultLogger) Warning(args ...any) {
log.Print(args...)
}
func (l *defaultLogger) Error(args ...any) {
log.Print(args...)
}
@ -70,9 +65,7 @@ func (l *defaultLogger) Infoln(args ...any) {
func (l *defaultLogger) Warnln(args ...any) {
log.Println(args...)
}
func (l *defaultLogger) Warningln(args ...any) {
log.Println(args...)
}
func (l *defaultLogger) Errorln(args ...any) {
log.Println(args...)
}

View File

@ -14,21 +14,22 @@ func Test_defaultLogger_Tracef(t *testing.T) {
log.Debugf("format: %s", "test")
log.Infof("format: %s", "test")
log.Warnf("format: %s", "test")
//log.Warningf("format: %s", "test")
log.Errorf("format: %s", "test")
log.Trace("test")
log.Debug("test")
log.Info("test")
log.Warn("test")
//log.Warning("test")
log.Error("test")
log.Traceln("test")
log.Debugln("test")
log.Infoln("test")
log.Warnln("test")
//log.Warningln("test")
log.Errorln("test")
})
}
func TestGetSimpleLogger(t *testing.T) {
assert.Equal(t, _defaultLogger, GetSimpleLogger())
}