当前位置: 首页>>代码示例>>Golang>>正文


Golang Assertions.Fail方法代码示例

本文整理汇总了Golang中github.com/stretchr/testify/assert.Assertions.Fail方法的典型用法代码示例。如果您正苦于以下问题:Golang Assertions.Fail方法的具体用法?Golang Assertions.Fail怎么用?Golang Assertions.Fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/stretchr/testify/assert.Assertions的用法示例。


在下文中一共展示了Assertions.Fail方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: assertChannelContainsMessage

func assertChannelContainsMessage(a *assert.Assertions, c <-chan *protocol.Message, msg []byte) {
	select {
	case m := <-c:
		a.Equal(string(msg), string(m.Body))
	case <-time.After(time.Millisecond * 5):
		a.Fail("No message received")
	}
}
开发者ID:smancke,项目名称:guble,代码行数:8,代码来源:router_test.go

示例2: ExpectDone

// ExpectDone waits to receive a value in the doneChannel for at least a second
// or fails the test.
func ExpectDone(a *assert.Assertions, doneChannel chan bool) {
	select {
	case <-doneChannel:
		return
	case <-time.After(time.Second):
		a.Fail("timeout in expectDone")
	}
}
开发者ID:smancke,项目名称:guble,代码行数:10,代码来源:testutil.go

示例3: assertChannelContainsMessage

func assertChannelContainsMessage(a *assert.Assertions, c chan MsgAndRoute, msg []byte) {
	//log.Println("DEBUG: start assertChannelContainsMessage-> select")
	select {
	case msgBack := <-c:
		a.Equal(string(msg), string(msgBack.Message.Body))
	case <-time.After(time.Millisecond):
		a.Fail("No message received")
	}
}
开发者ID:mley,项目名称:guble,代码行数:9,代码来源:router_test.go

示例4: messagePartitionReader

func messagePartitionReader(name string, a *assert.Assertions, store *MessagePartition, n int, done chan bool) {
	lastReadMessage := 0
	for lastReadMessage < n {

		msgC := make(chan MessageAndId)
		errorC := make(chan error)

		log.WithFields(log.Fields{
			"module":      "testing",
			"name":        name,
			"lastReadMsg": lastReadMessage + 1,
		}).Debug("Start fetching at")

		store.Fetch(FetchRequest{
			Partition:     "myMessages",
			StartId:       uint64(lastReadMessage + 1),
			Direction:     1,
			Count:         math.MaxInt32,
			MessageC:      msgC,
			ErrorCallback: errorC,
			StartCallback: make(chan int, 1),
		})

	fetch:

		for {
			select {
			case msgAndId, open := <-msgC:
				if !open {

					log.WithFields(log.Fields{
						"module":      "testing",
						"name":        name,
						"lastReadMsg": lastReadMessage,
					}).Debug("Stop fetching at")

					break fetch
				}
				a.Equal(lastReadMessage+1, int(msgAndId.Id))
				lastReadMessage = int(msgAndId.Id)
			case err := <-errorC:
				a.Fail("received error", err.Error())
				<-done
				return
			}
		}

	}
	log.WithFields(log.Fields{
		"module":      "testing",
		"name":        name,
		"lastReadMsg": lastReadMessage,
	}).Debug("Ready got id")

	done <- true
}
开发者ID:cosminrentea,项目名称:guble,代码行数:56,代码来源:message_partition_robustness_test.go

示例5: expectMessages

func expectMessages(a *assert.Assertions, msgChannel chan []byte, message ...string) {
	for _, m := range message {
		select {
		case msg := <-msgChannel:
			a.Equal(m, string(msg))
		case <-time.After(time.Millisecond * 100):
			a.Fail("timeout: " + m)
		}
	}
}
开发者ID:tkrille,项目名称:guble,代码行数:10,代码来源:receiver_test.go

示例6: loadJson

func loadJson(filename string, a *assert.Assertions) map[string]string {
	var data map[string]string
	content, err := ioutil.ReadFile("./test.json")

	if err != nil {
		a.Fail("Failed to read file ", err)
	}

	json.Unmarshal(content, &data)
	return data
}
开发者ID:DarkToast,项目名称:go-workshop,代码行数:11,代码来源:fileRepo_test.go

示例7: messagePartitionReader

