github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/vfs/vfscommon/cachemode_test.go (about)

     1  package vfscommon
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/spf13/pflag"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  // Check CacheMode it satisfies the pflag interface
    11  var _ pflag.Value = (*CacheMode)(nil)
    12  
    13  func TestCacheModeString(t *testing.T) {
    14  	assert.Equal(t, "off", CacheModeOff.String())
    15  	assert.Equal(t, "full", CacheModeFull.String())
    16  	assert.Equal(t, "CacheMode(17)", CacheMode(17).String())
    17  }
    18  
    19  func TestCacheModeSet(t *testing.T) {
    20  	var m CacheMode
    21  
    22  	err := m.Set("full")
    23  	assert.NoError(t, err)
    24  	assert.Equal(t, CacheModeFull, m)
    25  
    26  	err = m.Set("potato")
    27  	assert.Error(t, err, "Unknown cache mode level")
    28  
    29  	err = m.Set("")
    30  	assert.Error(t, err, "Unknown cache mode level")
    31  }
    32  
    33  func TestCacheModeType(t *testing.T) {
    34  	var m CacheMode
    35  	assert.Equal(t, "CacheMode", m.Type())
    36  }