d73287f043
this adds some stuff to ultest so that the set of files created by a test can be inspected after so that we can write some tests for the cp command to observe that it does what it is supposed to do. Change-Id: I98b8fb214058140dfbb117baa7acea6a2cc340e1
118 lines
4.2 KiB
Go
118 lines
4.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 TestCpDownload(t *testing.T) {
|
|
state := ultest.Setup(commands,
|
|
ultest.WithFile("sj://user/file1.txt", "remote"),
|
|
)
|
|
|
|
state.Succeed(t, "cp", "sj://user/file1.txt", "/home/user/file1.txt").RequireFiles(t,
|
|
ultest.File{Loc: "/home/user/file1.txt", Contents: "remote"},
|
|
ultest.File{Loc: "sj://user/file1.txt", Contents: "remote"},
|
|
)
|
|
}
|
|
|
|
func TestCpDownloadOverwrite(t *testing.T) {
|
|
state := ultest.Setup(commands,
|
|
ultest.WithFile("/home/user/file1.txt", "local"),
|
|
ultest.WithFile("sj://user/file1.txt", "remote"),
|
|
)
|
|
|
|
state.Succeed(t, "cp", "sj://user/file1.txt", "/home/user/file1.txt").RequireFiles(t,
|
|
ultest.File{Loc: "/home/user/file1.txt", Contents: "remote"},
|
|
ultest.File{Loc: "sj://user/file1.txt", Contents: "remote"},
|
|
)
|
|
}
|
|
|
|
func TestCpUpload(t *testing.T) {
|
|
state := ultest.Setup(commands,
|
|
ultest.WithFile("/home/user/file1.txt", "local"),
|
|
ultest.WithBucket("user"),
|
|
)
|
|
|
|
state.Succeed(t, "cp", "/home/user/file1.txt", "sj://user/file1.txt").RequireFiles(t,
|
|
ultest.File{Loc: "/home/user/file1.txt", Contents: "local"},
|
|
ultest.File{Loc: "sj://user/file1.txt", Contents: "local"},
|
|
)
|
|
}
|
|
|
|
func TestCpUploadOverwrite(t *testing.T) {
|
|
state := ultest.Setup(commands,
|
|
ultest.WithFile("/home/user/file1.txt", "local"),
|
|
ultest.WithFile("sj://user/file1.txt", "remote"),
|
|
)
|
|
|
|
state.Succeed(t, "cp", "/home/user/file1.txt", "sj://user/file1.txt").RequireFiles(t,
|
|
ultest.File{Loc: "/home/user/file1.txt", Contents: "local"},
|
|
ultest.File{Loc: "sj://user/file1.txt", Contents: "local"},
|
|
)
|
|
}
|
|
|
|
func TestCpRecursiveDownload(t *testing.T) {
|
|
state := ultest.Setup(commands,
|
|
ultest.WithFile("sj://user/file1.txt", "data1"),
|
|
ultest.WithFile("sj://user/folder1/file2.txt", "data2"),
|
|
ultest.WithFile("sj://user/folder1/file3.txt", "data3"),
|
|
ultest.WithFile("sj://user/folder2/folder3/file4.txt", "data4"),
|
|
ultest.WithFile("sj://user/folder2/folder3/file5.txt", "data5"),
|
|
)
|
|
|
|
state.Succeed(t, "cp", "sj://user", "/home/user/dest", "--recursive").RequireFiles(t,
|
|
ultest.File{Loc: "sj://user/file1.txt", Contents: "data1"},
|
|
ultest.File{Loc: "sj://user/folder1/file2.txt", Contents: "data2"},
|
|
ultest.File{Loc: "sj://user/folder1/file3.txt", Contents: "data3"},
|
|
ultest.File{Loc: "sj://user/folder2/folder3/file4.txt", Contents: "data4"},
|
|
ultest.File{Loc: "sj://user/folder2/folder3/file5.txt", Contents: "data5"},
|
|
|
|
ultest.File{Loc: "/home/user/dest/file1.txt", Contents: "data1"},
|
|
ultest.File{Loc: "/home/user/dest/folder1/file2.txt", Contents: "data2"},
|
|
ultest.File{Loc: "/home/user/dest/folder1/file3.txt", Contents: "data3"},
|
|
ultest.File{Loc: "/home/user/dest/folder2/folder3/file4.txt", Contents: "data4"},
|
|
ultest.File{Loc: "/home/user/dest/folder2/folder3/file5.txt", Contents: "data5"},
|
|
)
|
|
|
|
state.Succeed(t, "cp", "sj://user/fo", "/home/user/dest", "--recursive").RequireFiles(t,
|
|
ultest.File{Loc: "sj://user/file1.txt", Contents: "data1"},
|
|
ultest.File{Loc: "sj://user/folder1/file2.txt", Contents: "data2"},
|
|
ultest.File{Loc: "sj://user/folder1/file3.txt", Contents: "data3"},
|
|
ultest.File{Loc: "sj://user/folder2/folder3/file4.txt", Contents: "data4"},
|
|
ultest.File{Loc: "sj://user/folder2/folder3/file5.txt", Contents: "data5"},
|
|
|
|
ultest.File{Loc: "/home/user/dest/folder1/file2.txt", Contents: "data2"},
|
|
ultest.File{Loc: "/home/user/dest/folder1/file3.txt", Contents: "data3"},
|
|
ultest.File{Loc: "/home/user/dest/folder2/folder3/file4.txt", Contents: "data4"},
|
|
ultest.File{Loc: "/home/user/dest/folder2/folder3/file5.txt", Contents: "data5"},
|
|
)
|
|
}
|
|
|
|
func TestCpRecursiveDifficult(t *testing.T) {
|
|
state := ultest.Setup(commands,
|
|
ultest.WithFile("sj://user/dot-dot/../foo"),
|
|
ultest.WithFile("sj://user/dot-dot/../../foo"),
|
|
|
|
ultest.WithFile("sj://user//"),
|
|
ultest.WithFile("sj://user///"),
|
|
ultest.WithFile("sj://user////"),
|
|
|
|
ultest.WithFile("sj://user//starts-slash"),
|
|
|
|
ultest.WithFile("sj://user/ends-slash"),
|
|
ultest.WithFile("sj://user/ends-slash/"),
|
|
ultest.WithFile("sj://user/ends-slash//"),
|
|
|
|
ultest.WithFile("sj://user/mid-slash"),
|
|
ultest.WithFile("sj://user/mid-slash//2"),
|
|
ultest.WithFile("sj://user/mid-slash/1"),
|
|
)
|
|
|
|
_ = state
|
|
}
|