func messagePartitionReader(name string, a *assert.Assertions, mStore *messagePartition, n int, done chan bool) {
	lastReadMessage := 0

	for lastReadMessage < n {
		msgC := make(chan *store.FetchedMessage, 10)
		errorC := make(chan error)

		log.WithFields(log.Fields{
			"module":      "testing",
			"name":        name,
			"lastReadMsg": lastReadMessage + 1,
		}).Debug("Start fetching")

		mStore.Fetch(&store.FetchRequest{
			Partition: "myMessages",
			StartID:   uint64(lastReadMessage + 1),
			Direction: 1,
			Count:     math.MaxInt32,
			MessageC:  msgC,
			ErrorC:    errorC,
			StartC:    make(chan int, 1),
		})

	FETCH:
		for {
			select {
			case msgAndID, open := <-msgC:
				if !open {
					log.WithFields(log.Fields{
						"module":      "testing",
						"name":        name,
						"lastReadMsg": lastReadMessage,
					}).Debug("Stop fetching")
					break FETCH
				}
				a.Equal(lastReadMessage+1, int(msgAndID.ID), "Reader: "+name)
				lastReadMessage = int(msgAndID.ID)
			case err := <-errorC:
				a.Fail("received error", err.Error())
				<-done
				return
			}
		}
	}

	log.WithFields(log.Fields{
		"module":      "testing",
		"name":        name,
		"lastReadMsg": lastReadMessage,
	}).Debug("Ready got id")

	done <- true
}
开发者ID:smancke,项目名称:guble,代码行数:53,代码来源:message_partition_robustness_test.go

示例8: deepCheckValue

