Optimized testing

This commit is contained in:
yi-ge 2019-08-07 23:39:50 +08:00
parent 6e6c18baff
commit 368962abf3
2 changed files with 33 additions and 16 deletions

View File

@ -23,7 +23,7 @@ install:
- go mod install
script:
- make test COVERAGE_DIR=/tmp/coverage
- go test -v
after_success:
- goveralls -service=travis-ci -coverprofile /tmp/coverage/combined.txt
# - goveralls -service=travis-ci -coverprofile /tmp/coverage/combined.txt

View File

@ -16,18 +16,7 @@ func currentDir() string {
return dir
}
func TestUnxz(t *testing.T) {
filePath := filepath.FromSlash(path.Join(currentDir(), "./test/t.tar.xz"))
outDir := filepath.FromSlash(path.Join(currentDir(), "./test/out") + "/")
os.RemoveAll(outDir)
unxz := New(filePath, outDir)
err := unxz.Extract()
if err != nil {
t.Fatal(err)
}
func testNullContent(t *testing.T) {
aFile, err := os.Open(path.Join(currentDir(), "./test/a.txt"))
if err != nil {
t.Fatal(err)
@ -51,7 +40,9 @@ func TestUnxz(t *testing.T) {
if string(aFileContent) != "" {
t.Fatal("Unxz file content error.")
}
}
func testContentEqual(t *testing.T) {
bFile, err := os.Open(path.Join(currentDir(), "./test/b.txt"))
if err != nil {
t.Fatal(err)
@ -73,7 +64,9 @@ func TestUnxz(t *testing.T) {
t.Log(string(bOutFileContent))
t.Fatal("Unxz file content error.")
}
}
func testLink(t *testing.T) {
cOutFile, err := os.OpenFile(path.Join(currentDir(), "./test/out/c.txt"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
t.Fatal(err)
@ -121,8 +114,9 @@ func TestUnxz(t *testing.T) {
if string(cOutFileContentNew) != string(cOutLinkFileContentNew) {
t.Fatal("Unxz file link error.")
}
}
// test d
func testSymlink(t *testing.T) {
targetURL, err := filepath.EvalSymlinks(path.Join(currentDir(), "./test/out/d.txt"))
if targetURL != path.Join(currentDir(), "./test/out/dir/d.txt") {
@ -148,7 +142,9 @@ func TestUnxz(t *testing.T) {
if string(dOutSymlinkFileContent) != string(dOutFileContent) {
t.Fatal("The content of symlink file is not equal to that of target file")
}
}
func testLintInDir(t *testing.T) {
eOutFile, err := os.OpenFile(path.Join(currentDir(), "./test/out/dir/dir/e.txt"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
t.Fatal(err)
@ -196,8 +192,9 @@ func TestUnxz(t *testing.T) {
if string(eOutFileContentNew) != string(eOutLinkFileContentNew) {
t.Fatal("Unxz file link error.")
}
}
// test f
func testSymlinkInDir(t *testing.T) {
inDirTargetURL, err := filepath.EvalSymlinks(path.Join(currentDir(), "./test/out/dir/dir/f.txt"))
t.Log("F outSymlinkFile link:", inDirTargetURL)
@ -225,3 +222,23 @@ func TestUnxz(t *testing.T) {
t.Fatal("The content of symlink file is not equal to that of target file")
}
}
func TestUnxz(t *testing.T) {
filePath := filepath.FromSlash(path.Join(currentDir(), "./test/t.tar.xz"))
outDir := filepath.FromSlash(path.Join(currentDir(), "./test/out") + "/")
os.RemoveAll(outDir)
unxz := New(filePath, outDir)
err := unxz.Extract()
if err != nil {
t.Fatal(err)
}
t.Run("Content is null", testNullContent)
t.Run("Content is equal", testContentEqual)
t.Run("Link", testLink)
t.Run("Symlink", testSymlink)
t.Run("Link in dir", testLintInDir)
t.Run("Symlink in dir", testSymlinkInDir)
}