github.com/GuanceCloud/cliutils@v1.1.21/diskcache/options_test.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the MIT License.
     3  // This product includes software developed at Guance Cloud (https://www.guance.com/).
     4  // Copyright 2021-present Guance, Inc.
     5  
     6  package diskcache
     7  
     8  import (
     9  	T "testing"
    10  	"time"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  func TestOptions(t *T.T) {
    16  	t.Run(`basic`, func(t *T.T) {
    17  		c := defaultInstance()
    18  
    19  		WithWakeup(-time.Minute)(c) // invalid
    20  		assert.Equal(t, c.wakeup, time.Second*3)
    21  
    22  		WithWakeup(time.Minute)(c)
    23  		assert.Equal(t, c.wakeup, time.Minute)
    24  
    25  		WithBatchSize(1024)(c)
    26  		assert.Equal(t, int64(1024), c.batchSize)
    27  
    28  		WithBatchSize(-1024)(c)
    29  		assert.Equal(t, int64(1024), c.batchSize)
    30  
    31  		WithCapacity(100)(c)
    32  		assert.Equal(t, int64(100), c.capacity)
    33  
    34  		WithCapacity(-100)(c)
    35  		assert.Equal(t, int64(100), c.capacity)
    36  
    37  		WithExtraCapacity(-200)(c)
    38  		assert.Equal(t, int64(100), c.capacity)
    39  
    40  		WithExtraCapacity(-100)(c)
    41  		assert.Equal(t, int64(100), c.capacity)
    42  
    43  		WithExtraCapacity(-50)(c)
    44  		assert.Equal(t, int64(50), c.capacity)
    45  
    46  		WithMaxDataSize(100)(c)
    47  		assert.Equal(t, int32(100), c.maxDataSize)
    48  
    49  		WithNoSync(false)(c)
    50  		assert.False(t, c.noSync)
    51  	})
    52  }