// deepCheckValue checks that all given keys correspond to a valid path in the
// configuration map of the given layer, and that the final value equals the one given
func deepCheckValue(assert *assert.Assertions, v *Viper, l layer, keys []string, value interface{}) {
	if assert == nil || v == nil ||
		len(keys) == 0 || len(keys[0]) == 0 {
		return
	}

	// init
	var val interface{}
	var ms string
	switch l {
	case defaultLayer:
		val = v.defaults
		ms = "v.defaults"
	case overrideLayer:
		val = v.override
		ms = "v.override"
	}

	// loop through map
	var m map[string]interface{}
	err := false
	for _, k := range keys {
		if val == nil {
			assert.Fail(fmt.Sprintf("%s is not a map[string]interface{}", ms))
			return
		}

		// deep scan of the map to get the final value
		switch val.(type) {
		case map[interface{}]interface{}:
			m = cast.ToStringMap(val)
		case map[string]interface{}:
			m = val.(map[string]interface{})
		default:
			assert.Fail(fmt.Sprintf("%s is not a map[string]interface{}", ms))
			return
		}
		ms = ms + "[\"" + k + "\"]"
		val = m[k]
	}
	if !err {
		assert.Equal(value, val)
	}
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:46,代码来源:overrides_test.go

示例9: asserChannelContainsEntries

func asserChannelContainsEntries(a *assert.Assertions, entryC chan [2]string, expectedEntries ...[2]string) {
	allEntries := make([][2]string, 0)

loop:
	for {
		select {
		case entry, ok := <-entryC:
			if !ok {
				break loop
			}
			allEntries = append(allEntries, entry)
		case <-time.After(time.Second):
			a.Fail("timeout")
		}
	}

	a.Equal(len(expectedEntries), len(allEntries))
	for _, expected := range expectedEntries {
		a.Contains(allEntries, expected)
	}
}
开发者ID:cosminrentea,项目名称:guble,代码行数:21,代码来源:common_test.go

示例10: assertChannelContains

func assertChannelContains(a *assert.Assertions, entryC chan string, expectedEntries ...string) {
	var allEntries []string

WAITLOOP:
	for {
		select {
		case entry, ok := <-entryC:
			if !ok {
				break WAITLOOP
			}
			allEntries = append(allEntries, entry)
		case <-time.After(time.Second):
			a.Fail("timeout")
		}
	}

	a.Equal(len(expectedEntries), len(allEntries))
	for _, expected := range expectedEntries {
		a.Contains(allEntries, expected)
	}
}
开发者ID:smancke,项目名称:guble,代码行数:21,代码来源:common_test.go

示例11: runTestCase

func runTestCase(assert *assert.Assertions, given interface{}, testcase TestCase, filename string) {
	lexer := NewLexer()
	var err error
	_, err = lexer.tokenize(testcase.Expression)
	if err != nil {
		errMsg := fmt.Sprintf("(%s) Could not lex expression: %s -- %s", filename, testcase.Expression, err.Error())
		assert.Fail(errMsg)
		return
	}
	parser := NewParser()
	_, err = parser.Parse(testcase.Expression)
	if err != nil {
		errMsg := fmt.Sprintf("(%s) Could not parse expression: %s -- %s", filename, testcase.Expression, err.Error())
		assert.Fail(errMsg)
		return
	}
	actual, err := Search(testcase.Expression, given)
	if assert.Nil(err, fmt.Sprintf("Expression: %s", testcase.Expression)) {
		assert.Equal(testcase.Result, actual, fmt.Sprintf("Expression: %s", testcase.Expression))
	}
}
开发者ID:CNDonny,项目名称:scope,代码行数:21,代码来源:compliance_test.go

示例12: messagePartitionReader

func messagePartitionReader(name string, a *assert.Assertions, store *MessagePartition, n int, done chan bool) {
	lastReadMessage := 0
	for lastReadMessage < n {

		msgC := make(chan MessageAndId)
		errorC := make(chan error)

		guble.Debug("[%v] start fetching at: %v", name, lastReadMessage+1)
		store.Fetch(FetchRequest{
			Partition:     "myMessages",
			StartId:       uint64(lastReadMessage + 1),
			Direction:     1,
			Count:         math.MaxInt32,
			MessageC:      msgC,
			ErrorCallback: errorC,
			StartCallback: make(chan int, 1),
		})

	fetch:

		for {
			select {
			case msgAndId, open := <-msgC:
				if !open {
					guble.Debug("[%v] stop fetching at %v", name, lastReadMessage)
					break fetch
				}
				a.Equal(lastReadMessage+1, int(msgAndId.Id))
				lastReadMessage = int(msgAndId.Id)
			case err := <-errorC:
				a.Fail("received error", err.Error())
				<-done
				return
			}
		}

	}
	guble.Debug("[%v] ready, got %v", name, lastReadMessage)
	done <- true
}
开发者ID:tkrille,项目名称:guble,代码行数:40,代码来源:message_partition_robustness_test.go

示例13: checkNode

func checkNode(t testing.TB, x *assert.Assertions, node Node) {
	acount, err := node.AdjacentCount()
	if err != nil {
		t.Fatal(err)
	}
	kcount, err := node.ChildCount()
	if err != nil {
		t.Fatal(err)
	}
	kids, err := node.Children()
	if err != nil {
		t.Fatal(err)
	}
	pcount, err := node.ParentCount()
	if err != nil {
		t.Fatal(err)
	}
	parents, err := node.Parents()
	if err != nil {
		t.Fatal(err)
	}
	if kcount != len(kids) {
		x.Fail("kcount != len(kids)")
	}
	if pcount != len(parents) {
		x.Fail("count != len(parents)")
	}
	if kcount+pcount != acount {
		x.Fail("kcount + pcount != acount")
	}
	for _, kid := range kids {
		checkKid(t, x, node, kid.(Node))
	}
	for _, parent := range parents {
		checkKid(t, x, parent.(Node), node)
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:37,代码来源:connected_test.go

示例14: checkKid

func checkKid(t testing.TB, x *assert.Assertions, parent, kid Node) {
	pkids, err := parent.Children()
	if err != nil {
		t.Fatal(err)
	}
	found := false
	for _, pkid := range pkids {
		if bytes.Equal(pkid.Pattern().Label(), kid.Label()) {
			found = true
		}
	}
	if !found {
		t.Errorf("parent %v kids %v did not have %v", parent, pkids, kid)
		findChildren(parent, nil, true)
		t.Fatalf("assert-fail")
	}
	kparents, err := kid.Parents()
	if err != nil {
		t.Fatal(err)
	}
	found = false
	for _, kparent := range kparents {
		if bytes.Equal(kparent.Pattern().Label(), parent.Label()) {
			found = true
		}
	}
	if !found {
		t.Fatalf("kid %v parents %v did not have %v", kid, kparents, parent)
	}
	pkids, err = parent.CanonKids()
	if err != nil {
		errors.Logf("ERROR", "err = %v", err)
		x.Fail("err != nil")
		os.Exit(2)
	}
	found = false
	for _, pkid := range pkids {
		if bytes.Equal(pkid.Pattern().Label(), kid.Label()) {
			found = true
		}
	}
	if found {
		// kid is a canon kid
		// kid should have no other canon parents
		kparents, err := kid.Parents()
		if err != nil {
			t.Fatal(err)
		}
		found = false
		for _, kparent := range kparents {
			if bytes.Equal(kparent.Pattern().Label(), parent.Label()) {
				continue
			}
			kparent_ckids, err := kparent.CanonKids()
			if err != nil {
				t.Fatal(err)
			}
			for _, kparent_ckid := range kparent_ckids {
				if bytes.Equal(kparent_ckid.Pattern().Label(), kid.Label()) {
					x.Fail(errors.Errorf("kid %v had multiple canon parents %v %v", kid, parent, kparent).Error())
				}
			}
		}
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:65,代码来源:connected_test.go


注:本文中的github.com/stretchr/testify/assert.Assertions.Fail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。