github.com/lingyao2333/mo-zero@v1.4.1/core/stores/cache/cleaner_test.go (about)

     1  package cache
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestNextDelay(t *testing.T) {
    11  	tests := []struct {
    12  		name   string
    13  		input  time.Duration
    14  		output time.Duration
    15  		ok     bool
    16  	}{
    17  		{
    18  			name:   "second",
    19  			input:  time.Second,
    20  			output: time.Second * 5,
    21  			ok:     true,
    22  		},
    23  		{
    24  			name:   "5 seconds",
    25  			input:  time.Second * 5,
    26  			output: time.Minute,
    27  			ok:     true,
    28  		},
    29  		{
    30  			name:   "minute",
    31  			input:  time.Minute,
    32  			output: time.Minute * 5,
    33  			ok:     true,
    34  		},
    35  		{
    36  			name:   "5 minutes",
    37  			input:  time.Minute * 5,
    38  			output: time.Hour,
    39  			ok:     true,
    40  		},
    41  		{
    42  			name:   "hour",
    43  			input:  time.Hour,
    44  			output: 0,
    45  			ok:     false,
    46  		},
    47  	}
    48  
    49  	for _, test := range tests {
    50  		t.Run(test.name, func(t *testing.T) {
    51  			next, ok := nextDelay(test.input)
    52  			assert.Equal(t, test.ok, ok)
    53  			assert.Equal(t, test.output, next)
    54  		})
    55  	}
    56  }