本文整理汇总了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
}
示例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)
}
示例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
}
示例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")
}
}
示例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")
}
}
示例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)
}
示例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)
}
示例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")
}
}
示例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
}
示例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)
}
}
}
示例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"))
}
示例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
}
示例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)
}
}
}
}
示例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
}
示例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
}