本文整理汇总了Golang中github.com/stretchr/testify/assert.Fail函数的典型用法代码示例。如果您正苦于以下问题:Golang Fail函数的具体用法?Golang Fail怎么用?Golang Fail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fail函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestValidate_NoDataDir
func TestValidate_NoDataDir(t *testing.T) {
bagValidationConfig, err := getValidationConfig()
if err != nil {
assert.Fail(t, "Could not load BagValidationConfig: %s", err.Error())
}
optionalFileSpec := validation.FileSpec{Presence: "OPTIONAL"}
bagValidationConfig.FileSpecs["tagmanifest-md5.txt"] = optionalFileSpec
_, filename, _, _ := runtime.Caller(0)
dir := filepath.Dir(filename)
pathToBag, err := filepath.Abs(path.Join(dir, "..", "testdata", "unit_test_bags", "example.edu.sample_no_data_dir.tar"))
validator, err := validation.NewBagValidator(pathToBag, bagValidationConfig)
if err != nil {
assert.Fail(t, "NewBagValidator returned unexpected error: %s", err.Error())
}
result := validator.Validate()
assert.NotNil(t, result.IntellectualObject)
assert.Equal(t, 5, len(result.IntellectualObject.GenericFiles))
assert.True(t, strings.Contains(result.IntellectualObject.IngestErrorMessage,
"File 'data/datastream-DC' in manifest 'manifest-md5.txt' is missing"))
assert.True(t, strings.Contains(result.IntellectualObject.IngestErrorMessage,
"File 'data/datastream-descMetadata' in manifest 'manifest-md5.txt' is missing"))
assert.True(t, strings.Contains(result.IntellectualObject.IngestErrorMessage,
"File 'data/datastream-MARC' in manifest 'manifest-md5.txt' is missing"))
assert.True(t, strings.Contains(result.IntellectualObject.IngestErrorMessage,
"File 'data/datastream-RELS-EXT' in manifest 'manifest-md5.txt' is missing"))
assert.True(t, result.ParseSummary.HasErrors())
assert.NotNil(t, result.ValidationSummary)
require.True(t, result.ValidationSummary.HasErrors())
}
开发者ID:APTrust,项目名称:exchange,代码行数:29,代码来源:bag_validator_test.go
示例2: TestNewBagValidator_BadConfig
func TestNewBagValidator_BadConfig(t *testing.T) {
_, filename, _, _ := runtime.Caller(0)
dir := filepath.Dir(filename)
pathToBag, err := filepath.Abs(path.Join(dir, "..", "testdata", "unit_test_bags", "example.edu.tagsample_good.tar"))
if err != nil {
assert.Fail(t, "Can't figure out Abs path: %s", err.Error())
}
bagValidationConfig, err := getValidationConfig()
if err != nil {
assert.Fail(t, "Could not load BagValidationConfig: %v", err)
}
badPathSpec := validation.TagSpec{
FilePath: "",
Presence: "REQUIRED",
EmptyOK: true,
}
badPresenceSpec := validation.TagSpec{
FilePath: "orangina",
Presence: "orangina",
EmptyOK: true,
}
bagValidationConfig.TagSpecs["bad_path_spec"] = badPathSpec
bagValidationConfig.TagSpecs["bad_presence"] = badPresenceSpec
_, err = validation.NewBagValidator(pathToBag, bagValidationConfig)
require.NotNil(t, err)
assert.True(t, strings.Contains(err.Error(), "TagSpec for file ''"))
assert.True(t, strings.Contains(err.Error(), "TagSpec for file 'orangina'"))
}
开发者ID:APTrust,项目名称:exchange,代码行数:28,代码来源:bag_validator_test.go
示例3: TestValidate_BadFileNames
func TestValidate_BadFileNames(t *testing.T) {
bagValidationConfig, err := getValidationConfig()
if err != nil {
assert.Fail(t, "Could not load BagValidationConfig: %s", err.Error())
}
optionalFileSpec := validation.FileSpec{Presence: "OPTIONAL"}
bagValidationConfig.FileSpecs["tagmanifest-md5.txt"] = optionalFileSpec
_, filename, _, _ := runtime.Caller(0)
dir := filepath.Dir(filename)
pathToBag, err := filepath.Abs(path.Join(dir, "..", "testdata", "unit_test_bags", "example.edu.sample_bad_file_names.tar"))
validator, err := validation.NewBagValidator(pathToBag, bagValidationConfig)
if err != nil {
assert.Fail(t, "NewBagValidator returned unexpected error: %s", err.Error())
}
result := validator.Validate()
assert.NotNil(t, result.IntellectualObject)
assert.Equal(t, 9, len(result.IntellectualObject.GenericFiles))
assert.True(t, strings.Contains(result.IntellectualObject.IngestErrorMessage,
"Filename 'data/-starts-with-dash'"))
assert.True(t, strings.Contains(result.IntellectualObject.IngestErrorMessage,
"Filename 'data/contains#hash'"))
assert.True(t, strings.Contains(result.IntellectualObject.IngestErrorMessage,
"Filename 'data/contains*star'"))
assert.True(t, strings.Contains(result.IntellectualObject.IngestErrorMessage,
"Filename 'data/contains+plus'"))
assert.False(t, result.ParseSummary.HasErrors())
assert.NotNil(t, result.ValidationSummary)
require.True(t, result.ValidationSummary.HasErrors())
}
开发者ID:APTrust,项目名称:exchange,代码行数:29,代码来源:bag_validator_test.go
示例4: AssertContainsTaggedFields
func (a *Accumulator) AssertContainsTaggedFields(
t *testing.T,
measurement string,
fields map[string]interface{},
tags map[string]string,
) {
for _, p := range a.Points {
if !reflect.DeepEqual(tags, p.Tags) {
continue
}
if p.Measurement == measurement {
if !reflect.DeepEqual(fields, p.Fields) {
pActual, _ := json.MarshalIndent(p.Fields, "", " ")
pExp, _ := json.MarshalIndent(fields, "", " ")
msg := fmt.Sprintf("Actual:\n%s\n(%T) \nExpected:\n%s\n(%T)",
string(pActual), p.Fields, string(pExp), fields)
assert.Fail(t, msg)
}
return
}
}
msg := fmt.Sprintf("unknown measurement %s with tags %v", measurement, tags)
assert.Fail(t, msg)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:25,代码来源:accumulator.go
示例5: TestLoadBagValidationConfig
func TestLoadBagValidationConfig(t *testing.T) {
configFilePath := path.Join("testdata", "json_objects", "bag_validation_config.json")
conf, errors := validation.LoadBagValidationConfig(configFilePath)
if errors != nil && len(errors) > 0 {
assert.Fail(t, errors[0].Error())
}
assert.True(t, conf.AllowMiscTopLevelFiles)
assert.True(t, conf.AllowMiscDirectories)
assert.True(t, conf.TopLevelDirMustMatchBagName)
assert.Equal(t, 7, len(conf.FileSpecs))
assert.Equal(t, 3, len(conf.TagSpecs))
assert.Equal(t, 2, len(conf.FixityAlgorithms))
// Spot checks
if _, ok := conf.FileSpecs["manifest-md5.txt"]; !ok {
assert.Fail(t, "FileSpec for manifest-md5.txt is missing")
}
if _, ok := conf.FileSpecs["manifest-sha256.txt"]; !ok {
assert.Fail(t, "FileSpec for manifest-sha256.txt is missing")
}
if _, ok := conf.TagSpecs["Title"]; !ok {
assert.Fail(t, "TagSpec for Title is missing")
}
if len(conf.FixityAlgorithms) > 1 {
assert.Equal(t, "md5", conf.FixityAlgorithms[0])
assert.Equal(t, "sha256", conf.FixityAlgorithms[1])
}
assert.Equal(t, validation.REQUIRED, conf.FileSpecs["manifest-md5.txt"].Presence)
assert.Equal(t, validation.OPTIONAL, conf.FileSpecs["manifest-sha256.txt"].Presence)
assert.Equal(t, "aptrust-info.txt", conf.TagSpecs["Title"].FilePath)
assert.Equal(t, validation.REQUIRED, conf.TagSpecs["Title"].Presence)
assert.False(t, conf.TagSpecs["Title"].EmptyOK)
assert.Equal(t, 3, len(conf.TagSpecs["Access"].AllowedValues))
}
开发者ID:APTrust,项目名称:exchange,代码行数:34,代码来源:bag_validation_config_test.go
示例6: TestIdleOriginDirect
func TestIdleOriginDirect(t *testing.T) {
okAddr, err := impatientProxy(0, 30*time.Second)
if err != nil {
assert.Fail(t, "Error starting proxy server: %s", err)
}
impatientAddr, err := impatientProxy(0, 50*time.Millisecond)
if err != nil {
assert.Fail(t, "Error starting proxy server: %s", err)
}
okForwardFn := func(conn net.Conn, originURL *url.URL) {
var buf [400]byte
chunkedReq(t, &buf, conn, originURL)
assert.Contains(t, string(buf[:]), "200 OK", "should succeed")
}
failForwardFn := func(conn net.Conn, originURL *url.URL) {
var buf [400]byte
chunkedReq(t, &buf, conn, originURL)
assert.Contains(t, string(buf[:]), "502 Bad Gateway", "should fail with 502")
}
testRoundTrip(t, okAddr, false, httpOriginServer, okForwardFn)
testRoundTrip(t, impatientAddr, false, httpOriginServer, failForwardFn)
}
开发者ID:getlantern,项目名称:http-proxy,代码行数:26,代码来源:server_test.go
示例7: TestManifestInfoIsValid
func TestManifestInfoIsValid(t *testing.T) {
// Should flag all missing items
r := getReader("virginia.edu.uva-lib_2278801.tar")
outputPath := strings.Replace(r.Manifest.Object.IngestTarFilePath, ".tar", "", -1)
if len(outputPath) > 40 && strings.Contains(outputPath, "testdata") {
defer os.RemoveAll(outputPath)
}
r.Manifest.Object.Identifier = ""
r.Manifest.Object.BagName = ""
r.Manifest.Object.Institution = ""
r.Manifest.Object.IngestTarFilePath = ""
r.Untar()
assert.Equal(t, 5, len(r.Manifest.UntarResult.Errors))
// Should be specific about bad file path
r = getReader("virginia.edu.uva-lib_2278801.tar")
r.Manifest.Object.IngestTarFilePath = "/mUje9Dke0776adBx4Gq/file/does/not/exist.tar"
r.Untar()
if r.Manifest.UntarResult.HasErrors() == false {
assert.Fail(t, "Untar WorkSummary should have errors")
} else {
assert.True(t, strings.Contains(r.Manifest.UntarResult.Errors[0], "does not exist"))
}
// If IntellectualObject is nil, we should get an
// error message and not a panic.
r = getReader("virginia.edu.uva-lib_2278801.tar")
r.Manifest.Object = nil
r.Untar()
if r.Manifest.UntarResult.HasErrors() == false {
assert.Fail(t, "Untar WorkSummary should have errors")
} else {
assert.Equal(t, "IntellectualObject is missing from manifest.", r.Manifest.UntarResult.Errors[0])
}
}
开发者ID:APTrust,项目名称:exchange,代码行数:35,代码来源:reader_test.go
示例8: TestGetRecommendations
func TestGetRecommendations(t *testing.T) {
r1 := model.Relationship{"Tester", "tester1", "Test", "test1", "tested"}
r2 := model.Relationship{"Tester", "tester2", "Test", "test1", "tested"}
r3 := model.Relationship{"Tester", "tester2", "Test", "test2", "tested"}
r4 := model.Relationship{"Tester", "tester2", "Test", "test3", "tested"}
ProcessAddEvent(&r1)
ProcessAddEvent(&r2)
ProcessAddEvent(&r3)
ProcessAddEvent(&r4)
rq := model.RecommendationRequest{"Tester", "tester1", "Test", "tested", 5}
recommendation, err := GetRecommendations(&rq)
if err != nil {
assert.Fail(t, "Unexpected error: "+err.Error())
} else {
assert.Len(t, recommendation.Results, 2, "Unexpected size of results")
}
ProcessRemoveEvent(&r4)
recommendation, err = GetRecommendations(&rq)
if err != nil {
assert.Fail(t, "Unexpected error: "+err.Error())
} else {
assert.Len(t, recommendation.Results, 1, "Unexpected size of results")
}
ProcessRemoveEvent(&r1)
ProcessRemoveEvent(&r2)
ProcessRemoveEvent(&r3)
}
开发者ID:halk,项目名称:in-common,代码行数:30,代码来源:recommend_test.go
示例9: TestSuccessCodeAndInfoForComplexMessage
// TestSuccessCodeAndInfoForComplexMessage sends out a complex message to the pubnub channel
func TestSuccessCodeAndInfoForComplexMessage(t *testing.T) {
assert := assert.New(t)
stop, _ := NewVCRNonSubscribe(
"fixtures/publish/successCodeAndInfoForComplexMessage", []string{"uuid"})
defer stop()
pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, "")
channel := "successCodeAndInfoForComplexMessage"
customStruct := CustomStruct{
Foo: "hi!",
Bar: []int{1, 2, 3, 4, 5},
}
successChannel := make(chan []byte)
errorChannel := make(chan []byte)
go pubnubInstance.Publish(channel, customStruct, successChannel, errorChannel)
select {
case msg := <-successChannel:
assert.Contains(string(msg), "1,")
assert.Contains(string(msg), "\"Sent\",")
case err := <-errorChannel:
assert.Fail(string(err))
case <-timeout():
assert.Fail("Publish timeout")
}
}
开发者ID:pubnub,项目名称:go,代码行数:30,代码来源:pubnubPublish_test.go
示例10: assertContainsTaggedFloat
// Asserts that a given accumulator contains a measurment of type float64 with
// specific tags within a certain distance of a given expected value. Asserts a failure
// if the measurement is of the wrong type, or if no matching measurements are found
//
// Paramaters:
// t *testing.T : Testing object to use
// acc testutil.Accumulator: Accumulator to examine
// measurement string : Name of the measurement to examine
// expectedValue float64 : Value to search for within the measurement
// delta float64 : Maximum acceptable distance of an accumulated value
// from the expectedValue parameter. Useful when
// floating-point arithmatic imprecision makes looking
// for an exact match impractical
// tags map[string]string : Tag set the found measurement must have. Set to nil to
// ignore the tag set.
func assertContainsTaggedFloat(
t *testing.T,
acc testutil.Accumulator,
measurement string,
expectedValue float64,
delta float64,
tags map[string]string,
) {
for _, pt := range acc.Points {
if pt.Measurement == measurement {
if (tags == nil) || reflect.DeepEqual(pt.Tags, tags) {
if value, ok := pt.Values["value"].(float64); ok {
if (value >= expectedValue-delta) && (value <= expectedValue+delta) {
// Found the point, return without failing
return
}
} else {
assert.Fail(t, fmt.Sprintf("Measurement \"%s\" does not have type float64", measurement))
}
}
}
}
assert.Fail(t, fmt.Sprintf("Could not find measurement \"%s\" with requested tags within %f of %f", measurement, delta, expectedValue))
}
开发者ID:pablrod,项目名称:telegraf,代码行数:40,代码来源:system_test.go
示例11: TestSubscriptionConnectStatus
// TestSubscriptionConnectStatus sends out a subscribe request to a pubnub channel
// and validates the response for the connect status.
func TestSubscriptionConnectStatus(t *testing.T) {
assert := assert.New(t)
stop, _ := NewVCRBoth(
"fixtures/subscribe/connectStatus", []string{"uuid"})
defer stop()
channel := "Channel_ConnectStatus"
uuid := "UUID_ConnectStatus"
pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, uuid)
successChannel := make(chan []byte)
errorChannel := make(chan []byte)
unsubscribeSuccessChannel := make(chan []byte)
unsubscribeErrorChannel := make(chan []byte)
go pubnubInstance.Subscribe(channel, "", successChannel, false, errorChannel)
select {
case resp := <-successChannel:
response := fmt.Sprintf("%s", resp)
if response != "[]" {
message := "'" + channel + "' connected"
assert.Contains(response, message)
}
case err := <-errorChannel:
if !IsConnectionRefusedError(err) {
assert.Fail(string(err))
}
case <-timeouts(3):
assert.Fail("Subscribe timeout 3s")
}
go pubnubInstance.Unsubscribe(channel, unsubscribeSuccessChannel, unsubscribeErrorChannel)
ExpectUnsubscribedEvent(t, channel, "", unsubscribeSuccessChannel, unsubscribeErrorChannel)
}
开发者ID:pubnub,项目名称:go,代码行数:37,代码来源:pubnubSubscribe_test.go
示例12: TestGetDataCipher
func TestGetDataCipher(t *testing.T) {
assert := assert.New(t)
pubnub := Pubnub{
cipherKey: "enigma",
infoLogger: log.New(ioutil.Discard, "", log.Ldate|log.Ltime|log.Lshortfile),
}
response := `[["h5Uhyc8uf3h11w5C68QsVenCf7Llvdq5XWLa1RSgdfU=","AA9MBpymUzq/bfLCtIKFB+J6L+s3UGm6xPGh9kuXsoQ=","SfGYYp58jU2FGBNNsRk0kZ8KWRjZ6OsG3OxSySd7FF0=","ek+lrKjHCJPp5wYpxWlZcg806w/SWU5dzNYmjqDVb6o=","HrIrwvdGrm3/TM4kCf0EGl5SzcD+JqOXesWtzzc8+UA="],14610686757083461,14610686757935083]`
var contents = []byte(response)
var s interface{}
err := json.Unmarshal(contents, &s)
if err == nil {
v := s.(interface{})
switch vv := v.(type) {
case []interface{}:
length := len(vv)
if length > 0 {
msgStr := pubnub.getData(vv[0], pubnub.cipherKey)
//pubnub.infoLogger.Printf(msgStr)
assert.Equal("[\"Test Message 5\",\"Test Message 6\",\"Test Message 7\",\"Test Message 8\",\"Test Message 9\"]", msgStr)
}
default:
assert.Fail("default fall through")
}
} else {
assert.Fail("Unmarshal failed")
}
}
开发者ID:pubnub,项目名称:go,代码行数:28,代码来源:pubnub_test.go
示例13: assertContainsTaggedFloat
// Asserts that a given accumulator contains a measurment of type float64 with
// specific tags within a certain distance of a given expected value. Asserts a failure
// if the measurement is of the wrong type, or if no matching measurements are found
//
// Paramaters:
// t *testing.T : Testing object to use
// acc testutil.Accumulator: Accumulator to examine
// measurement string : Name of the measurement to examine
// expectedValue float64 : Value to search for within the measurement
// delta float64 : Maximum acceptable distance of an accumulated value
// from the expectedValue parameter. Useful when
// floating-point arithmatic imprecision makes looking
// for an exact match impractical
// tags map[string]string : Tag set the found measurement must have. Set to nil to
// ignore the tag set.
func assertContainsTaggedFloat(
t *testing.T,
acc *testutil.Accumulator,
measurement string,
field string,
expectedValue float64,
delta float64,
tags map[string]string,
) {
var actualValue float64
for _, pt := range acc.Points {
if pt.Measurement == measurement {
for fieldname, value := range pt.Fields {
if fieldname == field {
if value, ok := value.(float64); ok {
actualValue = value
if (value >= expectedValue-delta) && (value <= expectedValue+delta) {
// Found the point, return without failing
return
}
} else {
assert.Fail(t, fmt.Sprintf("Measurement \"%s\" does not have type float64",
measurement))
}
}
}
}
}
msg := fmt.Sprintf(
"Could not find measurement \"%s\" with requested tags within %f of %f, Actual: %f",
measurement, delta, expectedValue, actualValue)
assert.Fail(t, msg)
}
开发者ID:d4devops,项目名称:telegraf,代码行数:48,代码来源:cpu_test.go
示例14: TestSpecInNamespaceGone
// TestSpecInNamespaceGone validates that, if you delete a work spec's
// namespace, attempts to use the work spec return ErrGone.
func TestSpecInNamespaceGone(t *testing.T) {
sts := SimpleTestSetup{
NamespaceName: "TestSpecInNamespaceGone",
WorkSpecName: "spec",
}
sts.SetUp(t)
// We are about to blow up the namespace now so there is no cleanup
err := sts.Namespace.Destroy()
assert.NoError(t, err)
// Test a couple of basic things
_, err = sts.WorkSpec.Meta(false)
if err == coordinate.ErrGone {
// okay
} else if nsws, ok := err.(coordinate.ErrNoSuchWorkSpec); ok {
assert.Equal(t, sts.WorkSpecName, nsws.Name)
} else {
assert.Fail(t, "unexpected error reading deleted work spec meta",
"+v", err)
}
_, err = sts.WorkSpec.AddWorkUnit("foo", map[string]interface{}{}, coordinate.WorkUnitMeta{})
if err == coordinate.ErrGone {
// okay
} else if nsws, ok := err.(coordinate.ErrNoSuchWorkSpec); ok {
assert.Equal(t, sts.WorkSpecName, nsws.Name)
} else {
assert.Fail(t, "unexpected error adding work to deleted work spec",
"+v", err)
}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:34,代码来源:work_spec.go
示例15: TestUnsubscribe
func TestUnsubscribe(t *testing.T) {
client := create(t)
defer client.TearDown()
listener := client.Listener(Channel, "foobar")
client.WaitFor(SubscribeEvent)
publish("foobar", "heyo!")
assert.Equal(t, "heyo!", string((<-listener.Messages).Data))
// Unsubscribe, then publish and listen for a second to make sure
// the event doesn't come in.
listener.Unsubscribe()
client.WaitFor(UnsubscribeEvent)
publish("foobar", "heyo!")
select {
case packet := <-client.OnChannel(AnyEvent):
assert.Fail(t, fmt.Sprintf("Got 'some' packet after unsubscribe: %#v", packet))
case <-time.After(time.Millisecond * 100):
}
disrupt(client)
// Make sure we don't resubscribe after a disruption.
publish("foobar", "heyo!")
select {
case packet := <-client.OnChannel(AnyEvent):
assert.Fail(t, fmt.Sprintf("Got 'some' packet after unsubscribe reconnect: %#v", packet))
case <-time.After(time.Millisecond * 100):
}
}
开发者ID:wulffeld,项目名称:redutil,代码行数:31,代码来源:pubsub_test.go
示例16: TestDeStruct
func TestDeStruct(t *testing.T) {
for i, test := range tests {
outputCopy, outputScalar, outputFields := deStruct(test.input)
testInputPtr := reflect.ValueOf(&test.input).Pointer()
outputCopyPtr := reflect.ValueOf(&outputCopy).Pointer()
assertionMessage := fmt.Sprintf("Test #%d: %#v", i, test.input)
assert.NotEqual(t, testInputPtr, outputCopyPtr, assertionMessage)
// tests commented pending fix for https://github.com/stretchr/testify/issues/144
//assert.IsType(t, test.outputCopy, outputCopy, assertionMessage)
//assert.Exactly(t, test.outputCopy, outputCopy, assertionMessage)
if !reflect.DeepEqual(test.outputCopy, outputCopy) {
assert.Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+
" != %#v (actual)", test.outputCopy, outputCopy), assertionMessage)
}
assert.Equal(t, test.outputScalar, outputScalar, assertionMessage)
//assert.Equal(t, test.outputFields, outputFields, assertionMessage)
if !reflect.DeepEqual(test.outputFields, outputFields) {
assert.Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+
" != %#v (actual)", test.outputFields, outputFields), assertionMessage)
}
}
}
开发者ID:christianbak,项目名称:sawmill,代码行数:25,代码来源:destruct_test.go
示例17: TestGetConnTimeout
func TestGetConnTimeout(t *testing.T) {
assert := assert.New(t)
pool, err := NewPool(1, 3, connCreator)
if err != nil {
assert.Fail("Init conn pool fail.")
return
}
for i := 0; i < 3; i++ {
conn, err := pool.Get()
if err != nil {
assert.Fail("Get conn fail.")
}
_, err = conn.Write([]byte("Test conn1"))
if err != nil {
assert.Fail("Write message fail.")
}
}
_, err = pool.GetWithTimeout(time.Duration(1) * time.Second)
if err != nil {
fmt.Println(err)
return
}
assert.Fail("Need get timeout error.")
}
开发者ID:twocool,项目名称:gncp,代码行数:26,代码来源:pool_test.go
示例18: TestActorCanStopChildren
func TestActorCanStopChildren(t *testing.T) {
responsePID, result := RequestResponsePID()
responsePID2, result2 := RequestResponsePID()
actor := Spawn(FromProducer(NewCreateChildThenStopActor))
count := 10
for i := 0; i < count; i++ {
actor.Tell(CreateChildMessage{})
}
actor.Tell(GetChildCountMessage2{ReplyDirectly: responsePID, ReplyAfterStop: responsePID2})
//wait for the actor to reply to the first responsePID
_, err := result.ResultOrTimeout(testTimeout)
if err != nil {
assert.Fail(t, "timed out")
return
}
//then send a stop command
actor.Stop()
//wait for the actor to stop and get the result from the stopped handler
response, err := result2.ResultOrTimeout(testTimeout)
if err != nil {
assert.Fail(t, "timed out")
return
}
//we should have 0 children when the actor is stopped
assert.Equal(t, 0, response.(GetChildCountReplyMessage).ChildCount)
}
开发者ID:yonglehou,项目名称:gam,代码行数:29,代码来源:interaction_test.go
示例19: TestFileHandling
func (suite *AnnoyTestSuite) TestFileHandling() {
index := annoyindex.NewAnnoyIndexAngular(3)
index.AddItem(0, []float32{0, 0, 1})
index.AddItem(1, []float32{0, 1, 0})
index.AddItem(2, []float32{1, 0, 0})
index.Build(10)
index.Save("go_test.ann")
info, err := os.Stat("go_test.ann")
if err != nil {
assert.Fail(suite.T(), "Failed to create file, file not found")
}
if info.Size() == 0 {
assert.Fail(suite.T(), "Failed to create file, file size zero")
}
annoyindex.DeleteAnnoyIndexAngular(index)
index = annoyindex.NewAnnoyIndexAngular(3)
if ret := index.Load("go_test.ann"); ret == false {
assert.Fail(suite.T(), "Failed to load file")
}
annoyindex.DeleteAnnoyIndexAngular(index)
os.Remove("go_test.ann")
}
开发者ID:spotify,项目名称:annoy,代码行数:27,代码来源:annoy_test.go
示例20: TestGetDataCipherNonEncSingle
func TestGetDataCipherNonEncSingle(t *testing.T) {
assert := assert.New(t)
pubnub := Pubnub{
cipherKey: "enigma",
infoLogger: log.New(ioutil.Discard, "", log.Ldate|log.Ltime|log.Lshortfile),
}
response := "[\"Test Message 5\",14610686757083461,14610686757935083]"
var contents = []byte(response)
var s interface{}
err := json.Unmarshal(contents, &s)
if err == nil {
v := s.(interface{})
switch vv := v.(type) {
case []interface{}:
length := len(vv)
if length > 0 {
msgStr := pubnub.parseInterface(vv, pubnub.cipherKey)
//pubnub.infoLogger.Printf(msgStr)
assert.Equal("[\"Test Message 5\",1.461068675708346e+16,1.4610686757935084e+16]", msgStr)
}
default:
assert.Fail("default fall through")
}
} else {
assert.Fail("Unmarshal failed %s", err.Error())
}
}
开发者ID:pubnub,项目名称:go,代码行数:28,代码来源:pubnub_test.go
注:本文中的github.com/stretchr/testify/assert.Fail函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论