github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/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, eg. 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, eg. 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  		},
    39  		UnimplementableFsMethods: []string{
    40  			"PublicLink",
    41  			"OpenWriterAt",
    42  			"MergeDirs",
    43  			"DirCacheFlush",
    44  			"UserInfo",
    45  			"Disconnect",
    46  		},
    47  	}
    48  	if *fstest.RemoteName == "" {
    49  		name := "TestChunker"
    50  		opt.RemoteName = name + ":"
    51  		tempDir := filepath.Join(os.TempDir(), "rclone-chunker-test-standard")
    52  		opt.ExtraConfig = []fstests.ExtraConfigItem{
    53  			{Name: name, Key: "type", Value: "chunker"},
    54  			{Name: name, Key: "remote", Value: tempDir},
    55  		}
    56  	}
    57  	fstests.Run(t, &opt)
    58  }