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


Golang assert.Assertions类代码示例

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


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

示例1: messagePartitionWriter

func messagePartitionWriter(a *assert.Assertions, store *messagePartition, n int, done chan bool) {
	for i := 1; i <= n; i++ {
		msg := []byte("Hello " + strconv.Itoa(i))
		a.NoError(store.Store(uint64(i), msg))
	}
	done <- true
}
开发者ID:smancke,项目名称:guble,代码行数:7,代码来源:message_partition_robustness_test.go

示例2: assertOrder

// Assert Order type
func assertOrder(assert *assert.Assertions, order *OrderReply) {
	assert.EqualValues(123, order.OrderId)
	assert.Equal("test", order.ResultCode)
	assert.Equal("test", order.OrderState)
	assert.Equal("test", order.ActionState)
	assert.Equal("test", order.Message)
}
开发者ID:gurre,项目名称:nordnet,代码行数:8,代码来源:api_test.go

示例3: overrideFromLayer

// overrideFromLayer performs the sequential override and low-level checks.
//
// First assignment is made on layer l for path firstPath with value firstValue,
// the second one on the override layer (i.e., with the Set() function)
// for path secondPath with value secondValue.
//
// firstPath and secondPath can include an arbitrary number of dots to indicate
// a nested element.
//
// After each assignment, the value is checked, retrieved both by its full path
// and by its key sequence (successive maps).
func overrideFromLayer(l layer, assert *assert.Assertions, firstPath string, firstValue interface{}, secondPath string, secondValue interface{}) *Viper {
	v := New()
	firstKeys := strings.Split(firstPath, v.keyDelim)
	if assert == nil ||
		len(firstKeys) == 0 || len(firstKeys[0]) == 0 {
		return v
	}

	// Set and check first value
	switch l {
	case defaultLayer:
		v.SetDefault(firstPath, firstValue)
	case overrideLayer:
		v.Set(firstPath, firstValue)
	default:
		return v
	}
	assert.Equal(firstValue, v.Get(firstPath))
	deepCheckValue(assert, v, l, firstKeys, firstValue)

	// Override and check new value
	secondKeys := strings.Split(secondPath, v.keyDelim)
	if len(secondKeys) == 0 || len(secondKeys[0]) == 0 {
		return v
	}
	v.Set(secondPath, secondValue)
	assert.Equal(secondValue, v.Get(secondPath))
	deepCheckValue(assert, v, overrideLayer, secondKeys, secondValue)

	return v
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:42,代码来源:overrides_test.go

示例4: 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

示例5: 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

示例6: writeJSONToService

func writeJSONToService(service annotations.Service, pathToJSONFile string, contentUUID string, assert *assert.Assertions) {
	f, err := os.Open(pathToJSONFile)
	assert.NoError(err)
	dec := json.NewDecoder(f)
	annotation, errr := service.DecodeJSON(dec)
	assert.NoError(errr)
	errrr := service.Write(contentUUID, annotation)
	assert.NoError(errrr)
}
开发者ID:Financial-Times,项目名称:organisations-rw-neo4j,代码行数:9,代码来源:service_concording_scenarios_test.go

示例7: writeJSONToService

func writeJSONToService(service baseftrwapp.Service, pathToJSONFile string, assert *assert.Assertions) {
	f, err := os.Open(pathToJSONFile)
	assert.NoError(err)
	dec := json.NewDecoder(f)
	inst, _, errr := service.DecodeJSON(dec)
	assert.NoError(errr)
	errrr := service.Write(inst)
	assert.NoError(errrr)
}
开发者ID:Financial-Times,项目名称:public-organisations-api,代码行数:9,代码来源:cypher_test.go

示例8: 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

示例9: 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

示例10: 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

示例11: verifyLocalFileFromDefaultAsset

func verifyLocalFileFromDefaultAsset(dir string, assert *assert.Assertions) {
	assert.Nil(verifyLocalFile(dir, "index.html"))
	assert.Nil(verifyLocalFile(dir, "site.js"))
	assert.Nil(verifyLocalFile(dir, "assets/1.txt"))
	assert.Nil(verifyLocalFile(dir, "assets/2.txt"))
	assert.Nil(verifyLocalFile(dir, "assets/more/3.txt"))
	assert.Nil(verifyLocalFile(dir, "assets/four/4.txt"))
	assert.Nil(verifyLocalFile(dir, "assets/fivesix/5.txt"))
	assert.Nil(verifyLocalFile(dir, "assets/fivesix/6.txt"))
}
开发者ID:jeremyje,项目名称:gowebserver,代码行数:10,代码来源:zip_test.go

示例12: 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

示例13: runComplianceTest

func runComplianceTest(assert *assert.Assertions, filename string) {
	var testSuites []TestSuite
	data, err := ioutil.ReadFile(filename)
	if assert.Nil(err) {
		err := json.Unmarshal(data, &testSuites)
		if assert.Nil(err) {
			for _, testsuite := range testSuites {
				runTestSuite(assert, testsuite, filename)
			}
		}
	}
}
开发者ID:CNDonny,项目名称:scope,代码行数:12,代码来源:compliance_test.go

示例14: 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

示例15: getServices

func getServices(t *testing.T, assert *assert.Assertions, db neoutils.NeoConnection) (baseftrwapp.Service, baseftrwapp.Service, baseftrwapp.Service, baseftrwapp.Service, baseftrwapp.Service) {
	peopleRW := people.NewCypherPeopleService(db)
	assert.NoError(peopleRW.Initialise())
	organisationRW := organisations.NewCypherOrganisationService(db)
	assert.NoError(organisationRW.Initialise())
	membershipsRW := memberships.NewCypherMembershipService(db)
	assert.NoError(membershipsRW.Initialise())
	rolesRW := roles.NewCypherDriver(db)
	assert.NoError(rolesRW.Initialise())
	financialInstrumentsRW := financialinstruments.NewCypherFinancialInstrumentService(db)
	assert.NoError(financialInstrumentsRW.Initialise())
	return peopleRW, organisationRW, membershipsRW, rolesRW, financialInstrumentsRW
}
开发者ID:Financial-Times,项目名称:public-organisations-api,代码行数:13,代码来源:cypher_test.go


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