mirror of https://github.com/stretchr/testify.git
Improve tests
parent
4b71b28738
commit
28b40b159e
|
@ -6,7 +6,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -1472,6 +1471,29 @@ func TestFileExists(t *testing.T) {
|
||||||
|
|
||||||
mockT = new(testing.T)
|
mockT = new(testing.T)
|
||||||
False(t, FileExists(mockT, "../_codegen"))
|
False(t, FileExists(mockT, "../_codegen"))
|
||||||
|
|
||||||
|
var tempFiles []string
|
||||||
|
|
||||||
|
link, err := getTempSymlinkPath("assertions.go")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("could not create temp symlink, err:", err)
|
||||||
|
}
|
||||||
|
tempFiles = append(tempFiles, link)
|
||||||
|
mockT = new(testing.T)
|
||||||
|
True(t, FileExists(mockT, link))
|
||||||
|
|
||||||
|
link, err = getTempSymlinkPath("non_existent_file")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("could not create temp symlink, err:", err)
|
||||||
|
}
|
||||||
|
tempFiles = append(tempFiles, link)
|
||||||
|
mockT = new(testing.T)
|
||||||
|
True(t, FileExists(mockT, link))
|
||||||
|
|
||||||
|
errs := cleanUpTempFiles(tempFiles)
|
||||||
|
if len(errs) > 0 {
|
||||||
|
t.Fatal("could not clean up temporary files")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoFileExists(t *testing.T) {
|
func TestNoFileExists(t *testing.T) {
|
||||||
|
@ -1479,22 +1501,14 @@ func TestNoFileExists(t *testing.T) {
|
||||||
False(t, NoFileExists(mockT, "assertions.go"))
|
False(t, NoFileExists(mockT, "assertions.go"))
|
||||||
|
|
||||||
mockT = new(testing.T)
|
mockT = new(testing.T)
|
||||||
True(t, NoFileExists(mockT, "random_file"))
|
True(t, NoFileExists(mockT, "non_existent_file"))
|
||||||
|
|
||||||
mockT = new(testing.T)
|
mockT = new(testing.T)
|
||||||
True(t, NoFileExists(mockT, "../_codegen"))
|
True(t, NoFileExists(mockT, "../_codegen"))
|
||||||
|
|
||||||
var tempFiles []string
|
var tempFiles []string
|
||||||
|
|
||||||
file, err := getTempFilePath()
|
link, err := getTempSymlinkPath("assertions.go")
|
||||||
if err != nil {
|
|
||||||
t.Fatal("could not create temp file, err:", err)
|
|
||||||
}
|
|
||||||
tempFiles = append(tempFiles, file)
|
|
||||||
mockT = new(testing.T)
|
|
||||||
False(t, NoFileExists(mockT, file))
|
|
||||||
|
|
||||||
link, err := getTempSymlinkPath(file)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not create temp symlink, err:", err)
|
t.Fatal("could not create temp symlink, err:", err)
|
||||||
}
|
}
|
||||||
|
@ -1502,29 +1516,20 @@ func TestNoFileExists(t *testing.T) {
|
||||||
mockT = new(testing.T)
|
mockT = new(testing.T)
|
||||||
False(t, NoFileExists(mockT, link))
|
False(t, NoFileExists(mockT, link))
|
||||||
|
|
||||||
// symlink with non-existent target
|
link, err = getTempSymlinkPath("non_existent_file")
|
||||||
link, err = getTempSymlinkPath("random_file_which_does_not_exist")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not create temp symlink, err:", err)
|
t.Fatal("could not create temp symlink, err:", err)
|
||||||
}
|
}
|
||||||
tempFiles = append(tempFiles, link)
|
tempFiles = append(tempFiles, link)
|
||||||
mockT = new(testing.T)
|
mockT = new(testing.T)
|
||||||
True(t, NoFileExists(mockT, link))
|
False(t, NoFileExists(mockT, link))
|
||||||
|
|
||||||
errs := cleanUpTempFiles(tempFiles)
|
errs := cleanUpTempFiles(tempFiles)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
t.Fail()
|
t.Fatal("could not clean up temporary files")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTempFilePath() (string, error) {
|
|
||||||
file, err := ioutil.TempFile("", "stretchr_file_test_")
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return file.Name(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTempSymlinkPath(file string) (string, error) {
|
func getTempSymlinkPath(file string) (string, error) {
|
||||||
link := file + "_symlink"
|
link := file + "_symlink"
|
||||||
err := os.Symlink(file, link)
|
err := os.Symlink(file, link)
|
||||||
|
@ -1547,10 +1552,33 @@ func TestDirExists(t *testing.T) {
|
||||||
False(t, DirExists(mockT, "assertions.go"))
|
False(t, DirExists(mockT, "assertions.go"))
|
||||||
|
|
||||||
mockT = new(testing.T)
|
mockT = new(testing.T)
|
||||||
False(t, DirExists(mockT, "random_dir"))
|
False(t, DirExists(mockT, "non_existent_dir"))
|
||||||
|
|
||||||
mockT = new(testing.T)
|
mockT = new(testing.T)
|
||||||
True(t, DirExists(mockT, "../_codegen"))
|
True(t, DirExists(mockT, "../_codegen"))
|
||||||
|
|
||||||
|
var tempFiles []string
|
||||||
|
|
||||||
|
link, err := getTempSymlinkPath("assertions.go")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("could not create temp symlink, err:", err)
|
||||||
|
}
|
||||||
|
tempFiles = append(tempFiles, link)
|
||||||
|
mockT = new(testing.T)
|
||||||
|
False(t, DirExists(mockT, link))
|
||||||
|
|
||||||
|
link, err = getTempSymlinkPath("non_existent_dir")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("could not create temp symlink, err:", err)
|
||||||
|
}
|
||||||
|
tempFiles = append(tempFiles, link)
|
||||||
|
mockT = new(testing.T)
|
||||||
|
False(t, DirExists(mockT, link))
|
||||||
|
|
||||||
|
errs := cleanUpTempFiles(tempFiles)
|
||||||
|
if len(errs) > 0 {
|
||||||
|
t.Fatal("could not clean up temporary files")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoDirExists(t *testing.T) {
|
func TestNoDirExists(t *testing.T) {
|
||||||
|
@ -1558,10 +1586,33 @@ func TestNoDirExists(t *testing.T) {
|
||||||
True(t, NoDirExists(mockT, "assertions.go"))
|
True(t, NoDirExists(mockT, "assertions.go"))
|
||||||
|
|
||||||
mockT = new(testing.T)
|
mockT = new(testing.T)
|
||||||
True(t, NoDirExists(mockT, "random_dir"))
|
True(t, NoDirExists(mockT, "non_existent_dir"))
|
||||||
|
|
||||||
mockT = new(testing.T)
|
mockT = new(testing.T)
|
||||||
False(t, NoDirExists(mockT, "../_codegen"))
|
False(t, NoDirExists(mockT, "../_codegen"))
|
||||||
|
|
||||||
|
var tempFiles []string
|
||||||
|
|
||||||
|
link, err := getTempSymlinkPath("assertions.go")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("could not create temp symlink, err:", err)
|
||||||
|
}
|
||||||
|
tempFiles = append(tempFiles, link)
|
||||||
|
mockT = new(testing.T)
|
||||||
|
True(t, NoDirExists(mockT, link))
|
||||||
|
|
||||||
|
link, err = getTempSymlinkPath("non_existent_dir")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("could not create temp symlink, err:", err)
|
||||||
|
}
|
||||||
|
tempFiles = append(tempFiles, link)
|
||||||
|
mockT = new(testing.T)
|
||||||
|
True(t, NoDirExists(mockT, link))
|
||||||
|
|
||||||
|
errs := cleanUpTempFiles(tempFiles)
|
||||||
|
if len(errs) > 0 {
|
||||||
|
t.Fatal("could not clean up temporary files")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONEq_EqualSONString(t *testing.T) {
|
func TestJSONEq_EqualSONString(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue