github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/backend/chunker/chunker_test.go (about)

     1  // Test the Chunker filesystem interface
     2  package chunker_test
     3  
     4  import (
     5  	"flag"
     6  	"os"
     7  	"path/filepath"
     8  	"testing"
     9  
    10  	_ "github.com/rclone/rclone/backend/all" // for integration tests
    11  	"github.com/rclone/rclone/backend/chunker"
    12  	"github.com/rclone/rclone/fstest"
    13  	"github.com/rclone/rclone/fstest/fstests"
    14  )
    15  
    16  // Command line flags
    17  var (
    18  	// Invalid characters are not supported by some remotes, e.g. Mailru.
    19  	// We enable testing with invalid characters when -remote is not set, so
    20  	// chunker overlays a local directory, but invalid characters are disabled
    21  	// by default when -remote is set, e.g. when test_all runs backend tests.
    22  	// You can still test with invalid characters using the below flag.
    23  	UseBadChars = flag.Bool("bad-chars", false, "Set to test bad characters in file names when -remote is set")
    24  )
    25  
    26  // TestIntegration runs integration tests against a concrete remote
    27  // set by the -remote flag. If the flag is not set, it creates a
    28  // dynamic chunker overlay wrapping a local temporary directory.
    29  func TestIntegration(t *testing.T) {
    30  	opt := fstests.Opt{
    31  		RemoteName:               *fstest.RemoteName,
    32  		NilObject:                (*chunker.Object)(nil),
    33  		SkipBadWindowsCharacters: !*UseBadChars,
    34  		UnimplementableObjectMethods: []string{
    35  			"MimeType",
    36  			"GetTier",
    37  			"SetTier",
    38  			"Metadata",
    39  			"SetMetadata",
    40  		},
    41  		UnimplementableFsMethods: []string{
    42  			"PublicLink",
    43  			"OpenWriterAt",
    44  			"OpenChunkWriter",
    45  			"MergeDirs",
    46  			"DirCacheFlush",
    47  			"UserInfo",
    48  			"Disconnect",
    49  		},
    50  	}
    51  	if *fstest.RemoteName == "" {
    52  		name := "TestChunker"
    53  		opt.RemoteName = name + ":"
    54  		tempDir := filepath.Join(os.TempDir(), "rclone-chunker-test-standard")
    55  		opt.ExtraConfig = []fstests.ExtraConfigItem{
    56  			{Name: name, Key: "type", Value: "chunker"},
    57  			{Name: name, Key: "remote", Value: tempDir},
    58  		}
    59  		opt.QuickTestOK = true
    60  	}
    61  	fstests.Run(t, &opt)
    62  }