本文整理汇总了Golang中github.com/stretchr/testify/assert.ObjectsAreEqual函数的典型用法代码示例。如果您正苦于以下问题:Golang ObjectsAreEqual函数的具体用法?Golang ObjectsAreEqual怎么用?Golang ObjectsAreEqual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectsAreEqual函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Diff
// Diff gets a string describing the differences between the arguments
// and the specified objects.
//
// Returns the diff string and number of differences found.
func (args Arguments) Diff(objects []interface{}) (string, int) {
var output string = "\n"
var differences int
var maxArgCount int = len(args)
if len(objects) > maxArgCount {
maxArgCount = len(objects)
}
for i := 0; i < maxArgCount; i++ {
var actual, expected interface{}
if len(objects) <= i {
actual = "(Missing)"
} else {
actual = objects[i]
}
if len(args) <= i {
expected = "(Missing)"
} else {
expected = args[i]
}
if reflect.TypeOf(expected) == reflect.TypeOf((*AnythingOfTypeArgument)(nil)).Elem() {
// type checking
if reflect.TypeOf(actual).Name() != string(expected.(AnythingOfTypeArgument)) && reflect.TypeOf(actual).String() != string(expected.(AnythingOfTypeArgument)) {
// not match
differences++
output = fmt.Sprintf("%s\t%d: \u274C type %s != type %s - %s\n", output, i, expected, reflect.TypeOf(actual).Name(), actual)
}
} else {
// normal checking
if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) {
// match
output = fmt.Sprintf("%s\t%d: \u2705 %s == %s\n", output, i, actual, expected)
} else {
// not match
differences++
output = fmt.Sprintf("%s\t%d: \u274C %s != %s\n", output, i, actual, expected)
}
}
}
if differences == 0 {
return "No differences.", differences
}
return output, differences
}
示例2: TestSortableIdentifierSlice
func TestSortableIdentifierSlice(t *testing.T) {
e1 := MyEntity1{}
e1.BasicEntity = NewBasic()
e2 := MyEntity1{}
e2.BasicEntity = NewBasic()
var entities IdentifierSlice = []Identifier{e2, e1}
sort.Sort(entities)
assert.ObjectsAreEqual(e1, entities[0])
assert.ObjectsAreEqual(e2, entities[1])
}
示例3: TestGetModelsWithKeys
func (suite *datastoreTestSuite) TestGetModelsWithKeys() {
srcModels := loadTestData(suite.GAEContext)
destModels := make([]models.Model, 5)
destTest := make([]*testModel, 5)
var (
key *datastore.Key
err error
)
for index, _ := range destTest {
key, err = srcModels[index].Key()
destTest[index] = new(testModel)
destTest[index].SetKey(key)
destModels[index] = destTest[index]
}
err = GetModelsWithKeys(suite.GAEContext, destModels)
assert.Nil(suite.T, err, "GetModelsWithKeys shouldn't error")
for index, model := range destTest {
assert.ObjectsAreEqual(model, srcModels[index])
key, err = model.Key()
assert.Nil(suite.T, err, "Models should have keys after running Get")
assert.NotNil(suite.T, key, "Models should have keys after running Get")
}
}
示例4: parseTcpRequestResponse
// parseTcpRequestResponse parses a request then a response packet and validates
// the published result.
func parseTcpRequestResponse(t testing.TB, dns *Dns, q DnsTestMessage) {
var private protos.ProtocolData
packet := newPacket(forward, q.request)
tcptuple := testTcpTuple()
private = dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
packet = newPacket(reverse, q.response)
dns.Parse(packet, tcptuple, tcp.TcpDirectionReverse, private)
assert.Empty(t, dns.transactions.Size(), "There should be no transactions.")
m := expectResult(t, dns)
assert.Equal(t, "tcp", mapValue(t, m, "transport"))
assert.Equal(t, len(q.request), mapValue(t, m, "bytes_in"))
assert.Equal(t, len(q.response), mapValue(t, m, "bytes_out"))
assert.NotNil(t, mapValue(t, m, "responsetime"))
if assert.ObjectsAreEqual("NOERROR", mapValue(t, m, "dns.response_code")) {
assert.Equal(t, common.OK_STATUS, mapValue(t, m, "status"))
} else {
assert.Equal(t, common.ERROR_STATUS, mapValue(t, m, "status"))
}
assert.Nil(t, mapValue(t, m, "notes"))
assertMapStrData(t, m, q)
}
示例5: assertHasLine
func assertHasLine(t *testing.T, tr Transaction, expected Line) {
for _, l := range tr.Lines {
if assert.ObjectsAreEqual(expected, l) {
return
}
}
assert.Fail(t, "line not found", expected.String())
}
示例6: TestGetDocument
func TestGetDocument(t *testing.T) {
es := newEsTestClient(t).recreateIndex(estestIndex)
id := "1"
doc := map[string]interface{}{"name": id}
es.putDocument(estestIndex, estestType, id, "", doc)
returned := es.getDocumentMap(estestIndex, estestType, id, "")
assert.ObjectsAreEqual(doc, returned)
}
示例7: TestMarshalRoundtrip
func (suite *ConfigSuite) TestMarshalRoundtrip() {
configBytes, err := yaml.Marshal(suite.expectedConfig)
assert.Nil(suite.T(), err)
var config Configuration
err = yaml.Unmarshal(configBytes, &config)
assert.Nil(suite.T(), err)
assert.True(suite.T(), assert.ObjectsAreEqual(config, suite.expectedConfig))
}
示例8: Diff
// Diff returns the values in v that differ from the values in other.
// ISO 31-11: v \ other
func (v Values) Diff(other Values) Values {
diff := Values{}
for key, value := range v {
if !assert.ObjectsAreEqual(value, other[key]) {
diff[key] = value
}
}
return diff
}
示例9: TestCommandClone
func TestCommandClone(t *testing.T) {
nilCmds := Commands(nil)
assert.Equal(t, nilCmds.Clone(), Commands(nil))
manyCmds := Commands{
Command("1"),
Command("2"),
}
assert.True(t,
assert.ObjectsAreEqual(manyCmds.Clone(), manyCmds),
)
}
示例10: TestGetModel
func (suite *datastoreTestSuite) TestGetModel() {
models := loadTestData(suite.GAEContext)
src := models[0]
key, err := src.Key()
assert.NotNil(suite.T, key, "The src model should have its key set")
dest := new(testModel)
err = GetModel(suite.GAEContext, key, dest)
assert.Nil(suite.T, err, "GetModel shouldn't return an error")
assert.ObjectsAreEqual(src, dest)
}
示例11: TestMultipleEncodingDecodeEvent
func TestMultipleEncodingDecodeEvent(t *testing.T) {
cases := []struct {
ev *sse
}{
{ev},
{newSSEEvent("102", "DUP")},
{newSSEEvent("103", "FUN")},
}
r, w := io.Pipe()
enc := newEncoder(w)
assert.NotNil(t, enc)
dec := newDecoder(r)
assert.NotNil(t, dec)
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
defer w.Close()
for _, tc := range cases {
err := enc.Encode(tc.ev)
assert.Nil(t, err)
}
}()
go func() {
defer wg.Done()
defer r.Close()
for {
inputEv, err := dec.Decode()
if err == io.EOF {
break
}
exists := false
for _, tc := range cases {
exists = exists || assert.ObjectsAreEqual(tc.ev, inputEv)
}
assert.NoError(t, err)
assert.True(t, exists)
}
}()
wg.Wait()
}
示例12: SQL
// SQL tests that the given Compiles instance matches the expected string for
// the current dialect.
func (t *tester) SQL(expect string, stmt Compiles, ps ...interface{}) {
// Get caller information in case of failure
caller := callerInfo()
// Start a new parameters instance
params := Params()
// Compile the given stmt with the tester's dialect
actual, err := stmt.Compile(t.dialect, params)
if err != nil {
t.t.Errorf("%s: unexpected error from Compile(): %s", caller, err)
return
}
if expect != actual {
t.t.Errorf(
"%s: unexpected SQL from Compile(): expect %s, got %s",
caller,
expect,
actual,
)
}
// Test that the parameters are equal
if len(*params) != len(ps) {
t.t.Errorf(
"%s: unexpected number of parameters for %s: expect %d, got %d",
caller,
actual,
len(ps),
len(*params),
)
return
}
// Examine individual parameters for equality
for i, param := range *params {
if !assert.ObjectsAreEqual(ps[i], param) {
t.t.Errorf(
"%s: unequal parameters at index %d: expect %#v, got %#v",
caller,
i,
ps[i],
param,
)
}
}
}
示例13: parseUDPRequestResponse
// parseUdpRequestResponse parses a request then a response packet and validates
// the published result.
func parseUDPRequestResponse(t testing.TB, dns *dnsPlugin, q dnsTestMessage) {
packet := newPacket(forward, q.request)
dns.ParseUDP(packet)
packet = newPacket(reverse, q.response)
dns.ParseUDP(packet)
assert.Empty(t, dns.transactions.Size(), "There should be no transactions.")
m := expectResult(t, dns)
assert.Equal(t, "udp", mapValue(t, m, "transport"))
assert.Equal(t, len(q.request), mapValue(t, m, "bytes_in"))
assert.Equal(t, len(q.response), mapValue(t, m, "bytes_out"))
assert.NotNil(t, mapValue(t, m, "responsetime"))
if assert.ObjectsAreEqual("NOERROR", mapValue(t, m, "dns.response_code")) {
assert.Equal(t, common.OK_STATUS, mapValue(t, m, "status"))
} else {
assert.Equal(t, common.ERROR_STATUS, mapValue(t, m, "status"))
}
assert.Nil(t, mapValue(t, m, "notes"))
assertMapStrData(t, m, q)
}
示例14: TestParseTcpSplitResponse
// Verify that the split lone request packet is parsed.
func TestParseTcpSplitResponse(t *testing.T) {
dns := newDns(testing.Verbose())
tcpQuery := elasticATcp
q := tcpQuery.request
r0 := tcpQuery.response[:10]
r1 := tcpQuery.response[10:]
tcptuple := testTcpTuple()
private := protos.ProtocolData(new(dnsPrivateData))
packet := newPacket(forward, q)
private = dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
assert.Equal(t, 1, dns.transactions.Size(), "There should be one transaction.")
packet = newPacket(reverse, r0)
private = dns.Parse(packet, tcptuple, tcp.TcpDirectionReverse, private)
assert.Equal(t, 1, dns.transactions.Size(), "There should be one transaction.")
packet = newPacket(reverse, r1)
private = dns.Parse(packet, tcptuple, tcp.TcpDirectionReverse, private)
assert.Empty(t, dns.transactions.Size(), "There should be no transaction.")
m := expectResult(t, dns)
assert.Equal(t, "tcp", mapValue(t, m, "transport"))
assert.Equal(t, len(tcpQuery.request), mapValue(t, m, "bytes_in"))
assert.Equal(t, len(tcpQuery.response), mapValue(t, m, "bytes_out"))
assert.NotNil(t, mapValue(t, m, "responsetime"))
if assert.ObjectsAreEqual("NOERROR", mapValue(t, m, "dns.response_code")) {
assert.Equal(t, common.OK_STATUS, mapValue(t, m, "status"))
} else {
assert.Equal(t, common.ERROR_STATUS, mapValue(t, m, "status"))
}
assert.Nil(t, mapValue(t, m, "notes"))
assertMapStrData(t, m, tcpQuery)
}
示例15: TestNewClient_httpClient
func TestNewClient_httpClient(t *testing.T) {
transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
httpClient := &http.Client{Transport: transport}
client := NewClient(httpClient, testClientToken)
assert.ObjectsAreEqual(httpClient, client.Client)
}