1
mirror of https://github.com/rclone/rclone synced 2024-12-24 15:43:45 +01:00
rclone/fs/backend_config_test.go
Nick Craig-Wood 296ceadda6 fs: add --all to rclone config create/update to ask all the config questions #3455
This also factors the config questions into a state based mechanism so
a backend can be configured using the same dialog as rclone config but
remotely.
2021-05-14 14:07:44 +01:00

60 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package fs
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStatePush(t *testing.T) {
assert.Equal(t, "", StatePush(""))
assert.Equal(t, "", StatePush("", ""))
assert.Equal(t, "a", StatePush("", "a"))
assert.Equal(t, "a,123", StatePush("", "a", "1,2,3"))
assert.Equal(t, "potato", StatePush("potato"))
assert.Equal(t, ",potato", StatePush("potato", ""))
assert.Equal(t, "a,potato", StatePush("potato", "a"))
assert.Equal(t, "a,123,potato", StatePush("potato", "a", "1,2,3"))
}
func TestStatePop(t *testing.T) {
state, value := StatePop("")
assert.Equal(t, "", value)
assert.Equal(t, "", state)
state, value = StatePop("a")
assert.Equal(t, "a", value)
assert.Equal(t, "", state)
state, value = StatePop("a,123")
assert.Equal(t, "a", value)
assert.Equal(t, "123", state)
state, value = StatePop("123,a")
assert.Equal(t, "1,2,3", value)
assert.Equal(t, "a", state)
}
func TestMatchProvider(t *testing.T) {
for _, test := range []struct {
config string
provider string
want bool
}{
{"", "", true},
{"one", "one", true},
{"one,two", "two", true},
{"one,two,three", "two", true},
{"one", "on", false},
{"one,two,three", "tw", false},
{"!one,two,three", "two", false},
{"!one,two,three", "four", true},
} {
what := fmt.Sprintf("%q,%q", test.config, test.provider)
got := MatchProvider(test.config, test.provider)
assert.Equal(t, test.want, got, what)
}
}