fs: make Flagger and FlaggerNP interfaces public so we can test flags elsewhere

This commit is contained in:
Nick Craig-Wood 2024-07-08 12:14:28 +01:00
parent e79273f9c9
commit 2e653f8128
12 changed files with 43 additions and 39 deletions

View File

@ -31,8 +31,8 @@ func (bitsChoices) Choices() []BitsChoicesInfo {
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*bits)(nil) _ Flagger = (*bits)(nil)
_ flaggerNP = bits(0) _ FlaggerNP = bits(0)
) )
func TestBitsString(t *testing.T) { func TestBitsString(t *testing.T) {

View File

@ -11,8 +11,8 @@ import (
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*BwTimetable)(nil) _ Flagger = (*BwTimetable)(nil)
_ flaggerNP = BwTimetable{} _ FlaggerNP = BwTimetable{}
) )
func TestBwTimetableSet(t *testing.T) { func TestBwTimetableSet(t *testing.T) {

View File

@ -11,8 +11,8 @@ import (
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*CountSuffix)(nil) _ Flagger = (*CountSuffix)(nil)
_ flaggerNP = CountSuffix(0) _ FlaggerNP = CountSuffix(0)
) )
func TestCountSuffixString(t *testing.T) { func TestCountSuffixString(t *testing.T) {

View File

@ -11,8 +11,8 @@ import (
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*CutoffMode)(nil) _ Flagger = (*CutoffMode)(nil)
_ flaggerNP = CutoffMode(0) _ FlaggerNP = CutoffMode(0)
) )
func TestCutoffModeString(t *testing.T) { func TestCutoffModeString(t *testing.T) {

View File

@ -10,8 +10,8 @@ import (
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*DumpFlags)(nil) _ Flagger = (*DumpFlags)(nil)
_ flaggerNP = DumpFlags(0) _ FlaggerNP = DumpFlags(0)
) )
func TestDumpFlagsString(t *testing.T) { func TestDumpFlagsString(t *testing.T) {

View File

@ -29,8 +29,8 @@ const (
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*choice)(nil) _ Flagger = (*choice)(nil)
_ flaggerNP = choice(0) _ FlaggerNP = choice(0)
) )
func TestEnumString(t *testing.T) { func TestEnumString(t *testing.T) {

View File

@ -12,8 +12,8 @@ import (
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*LogLevel)(nil) _ Flagger = (*LogLevel)(nil)
_ flaggerNP = LogLevel(0) _ FlaggerNP = LogLevel(0)
_ fmt.Stringer = LogValueItem{} _ fmt.Stringer = LogValueItem{}
) )

View File

@ -13,8 +13,8 @@ import (
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*Duration)(nil) _ Flagger = (*Duration)(nil)
_ flaggerNP = Duration(0) _ FlaggerNP = Duration(0)
) )
func TestParseDuration(t *testing.T) { func TestParseDuration(t *testing.T) {

View File

@ -12,8 +12,8 @@ import (
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*Time)(nil) _ Flagger = (*Time)(nil)
_ flaggerNP = Time{} _ FlaggerNP = Time{}
) )
func TestParseTime(t *testing.T) { func TestParseTime(t *testing.T) {

View File

@ -5,31 +5,14 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "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 // Check it satisfies the interfaces
var ( var (
_ flagger = (*SizeSuffix)(nil) _ Flagger = (*SizeSuffix)(nil)
_ flaggerNP = SizeSuffix(0) _ FlaggerNP = SizeSuffix(0)
) )
func TestSizeSuffixString(t *testing.T) { func TestSizeSuffixString(t *testing.T) {

View File

@ -11,8 +11,8 @@ import (
// Check it satisfies the interfaces // Check it satisfies the interfaces
var ( var (
_ flagger = (*Tristate)(nil) _ Flagger = (*Tristate)(nil)
_ flaggerNP = Tristate{} _ FlaggerNP = Tristate{}
) )
func TestTristateString(t *testing.T) { func TestTristateString(t *testing.T) {

View File

@ -5,6 +5,7 @@ package fs
import ( import (
"context" "context"
"encoding/json"
"io" "io"
"time" "time"
@ -312,6 +313,26 @@ type ListRCallback func(entries DirEntries) error
// ListRFn is defines the call used to recursively list a directory // ListRFn is defines the call used to recursively list a directory
type ListRFn func(ctx context.Context, dir string, callback ListRCallback) error 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 // NewUsageValue makes a valid value
func NewUsageValue(value int64) *int64 { func NewUsageValue(value int64) *int64 {
p := new(int64) p := new(int64)