storj/cmd/uplinkng/cmd_rm_test.go
Jeff Wendling 08d860570b cmd/uplinkng: parallelsm and a ton of fixes
this was just supposed to add parallel uploads/downloads
and it does do that, but i then found a bunch of bugs
with respect to path handling that i thought i had under
control. oops.

so this adds a ton of tests and tries to make the logic
in ulloc to be more consistent. almost all of the actual
file handling bits and knowledge happens in cmd_cp now
where it should belong.

additionally, the s3 command has the behavior that if your
bucket has the file s3://bucket/file, then executing
s3 ls s3://bucket/fi returns nothing. this change makes
uplinkng match that behavior even if i don't personally
like it.

a big portion of the weirdness is the concept introduced
that i've named "directoryish", which intends to capture
the behavior that if a user copies a file to that location
then the base name of the source should be appended on
rather than a direct copy. this concept is entirely a
based on the string value and not the actual filesystem
state. hence, the cp command is responsible for checking
if local paths are actually a directory, and adding a
trailing slash if necessary to make them "directoryish".
additionally, the empty key for a bucket and the empty
string for local paths are considered "directoryish".

Change-Id: I9120d18616fd813b29ff81beed4f5993caa99fb6
2021-08-11 02:30:06 +00:00

77 lines
2.2 KiB
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"testing"
"storj.io/storj/cmd/uplinkng/ultest"
)
func TestRmRemote(t *testing.T) {
t.Run("Basic", func(t *testing.T) {
state := ultest.Setup(commands,
ultest.WithFile("sj://user/file1.txt"),
ultest.WithFile("sj://user/file2.txt"),
ultest.WithFile("/home/user/file1.txt"),
ultest.WithFile("/home/user/file2.txt"),
)
state.Succeed(t, "rm", "sj://user/file1.txt").RequireFiles(t,
ultest.File{Loc: "sj://user/file2.txt"},
ultest.File{Loc: "/home/user/file1.txt"},
ultest.File{Loc: "/home/user/file2.txt"},
)
})
t.Run("Recursive", func(t *testing.T) {
state := ultest.Setup(commands,
ultest.WithFile("sj://user/files/file1.txt"),
ultest.WithFile("sj://user/files/file2.txt"),
ultest.WithFile("sj://user/other_file1.txt"),
ultest.WithFile("/home/user/files/file1.txt"),
ultest.WithFile("/home/user/files/file2.txt"),
)
state.Succeed(t, "rm", "sj://user/files", "-r").RequireFiles(t,
ultest.File{Loc: "sj://user/other_file1.txt"},
ultest.File{Loc: "/home/user/files/file1.txt"},
ultest.File{Loc: "/home/user/files/file2.txt"},
)
})
}
func TestRmLocal(t *testing.T) {
t.Run("Basic", func(t *testing.T) {
state := ultest.Setup(commands,
ultest.WithFile("sj://user/file1.txt"),
ultest.WithFile("sj://user/file2.txt"),
ultest.WithFile("/home/user/file1.txt"),
ultest.WithFile("/home/user/file2.txt"),
)
state.Succeed(t, "rm", "/home/user/file1.txt").RequireFiles(t,
ultest.File{Loc: "sj://user/file1.txt"},
ultest.File{Loc: "sj://user/file2.txt"},
ultest.File{Loc: "/home/user/file2.txt"},
)
})
t.Run("Recursive", func(t *testing.T) {
state := ultest.Setup(commands,
ultest.WithFile("sj://user/files/file1.txt"),
ultest.WithFile("sj://user/files/file2.txt"),
ultest.WithFile("/home/user/files/file1.txt"),
ultest.WithFile("/home/user/files/file2.txt"),
ultest.WithFile("/home/user/other_file1.txt"),
)
state.Succeed(t, "rm", "/home/user/files", "-r").RequireFiles(t,
ultest.File{Loc: "sj://user/files/file1.txt"},
ultest.File{Loc: "sj://user/files/file2.txt"},
ultest.File{Loc: "/home/user/other_file1.txt"},
)
})
}