本文整理汇总了Golang中github.com/stretchr/testify/assert.Assertions.Equal方法的典型用法代码示例。如果您正苦于以下问题:Golang Assertions.Equal方法的具体用法?Golang Assertions.Equal怎么用?Golang Assertions.Equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/stretchr/testify/assert.Assertions
的用法示例。
在下文中一共展示了Assertions.Equal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例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: 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")
}
}
示例4: 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")
}
}
示例5: 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
}
示例6: 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)
}
}
}
示例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
}
示例8: mockGetStateNodes
func mockGetStateNodes(assert *assert.Assertions, data []byte) *Client {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal("GET", r.Method)
assert.Equal("/v1/state/nodes", r.URL.Path)
w.Write(data)
}))
host, port, err := getHostAndPortFromTestServer(ts)
assert.NoError(err)
c := newFlockerTestClient(host, port)
return c
}
示例9: assertIndicator
// Assert Indicator type
func assertIndicator(assert *assert.Assertions, indicator *Indicator) {
assert.Equal("test", indicator.Name)
assert.Equal("test", indicator.Src)
assert.Equal("test", indicator.Identifier)
assert.EqualValues(123, indicator.Delayed)
assert.Equal(true, indicator.OnlyEod)
assert.Equal("test", indicator.Open)
assert.Equal("test", indicator.Close)
assert.Equal("test", indicator.Country)
assert.Equal("test", indicator.Type)
assert.Equal("test", indicator.Region)
assert.EqualValues(123, indicator.InstrumentId)
}
示例10: checkRelationship
func checkRelationship(assert *assert.Assertions, contentID string, platformVersion string) {
countQuery := `Match (t:Thing {uuid: {contentID}})-[r {lifecycle: {lifecycle}}]-(x) return count(r) as c`
results := []struct {
Count int `json:"c"`
}{}
qs := &neoism.CypherQuery{
Statement: countQuery,
Parameters: neoism.Props{"contentID": contentID, "lifecycle": "annotations-" + platformVersion},
Result: &results,
}
err := annotationsDriver.conn.CypherBatch([]*neoism.CypherQuery{qs})
assert.NoError(err)
assert.Equal(1, len(results), "More results found than expected!")
assert.Equal(1, results[0].Count, "No Relationship with Lifecycle found!")
}
示例11: testMapOrder
func testMapOrder(assert *assert.Assertions, keyType, valueType Type, tuples []Value, expectOrdering []Value) {
mapTr := MakeCompoundType(MapKind, keyType, valueType)
m := NewTypedMap(mapTr, tuples...)
i := 0
m.IterAll(func(key, value Value) {
assert.Equal(expectOrdering[i].Ref().String(), key.Ref().String())
i++
})
}
示例12: testByteRange
func testByteRange(assert *assert.Assertions, offset, length int64, expect io.ReadSeeker, actual io.ReadSeeker) {
n, err := expect.Seek(offset, 0)
assert.Equal(offset, n)
assert.NoError(err)
b1 := &bytes.Buffer{}
n, err = io.CopyN(b1, expect, length)
assert.Equal(length, n)
assert.NoError(err)
n, err = actual.Seek(offset, 0)
assert.Equal(offset, n)
assert.NoError(err)
b2 := &bytes.Buffer{}
n, err = io.CopyN(b2, actual, length)
assert.Equal(length, n)
assert.NoError(err)
assert.Equal(b1.Bytes(), b2.Bytes())
}
示例13: 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)
}
}
示例14: 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)
}
}
示例15: 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
}