本文整理汇总了Golang中github.com/stretchr/testify/assert.FailNow函数的典型用法代码示例。如果您正苦于以下问题:Golang FailNow函数的具体用法?Golang FailNow怎么用?Golang FailNow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FailNow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAddToArchiveWithClosedWriter
func TestAddToArchiveWithClosedWriter(t *testing.T) {
dir, err := ioutil.TempDir("", "tarwriter_test")
if err != nil {
assert.FailNow(t, "Cannot create temp dir", err.Error())
}
tempFilePath := filepath.Join(dir, "test_file.tar")
defer os.RemoveAll(dir)
w := tarfile.NewWriter(tempFilePath)
// Note that we have not opened the writer
err = w.AddToArchive(pathToTestFile("cleanup_result.json"), "file1.json")
if err == nil {
assert.FailNow(t, "Should have gotten a tar write error")
}
assert.True(t, strings.HasPrefix(err.Error(), "Underlying TarWriter is nil"))
// Open and close the writer, so the file exists.
w.Open()
w.Close()
if _, err := os.Stat(w.PathToTarFile); os.IsNotExist(err) {
assert.Fail(t, "Tar file does not exist at %s", w.PathToTarFile)
}
err = w.AddToArchive(pathToTestFile("cleanup_result.json"), "file1.json")
if err == nil {
assert.FailNow(t, "Should have gotten a tar write error")
}
assert.True(t, strings.HasPrefix(err.Error(), "archive/tar: write after close"))
}
示例2: TestS3ObjectDelete
func TestS3ObjectDelete(t *testing.T) {
if !canTestS3() {
return
}
// Hmmm... don't like having to upload objects first.
// But how else to test delete?
err := upload(t, "test_obj_1.tar")
if err != nil {
assert.FailNow(t, "Could not upload file 1 for delete test")
}
err = upload(t, "test_obj_2.tar")
if err != nil {
assert.FailNow(t, "Could not upload file 2 for delete test")
}
// Now delete those objects
s3ObjectDelete := network.NewS3ObjectDelete(
constants.AWSVirginia,
testBucket,
[]string{"test_obj_1.tar", "test_obj_2.tar"},
)
s3ObjectDelete.DeleteList()
assert.Equal(t, "", s3ObjectDelete.ErrorMessage)
assert.Equal(t, 2, len(s3ObjectDelete.Response.Deleted))
assert.Empty(t, s3ObjectDelete.Response.Errors)
}
示例3: TestFetchWithoutChecksums
func TestFetchWithoutChecksums(t *testing.T) {
if !canTestS3() {
return
}
download := getS3DownloadObject(t)
if download == nil {
return
}
download.CalculateMd5 = false
download.CalculateSha256 = false
download.Fetch()
defer os.Remove(download.LocalPath)
assert.Empty(t, download.ErrorMessage)
if download.Response == nil {
assert.FailNow(t, "Response object is nil")
}
assert.Equal(t, testFileETag, *download.Response.ETag)
assert.Equal(t, int64(testFileSize), *download.Response.ContentLength)
assert.Equal(t, int64(testFileSize), download.BytesCopied)
fileStat, err := os.Stat(download.LocalPath)
if err != nil {
assert.FailNow(t, "Download file '%s' does not exist", download.LocalPath)
}
assert.Equal(t, int64(testFileSize), fileStat.Size())
assert.Empty(t, download.Md5Digest)
assert.Empty(t, download.Sha256Digest)
}
示例4: TestNewReader
func TestNewReader(t *testing.T) {
r := getReader("virginia.edu.uva-lib_2278801.tar")
if r.Manifest == nil {
assert.FailNow(t, "Reader Manifest should not be nil")
}
if r.Manifest.Object == nil {
assert.FailNow(t, "Reader Manifest Object should not be nil")
}
assert.Equal(t, "virginia.edu.uva-lib_2278801", r.Manifest.Object.Identifier)
assert.Equal(t, "virginia.edu", r.Manifest.Object.Institution)
assert.Equal(t, "uva-lib_2278801", r.Manifest.Object.BagName)
assert.True(t, strings.HasPrefix(r.Manifest.Object.IngestTarFilePath, "/"))
assert.True(t, strings.HasSuffix(r.Manifest.Object.IngestTarFilePath, "testdata/unit_test_bags/virginia.edu.uva-lib_2278801.tar"))
}
示例5: Expect
// Expect fails the test if the next event is not one of the specified events.
func Expect(t *testing.T, watch chan events.Event, specifiers ...state.Event) {
matcher := state.Matcher(specifiers...)
for {
select {
case event := <-watch:
if !matcher.Match(event) {
assert.FailNow(t, fmt.Sprintf("unexpected event: %T", event))
}
return
case <-time.After(time.Second):
assert.FailNow(t, "no commit event")
}
}
}
示例6: Test01RawGet
func (suite *LoggerTester) Test01RawGet() {
t := suite.T()
assert := assert.New(t)
suite.setupFixture()
defer suite.teardownFixture()
resp, err := http.Get(suite.url + "/message?perPage=13&page=&0")
assert.NoError(err)
assert.True(resp.ContentLength >= 0)
if resp.ContentLength == -1 {
assert.FailNow("bonk")
}
assert.True(resp.ContentLength > 0)
raw := make([]byte, resp.ContentLength)
_, err = io.ReadFull(resp.Body, raw)
defer func() {
err = resp.Body.Close()
assert.NoError(err)
}()
if err != nil && err != io.EOF {
assert.NoError(err)
}
assert.Equal(200, resp.StatusCode)
}
示例7: TestRangeNetwork
func TestRangeNetwork(t *testing.T) {
var tests = []struct {
r *Range
n *net.IPNet
}{
{ParseRange("10.10.10.10/24"), &net.IPNet{IP: net.ParseIP("10.10.10.0"), Mask: net.CIDRMask(24, 32)}},
{ParseRange("10.10.10.10-10.10.14.11"), nil},
{ParseRange("10.10.10.10-10.10.10.11"), &net.IPNet{IP: net.ParseIP("10.10.10.10"), Mask: net.CIDRMask(31, 32)}},
}
for _, te := range tests {
n := te.r.Network()
if te.n != nil {
assert.NotNil(t, n)
} else {
assert.Nil(t, n)
continue
}
if !n.IP.Equal(te.n.IP) {
assert.FailNow(t, fmt.Sprintf("got %s, want %s", n, te.n))
}
assert.EqualValues(t, n.Mask, te.n.Mask)
}
}
示例8: TestNT
func TestNT(t *testing.T) {
assert := assert.New(t)
var genericServer *GenericServer
var server *ThingServer
var sys *SystemConfig
{
var err error
required := []ServiceName{}
sys, err = NewSystemConfig(PzGoCommonTest, required)
if err != nil {
assert.FailNow(err.Error())
}
genericServer = &GenericServer{Sys: sys}
server = &ThingServer{}
service := &ThingService{
assert: assert,
IDCount: 0,
Data: make(map[string]string),
}
server.Init(service)
}
{
var err error
err = genericServer.Configure(server.routes)
if err != nil {
assert.FailNow("server failed to configure: " + err.Error())
}
_, err = genericServer.Start()
if err != nil {
assert.FailNow("server failed to start: " + err.Error())
}
}
GetValueFromHeader(http.Header{}, "Content-Type")
_, _, _, err := HTTP(GET, "localhost:"+LocalPortNumbers[PzGoCommonTest], NewHeaderBuilder().AddJsonContentType().AddBasicAuth("foo", "bar").GetHeader(), nil)
if err != nil {
assert.FailNow(err.Error())
}
err = genericServer.Stop()
assert.NoError(err)
}
示例9: TestNewWriter
func TestNewWriter(t *testing.T) {
dir, err := ioutil.TempDir("", "tarwriter_test")
if err != nil {
assert.FailNow(t, "Cannot create temp dir", err.Error())
}
tempFilePath := filepath.Join(dir, "test_file.tar")
defer os.RemoveAll(dir)
w := tarfile.NewWriter(tempFilePath)
assert.NotNil(t, w)
assert.Equal(t, tempFilePath, w.PathToTarFile)
}
示例10: createClients
func (params *benchParams) createClients() (clients []client.Client) {
wsURL := "ws://" + params.service.WebServer().GetAddr() + "/stream/user/"
for clientID := 0; clientID < params.clients; clientID++ {
location := wsURL + strconv.Itoa(clientID)
c, err := client.Open(location, "http://localhost/", 1000, true)
if err != nil {
assert.FailNow(params, "guble client could not connect to server")
}
clients = append(clients, c)
}
return
}
示例11: TestAddToArchiveWithBadFilePath
func TestAddToArchiveWithBadFilePath(t *testing.T) {
dir, err := ioutil.TempDir("", "tarwriter_test")
if err != nil {
assert.FailNow(t, "Cannot create temp dir", err.Error())
}
tempFilePath := filepath.Join(dir, "test_file.tar")
defer os.RemoveAll(dir)
w := tarfile.NewWriter(tempFilePath)
defer w.Close()
err = w.Open()
assert.Nil(t, err)
if _, err := os.Stat(w.PathToTarFile); os.IsNotExist(err) {
assert.Fail(t, "Tar file does not exist at %s", w.PathToTarFile)
}
// This file doesn't exist. Make sure we get the right error.
err = w.AddToArchive(pathToTestFile("this_file_does_not_exist"), "file1.json")
if err == nil {
assert.FailNow(t, "Should have gotten a tar write error")
}
assert.True(t, strings.Contains(err.Error(), "no such file or directory"))
}
示例12: TestAddToArchive
func TestAddToArchive(t *testing.T) {
dir, err := ioutil.TempDir("", "tarwriter_test")
if err != nil {
assert.FailNow(t, "Cannot create temp dir", err.Error())
}
tempFilePath := filepath.Join(dir, "test_file.tar")
defer os.RemoveAll(dir)
w := tarfile.NewWriter(tempFilePath)
defer w.Close()
err = w.Open()
assert.Nil(t, err)
if _, err := os.Stat(w.PathToTarFile); os.IsNotExist(err) {
assert.Fail(t, "Tar file does not exist at %s", w.PathToTarFile)
}
err = w.AddToArchive(pathToTestFile("cleanup_result.json"), "file1.json")
assert.Nil(t, err)
err = w.AddToArchive(pathToTestFile("ingest_result.json"), "data/subdir/file2.json")
assert.Nil(t, err)
w.Close()
file, err := os.Open(w.PathToTarFile)
if file != nil {
defer file.Close()
}
if err != nil {
assert.FailNow(t, "Could not open tar file", err.Error())
}
filesInArchive := make([]string, 0)
reader := tar.NewReader(file)
for {
header, err := reader.Next()
if err != nil {
break
}
filesInArchive = append(filesInArchive, header.Name)
}
assert.Equal(t, "file1.json", filesInArchive[0])
assert.Equal(t, "data/subdir/file2.json", filesInArchive[1])
}
示例13: parse
func parse(t *testing.T, remote string) *Reference {
reference, err := Parse(remote)
if err != nil {
assert.FailNow(t, "An error has occurred with the parser")
return nil
}
assert.NotNil(t, reference)
assert.NotEmpty(t, reference)
return reference
}
示例14: assertDeepValues
func assertDeepValues(t *testing.T, expected, actual []inference.Field) {
for _, v := range expected {
dataVal, err := whereKeyEquals(actual, v.Name)
if err != nil {
assert.FailNow(t, err.Error())
}
if dataVal.Type == "array" || dataVal.Type == "object" {
assertDeepValues(t, v.SubObject, dataVal.SubObject)
} else {
assert.EqualValues(t, v, *dataVal)
}
}
}
示例15: TestAndCloseOpen
func TestAndCloseOpen(t *testing.T) {
dir, err := ioutil.TempDir("", "tarwriter_test")
if err != nil {
assert.FailNow(t, "Cannot create temp dir", err.Error())
}
tempFilePath := filepath.Join(dir, "test_file.tar")
defer os.RemoveAll(dir)
w := tarfile.NewWriter(tempFilePath)
defer w.Close()
err = w.Open()
assert.Nil(t, err)
if _, err := os.Stat(w.PathToTarFile); os.IsNotExist(err) {
assert.Fail(t, "Tar file does not exist at %s", w.PathToTarFile)
}
err = w.Close()
assert.Nil(t, err)
}