github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/countlog/output/rotation/trigger_by_interval_test.go (about)

     1  package rotation
     2  
     3  import (
     4  	"testing"
     5  	"github.com/v2pro/plz/test"
     6  	"github.com/v2pro/plz/countlog"
     7  	"github.com/v2pro/plz/clock"
     8  	"time"
     9  	"github.com/v2pro/plz/test/must"
    10  )
    11  
    12  func Test_TriggerByInterval(t *testing.T) {
    13  	t.Run("interval", test.Case(func(ctx *countlog.Context) {
    14  		trigger := &TriggerByInterval{
    15  			Interval: time.Hour,
    16  		}
    17  		defer clock.ResetNow()
    18  		clock.Now = func() time.Time {
    19  			return time.Unix(0, 0)
    20  		}
    21  		must.Equal(time.Hour, trigger.TimeToTrigger())
    22  		clock.Now = func() time.Time {
    23  			return time.Unix(1, 0)
    24  		}
    25  		must.Equal(3599 * time.Second, trigger.TimeToTrigger())
    26  	}))
    27  }