github.com/divyam234/rclone@v1.64.1/fs/backend_config_test.go (about)

     1  package fs
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestStatePush(t *testing.T) {
    11  	assert.Equal(t, "", StatePush(""))
    12  	assert.Equal(t, "", StatePush("", ""))
    13  	assert.Equal(t, "a", StatePush("", "a"))
    14  	assert.Equal(t, "a,1,2,3", StatePush("", "a", "1,2,3"))
    15  
    16  	assert.Equal(t, "potato", StatePush("potato"))
    17  	assert.Equal(t, ",potato", StatePush("potato", ""))
    18  	assert.Equal(t, "a,potato", StatePush("potato", "a"))
    19  	assert.Equal(t, "a,1,2,3,potato", StatePush("potato", "a", "1,2,3"))
    20  }
    21  
    22  func TestStatePop(t *testing.T) {
    23  	state, value := StatePop("")
    24  	assert.Equal(t, "", value)
    25  	assert.Equal(t, "", state)
    26  
    27  	state, value = StatePop("a")
    28  	assert.Equal(t, "a", value)
    29  	assert.Equal(t, "", state)
    30  
    31  	state, value = StatePop("a,1,2,3")
    32  	assert.Equal(t, "a", value)
    33  	assert.Equal(t, "1,2,3", state)
    34  
    35  	state, value = StatePop("1,2,3,a")
    36  	assert.Equal(t, "1,2,3", value)
    37  	assert.Equal(t, "a", state)
    38  }
    39  
    40  func TestMatchProvider(t *testing.T) {
    41  	for _, test := range []struct {
    42  		config   string
    43  		provider string
    44  		want     bool
    45  	}{
    46  		{"", "", true},
    47  		{"one", "one", true},
    48  		{"one,two", "two", true},
    49  		{"one,two,three", "two", true},
    50  		{"one", "on", false},
    51  		{"one,two,three", "tw", false},
    52  		{"!one,two,three", "two", false},
    53  		{"!one,two,three", "four", true},
    54  	} {
    55  		what := fmt.Sprintf("%q,%q", test.config, test.provider)
    56  		got := MatchProvider(test.config, test.provider)
    57  		assert.Equal(t, test.want, got, what)
    58  	}
    59  }