From 2e653f81287179e38acce46b4cbc70a7c2706db2 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 8 Jul 2024 12:14:28 +0100 Subject: [PATCH] fs: make Flagger and FlaggerNP interfaces public so we can test flags elsewhere --- fs/bits_test.go | 4 ++-- fs/bwtimetable_test.go | 4 ++-- fs/countsuffix_test.go | 4 ++-- fs/cutoffmode_test.go | 4 ++-- fs/dump_test.go | 4 ++-- fs/enum_test.go | 4 ++-- fs/log_test.go | 4 ++-- fs/parseduration_test.go | 4 ++-- fs/parsetime_test.go | 4 ++-- fs/sizesuffix_test.go | 21 ++------------------- fs/tristate_test.go | 4 ++-- fs/types.go | 21 +++++++++++++++++++++ 12 files changed, 43 insertions(+), 39 deletions(-) diff --git a/fs/bits_test.go b/fs/bits_test.go index 4ab1585a0..ad5f07400 100644 --- a/fs/bits_test.go +++ b/fs/bits_test.go @@ -31,8 +31,8 @@ func (bitsChoices) Choices() []BitsChoicesInfo { // Check it satisfies the interfaces var ( - _ flagger = (*bits)(nil) - _ flaggerNP = bits(0) + _ Flagger = (*bits)(nil) + _ FlaggerNP = bits(0) ) func TestBitsString(t *testing.T) { diff --git a/fs/bwtimetable_test.go b/fs/bwtimetable_test.go index e51400cab..67f4057a3 100644 --- a/fs/bwtimetable_test.go +++ b/fs/bwtimetable_test.go @@ -11,8 +11,8 @@ import ( // Check it satisfies the interfaces var ( - _ flagger = (*BwTimetable)(nil) - _ flaggerNP = BwTimetable{} + _ Flagger = (*BwTimetable)(nil) + _ FlaggerNP = BwTimetable{} ) func TestBwTimetableSet(t *testing.T) { diff --git a/fs/countsuffix_test.go b/fs/countsuffix_test.go index a8635572c..58fca960a 100644 --- a/fs/countsuffix_test.go +++ b/fs/countsuffix_test.go @@ -11,8 +11,8 @@ import ( // Check it satisfies the interfaces var ( - _ flagger = (*CountSuffix)(nil) - _ flaggerNP = CountSuffix(0) + _ Flagger = (*CountSuffix)(nil) + _ FlaggerNP = CountSuffix(0) ) func TestCountSuffixString(t *testing.T) { diff --git a/fs/cutoffmode_test.go b/fs/cutoffmode_test.go index 867209843..389350278 100644 --- a/fs/cutoffmode_test.go +++ b/fs/cutoffmode_test.go @@ -11,8 +11,8 @@ import ( // Check it satisfies the interfaces var ( - _ flagger = (*CutoffMode)(nil) - _ flaggerNP = CutoffMode(0) + _ Flagger = (*CutoffMode)(nil) + _ FlaggerNP = CutoffMode(0) ) func TestCutoffModeString(t *testing.T) { diff --git a/fs/dump_test.go b/fs/dump_test.go index b0bba60d0..aa47264c4 100644 --- a/fs/dump_test.go +++ b/fs/dump_test.go @@ -10,8 +10,8 @@ import ( // Check it satisfies the interfaces var ( - _ flagger = (*DumpFlags)(nil) - _ flaggerNP = DumpFlags(0) + _ Flagger = (*DumpFlags)(nil) + _ FlaggerNP = DumpFlags(0) ) func TestDumpFlagsString(t *testing.T) { diff --git a/fs/enum_test.go b/fs/enum_test.go index 67dc36056..c17f334ad 100644 --- a/fs/enum_test.go +++ b/fs/enum_test.go @@ -29,8 +29,8 @@ const ( // Check it satisfies the interfaces var ( - _ flagger = (*choice)(nil) - _ flaggerNP = choice(0) + _ Flagger = (*choice)(nil) + _ FlaggerNP = choice(0) ) func TestEnumString(t *testing.T) { diff --git a/fs/log_test.go b/fs/log_test.go index ef3ae2a72..0bb04bd21 100644 --- a/fs/log_test.go +++ b/fs/log_test.go @@ -12,8 +12,8 @@ import ( // Check it satisfies the interfaces var ( - _ flagger = (*LogLevel)(nil) - _ flaggerNP = LogLevel(0) + _ Flagger = (*LogLevel)(nil) + _ FlaggerNP = LogLevel(0) _ fmt.Stringer = LogValueItem{} ) diff --git a/fs/parseduration_test.go b/fs/parseduration_test.go index 93340026c..fa2230f75 100644 --- a/fs/parseduration_test.go +++ b/fs/parseduration_test.go @@ -13,8 +13,8 @@ import ( // Check it satisfies the interfaces var ( - _ flagger = (*Duration)(nil) - _ flaggerNP = Duration(0) + _ Flagger = (*Duration)(nil) + _ FlaggerNP = Duration(0) ) func TestParseDuration(t *testing.T) { diff --git a/fs/parsetime_test.go b/fs/parsetime_test.go index 611b0c79b..42ab5ac71 100644 --- a/fs/parsetime_test.go +++ b/fs/parsetime_test.go @@ -12,8 +12,8 @@ import ( // Check it satisfies the interfaces var ( - _ flagger = (*Time)(nil) - _ flaggerNP = Time{} + _ Flagger = (*Time)(nil) + _ FlaggerNP = Time{} ) func TestParseTime(t *testing.T) { diff --git a/fs/sizesuffix_test.go b/fs/sizesuffix_test.go index fd87811c8..732ec4372 100644 --- a/fs/sizesuffix_test.go +++ b/fs/sizesuffix_test.go @@ -5,31 +5,14 @@ import ( "fmt" "testing" - "github.com/spf13/pflag" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -// Interface which flags must satisfy - only defined for _test.go -// since we don't want to pull in pflag here -type flagger interface { - pflag.Value - json.Unmarshaler -} - -// Interface which non-pointer flags must satisfy -// -// These are from pflag.Value and need to be non-pointer due the the -// way the backend flags are inserted into the flags. -type flaggerNP interface { - String() string - Type() string -} - // Check it satisfies the interfaces var ( - _ flagger = (*SizeSuffix)(nil) - _ flaggerNP = SizeSuffix(0) + _ Flagger = (*SizeSuffix)(nil) + _ FlaggerNP = SizeSuffix(0) ) func TestSizeSuffixString(t *testing.T) { diff --git a/fs/tristate_test.go b/fs/tristate_test.go index 7e9f11d9b..b70f9a928 100644 --- a/fs/tristate_test.go +++ b/fs/tristate_test.go @@ -11,8 +11,8 @@ import ( // Check it satisfies the interfaces var ( - _ flagger = (*Tristate)(nil) - _ flaggerNP = Tristate{} + _ Flagger = (*Tristate)(nil) + _ FlaggerNP = Tristate{} ) func TestTristateString(t *testing.T) { diff --git a/fs/types.go b/fs/types.go index 18c9848e5..2ed4e588b 100644 --- a/fs/types.go +++ b/fs/types.go @@ -5,6 +5,7 @@ package fs import ( "context" + "encoding/json" "io" "time" @@ -312,6 +313,26 @@ type ListRCallback func(entries DirEntries) error // ListRFn is defines the call used to recursively list a directory type ListRFn func(ctx context.Context, dir string, callback ListRCallback) error +// Flagger describes the interface rclone config types flags must satisfy +type Flagger interface { + // These are from pflag.Value which we don't want to pull in here + String() string + Set(string) error + Type() string + json.Unmarshaler +} + +// FlaggerNP describes the interface rclone config types flags must +// satisfy as non-pointers +// +// These are from pflag.Value and need to be tested against +// non-pointer value due the the way the backend flags are inserted +// into the flags. +type FlaggerNP interface { + String() string + Type() string +} + // NewUsageValue makes a valid value func NewUsageValue(value int64) *int64 { p := new(int64)