本文整理汇总了Golang中reflect.DeepEqual函数的典型用法代码示例。如果您正苦于以下问题:Golang DeepEqual函数的具体用法?Golang DeepEqual怎么用?Golang DeepEqual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DeepEqual函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestClientMassError_json
func TestClientMassError_json(t *testing.T) {
cli, srv := net.Pipe()
go ServeConn(srv)
client := NewClient(cli)
defer client.Close()
for i := len(svcMsg); i < cap(svcMsg); i++ {
svcMsg <- ""
}
defer func() {
for len(svcMsg) > 0 {
<-svcMsg
}
}()
wanterr1 := NewError(-32603, "json: cannot unmarshal number into Go value of type string")
wanterr2 := NewError(-32603, "some other Call failed to unmarshal Reply")
call2 := client.Go("Svc.Msg", []string{"test"}, nil, nil)
var badreply string
err1 := client.Call("Svc.Sum", [2]int{}, &badreply)
if err1 == nil || !reflect.DeepEqual(ServerError(err1), wanterr1) {
t.Errorf("%serr1 = %v, wanterr1 = %v", caller(), err1, wanterr1)
}
<-call2.Done
err2 := call2.Error
if err2 == nil || !reflect.DeepEqual(ServerError(err2), wanterr2) {
t.Errorf("%serr2 = %v, wanterr2 = %v", caller(), err2, wanterr2)
}
}
示例2: TestPathUnmarshalJSON
func TestPathUnmarshalJSON(t *testing.T) {
type in struct {
data string
}
type out struct {
device Path
err error
}
tests := []struct {
in in
out out
}{
{
in: in{data: `"/path"`},
out: out{device: Path("/path")},
},
{
in: in{data: `"bad"`},
out: out{device: Path("bad"), err: ErrPathRelative},
},
}
for i, test := range tests {
var device Path
err := json.Unmarshal([]byte(test.in.data), &device)
if !reflect.DeepEqual(test.out.err, err) {
t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
}
if !reflect.DeepEqual(test.out.device, device) {
t.Errorf("#%d: bad device: want %#v, got %#v", i, test.out.device, device)
}
}
}
示例3: validateClusteringFlags
func validateClusteringFlags(t *testing.T, cfg *config) {
wcfg := newConfig()
wcfg.APUrls = []url.URL{{Scheme: "http", Host: "localhost:8000"}, {Scheme: "https", Host: "localhost:8001"}}
wcfg.ACUrls = []url.URL{{Scheme: "http", Host: "localhost:7000"}, {Scheme: "https", Host: "localhost:7001"}}
wcfg.ClusterState = embed.ClusterStateFlagExisting
wcfg.fallback.Set(fallbackFlagExit)
wcfg.InitialCluster = "0=http://localhost:8000"
wcfg.InitialClusterToken = "etcdtest"
if cfg.ClusterState != wcfg.ClusterState {
t.Errorf("clusterState = %v, want %v", cfg.ClusterState, wcfg.ClusterState)
}
if cfg.fallback.String() != wcfg.fallback.String() {
t.Errorf("fallback = %v, want %v", cfg.fallback, wcfg.fallback)
}
if cfg.InitialCluster != wcfg.InitialCluster {
t.Errorf("initialCluster = %v, want %v", cfg.InitialCluster, wcfg.InitialCluster)
}
if cfg.InitialClusterToken != wcfg.InitialClusterToken {
t.Errorf("initialClusterToken = %v, want %v", cfg.InitialClusterToken, wcfg.InitialClusterToken)
}
if !reflect.DeepEqual(cfg.APUrls, wcfg.APUrls) {
t.Errorf("initial-advertise-peer-urls = %v, want %v", cfg.LPUrls, wcfg.LPUrls)
}
if !reflect.DeepEqual(cfg.ACUrls, wcfg.ACUrls) {
t.Errorf("advertise-client-urls = %v, want %v", cfg.LCUrls, wcfg.LCUrls)
}
}
示例4: Test_runCommand
func Test_runCommand(t *testing.T) {
cmd := &runCommand{}
for _, v := range [][]interface{}{
{"Name", cmd.Name(), "run"},
{"Alias", cmd.Alias(), ""},
{"Short", cmd.Short(), "run the your application"},
{"Usage", cmd.Usage(), "run"},
} {
name, actual, expected := v[0], v[1], v[2]
if !reflect.DeepEqual(actual, expected) {
t.Errorf(".%v expect %v, but %v", name, expected, actual)
}
}
if cmd.flag != nil {
t.Fatalf("Expect nil, but %v", cmd.flag)
}
flags := flag.NewFlagSet("testflags", flag.ExitOnError)
cmd.DefineFlags(flags)
flags.Parse([]string{})
actual, expected := cmd.flag, flags
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
}
示例5: TestArgsPeekMulti
func TestArgsPeekMulti(t *testing.T) {
var a Args
a.Parse("foo=123&bar=121&foo=321&foo=&barz=sdf")
vv := a.PeekMulti("foo")
expectedVV := [][]byte{
[]byte("123"),
[]byte("321"),
[]byte(nil),
}
if !reflect.DeepEqual(vv, expectedVV) {
t.Fatalf("unexpected vv\n%#v\nExpecting\n%#v\n", vv, expectedVV)
}
vv = a.PeekMulti("aaaa")
if len(vv) > 0 {
t.Fatalf("expecting empty result for non-existing key. Got %#v", vv)
}
vv = a.PeekMulti("bar")
expectedVV = [][]byte{[]byte("121")}
if !reflect.DeepEqual(vv, expectedVV) {
t.Fatalf("unexpected vv\n%#v\nExpecting\n%#v\n", vv, expectedVV)
}
}
示例6: TestReverse
func TestReverse(t *testing.T) {
oldAppConfig := appConfig
appConfig = newTestAppConfig()
defer func() {
appConfig = oldAppConfig
}()
actual := Reverse("root")
expected := "/"
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
actual = Reverse("user", 77)
expected = "/user/77"
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
actual = Reverse("date", 2013, 10, 26, "naoina")
expected = "/2013/10/26/user/naoina"
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
for _, v := range []string{"/hoge.png", "hoge.png"} {
actual = Reverse("static", v)
expected = "/static/hoge.png"
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
}
}
示例7: TestCsvPairToRecord
func TestCsvPairToRecord(t *testing.T) {
eRecord := []string{"INVITE", "2daec40c", "548625ac", "[email protected]:0:0:0:0:0:0:0", "200", "OK", "1436454408", "*prepaid", "1001", "1002", "", "3401:2069362475", "2"}
invPr := &UnpairedRecord{Method: "INVITE", Timestamp: time.Date(2015, 7, 9, 15, 6, 48, 0, time.UTC),
Values: []string{"INVITE", "2daec40c", "548625ac", "[email protected]:0:0:0:0:0:0:0", "200", "OK", "1436454408", "*prepaid", "1001", "1002", "", "3401:2069362475"}}
byePr := &UnpairedRecord{Method: "BYE", Timestamp: time.Date(2015, 7, 9, 15, 6, 50, 0, time.UTC),
Values: []string{"BYE", "2daec40c", "548625ac", "[email protected]:0:0:0:0:0:0:0", "200", "OK", "1436454410", "", "", "", "", "3401:2069362475"}}
if rec, err := pairToRecord(invPr, byePr); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eRecord, rec) {
t.Errorf("Expected: %+v, received: %+v", eRecord, rec)
}
if rec, err := pairToRecord(byePr, invPr); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eRecord, rec) {
t.Errorf("Expected: %+v, received: %+v", eRecord, rec)
}
if _, err := pairToRecord(byePr, byePr); err == nil || err.Error() != "MISSING_INVITE" {
t.Error(err)
}
if _, err := pairToRecord(invPr, invPr); err == nil || err.Error() != "MISSING_BYE" {
t.Error(err)
}
byePr.Values = []string{"BYE", "2daec40c", "548625ac", "[email protected]:0:0:0:0:0:0:0", "200", "OK", "1436454410", "", "", "", "3401:2069362475"} // Took one value out
if _, err := pairToRecord(invPr, byePr); err == nil || err.Error() != "INCONSISTENT_VALUES_LENGTH" {
t.Error(err)
}
}
示例8: Eq
func (self *ContainerSpec) Eq(b *ContainerSpec) bool {
// Creation within 1s of each other.
diff := self.CreationTime.Sub(b.CreationTime)
if (diff > time.Second) || (diff < -time.Second) {
return false
}
if self.HasCpu != b.HasCpu {
return false
}
if !reflect.DeepEqual(self.Cpu, b.Cpu) {
return false
}
if self.HasMemory != b.HasMemory {
return false
}
if !reflect.DeepEqual(self.Memory, b.Memory) {
return false
}
if self.HasNetwork != b.HasNetwork {
return false
}
if self.HasFilesystem != b.HasFilesystem {
return false
}
if self.HasDiskIo != b.HasDiskIo {
return false
}
if self.HasCustomMetrics != b.HasCustomMetrics {
return false
}
return true
}
示例9: checkPackagesEqual
// Tests two Packages for equality, checking only those fields that we care
// about in tests. E.g., ignores fields that contain absolute paths
// (for now).
func checkPackagesEqual(t *testing.T, importPath string, exp, actual *Package) {
if exp.ImportPath != actual.ImportPath {
t.Errorf("%s: ImportPath: want %v, got %v", importPath, exp.ImportPath, actual.ImportPath)
}
if exp.Name != actual.Name {
t.Errorf("%s: Name: want %v, got %v", importPath, exp.Name, actual.Name)
}
if exp.Goroot != actual.Goroot {
t.Errorf("%s: Goroot: want %v, got %v", importPath, exp.Goroot, actual.Goroot)
}
if exp.Standard != actual.Standard {
t.Errorf("%s: Standard: want %v, got %v", importPath, exp.Standard, actual.Standard)
}
if !reflect.DeepEqual(exp.Imports, actual.Imports) {
t.Errorf("%s: Imports: want %v, got %v", importPath, exp.Imports, actual.Imports)
}
if !reflect.DeepEqual(exp.Deps, actual.Deps) {
t.Errorf("%s: Deps: want %v, got %v", importPath, exp.Deps, actual.Deps)
}
if !reflect.DeepEqual(exp.DepsNotFound, actual.DepsNotFound) {
t.Errorf("%s: DepsNotFound: want %v, got %v", importPath, exp.DepsNotFound, actual.DepsNotFound)
}
if exp.Incomplete != actual.Incomplete {
t.Errorf("%s: Incomplete: want %v, got %v", importPath, exp.Incomplete, actual.Incomplete)
}
checkPackageErrorsEqual(t, importPath, exp.Error, actual.Error)
if len(exp.DepsErrors) == len(actual.DepsErrors) {
for i, expe := range exp.DepsErrors {
actuale := actual.DepsErrors[i]
checkPackageErrorsEqual(t, importPath, expe, actuale)
}
} else {
t.Errorf("%s: DepsErrors: want len %d (%v), got len %d (%v)", importPath, len(exp.DepsErrors), exp.DepsErrors, len(actual.DepsErrors), actual.DepsErrors)
}
}
示例10: TestPatchQuery
func TestPatchQuery(t *testing.T) {
req, _ := NewRequest("PATCH", "http://www.google.com/search?q=foo&q=bar&both=x&prio=1&empty=not",
strings.NewReader("z=post&both=y&prio=2&empty="))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value")
if q := req.FormValue("q"); q != "foo" {
t.Errorf(`req.FormValue("q") = %q, want "foo"`, q)
}
if z := req.FormValue("z"); z != "post" {
t.Errorf(`req.FormValue("z") = %q, want "post"`, z)
}
if bq, found := req.PostForm["q"]; found {
t.Errorf(`req.PostForm["q"] = %q, want no entry in map`, bq)
}
if bz := req.PostFormValue("z"); bz != "post" {
t.Errorf(`req.PostFormValue("z") = %q, want "post"`, bz)
}
if qs := req.Form["q"]; !reflect.DeepEqual(qs, []string{"foo", "bar"}) {
t.Errorf(`req.Form["q"] = %q, want ["foo", "bar"]`, qs)
}
if both := req.Form["both"]; !reflect.DeepEqual(both, []string{"y", "x"}) {
t.Errorf(`req.Form["both"] = %q, want ["y", "x"]`, both)
}
if prio := req.FormValue("prio"); prio != "2" {
t.Errorf(`req.FormValue("prio") = %q, want "2" (from body)`, prio)
}
if empty := req.FormValue("empty"); empty != "" {
t.Errorf(`req.FormValue("empty") = %q, want "" (from body)`, empty)
}
}
示例11: TestPoolPubSubCleanup
func TestPoolPubSubCleanup(t *testing.T) {
d := poolDialer{t: t}
p := &redis.Pool{
MaxIdle: 2,
MaxActive: 2,
Dial: d.dial,
}
defer p.Close()
c := p.Get()
c.Send("SUBSCRIBE", "x")
c.Close()
want := []string{"SUBSCRIBE", "UNSUBSCRIBE", "PUNSUBSCRIBE", "ECHO"}
if !reflect.DeepEqual(d.commands, want) {
t.Errorf("got commands %v, want %v", d.commands, want)
}
d.commands = nil
c = p.Get()
c.Send("PSUBSCRIBE", "x*")
c.Close()
want = []string{"PSUBSCRIBE", "UNSUBSCRIBE", "PUNSUBSCRIBE", "ECHO"}
if !reflect.DeepEqual(d.commands, want) {
t.Errorf("got commands %v, want %v", d.commands, want)
}
d.commands = nil
}
示例12: TestCollector
func TestCollector(t *testing.T) {
window := time.Millisecond
c := xfer.NewCollector(window)
r1 := report.MakeReport()
r1.Endpoint.NodeMetadatas["foo"] = report.MakeNodeMetadata()
r2 := report.MakeReport()
r2.Endpoint.NodeMetadatas["bar"] = report.MakeNodeMetadata()
if want, have := report.MakeReport(), c.Report(); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
c.Add(r1)
if want, have := r1, c.Report(); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
c.Add(r2)
merged := report.MakeReport()
merged = merged.Merge(r1)
merged = merged.Merge(r2)
if want, have := merged, c.Report(); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
示例13: TestHTTPClusterClientSyncFail
func TestHTTPClusterClientSyncFail(t *testing.T) {
cf := newStaticHTTPClientFactory([]staticHTTPResponse{
{err: errors.New("fail!")},
})
hc := &httpClusterClient{
clientFactory: cf,
rand: rand.New(rand.NewSource(0)),
}
err := hc.SetEndpoints([]string{"http://127.0.0.1:2379"})
if err != nil {
t.Fatalf("unexpected error during setup: %#v", err)
}
want := []string{"http://127.0.0.1:2379"}
got := hc.Endpoints()
if !reflect.DeepEqual(want, got) {
t.Fatalf("incorrect endpoints: want=%#v got=%#v", want, got)
}
err = hc.Sync(context.Background())
if err == nil {
t.Fatalf("got nil error during Sync")
}
got = hc.Endpoints()
if !reflect.DeepEqual(want, got) {
t.Fatalf("incorrect endpoints after failed Sync: want=%#v got=%#v", want, got)
}
}
示例14: TestMapFilesToFilesystems
func TestMapFilesToFilesystems(t *testing.T) {
type in struct {
config types.Config
}
type out struct {
files map[types.Filesystem][]types.File
err error
}
tests := []struct {
in in
out out
}{
{
in: in{config: types.Config{}},
out: out{files: map[types.Filesystem][]types.File{}},
},
{
in: in{config: types.Config{Storage: types.Storage{Files: []types.File{{Filesystem: "foo"}}}}},
out: out{err: ErrFilesystemUndefined},
},
{
in: in{config: types.Config{Storage: types.Storage{
Filesystems: []types.Filesystem{{Name: "fs1"}},
Files: []types.File{{Filesystem: "fs1", Path: "/foo"}, {Filesystem: "fs1", Path: "/bar"}},
}}},
out: out{files: map[types.Filesystem][]types.File{types.Filesystem{Name: "fs1"}: {{Filesystem: "fs1", Path: "/foo"}, {Filesystem: "fs1", Path: "/bar"}}}},
},
{
in: in{config: types.Config{Storage: types.Storage{
Filesystems: []types.Filesystem{{Name: "fs1", Path: "/fs1"}, {Name: "fs2", Path: "/fs2"}},
Files: []types.File{{Filesystem: "fs1", Path: "/foo"}, {Filesystem: "fs2", Path: "/bar"}},
}}},
out: out{files: map[types.Filesystem][]types.File{
types.Filesystem{Name: "fs1", Path: "/fs1"}: {{Filesystem: "fs1", Path: "/foo"}},
types.Filesystem{Name: "fs2", Path: "/fs2"}: {{Filesystem: "fs2", Path: "/bar"}},
}},
},
{
in: in{config: types.Config{Storage: types.Storage{
Filesystems: []types.Filesystem{{Name: "fs1"}, {Name: "fs1", Path: "/fs1"}},
Files: []types.File{{Filesystem: "fs1", Path: "/foo"}, {Filesystem: "fs1", Path: "/bar"}},
}}},
out: out{files: map[types.Filesystem][]types.File{
types.Filesystem{Name: "fs1", Path: "/fs1"}: {{Filesystem: "fs1", Path: "/foo"}, {Filesystem: "fs1", Path: "/bar"}},
}},
},
}
for i, test := range tests {
logger := log.New()
files, err := stage{Util: util.Util{Logger: &logger}}.mapFilesToFilesystems(test.in.config)
if !reflect.DeepEqual(test.out.err, err) {
t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
}
if !reflect.DeepEqual(test.out.files, files) {
t.Errorf("#%d: bad map: want %#v, got %#v", i, test.out.files, files)
}
}
}
示例15: TestEncodeDecode
func TestEncodeDecode(t *testing.T) {
arg := &RegisterRequest{
Datacenter: "foo",
Node: "bar",
Address: "baz",
Service: &NodeService{
Service: "test",
Address: "127.0.0.2",
},
}
buf, err := Encode(RegisterRequestType, arg)
if err != nil {
t.Fatalf("err: %v", err)
}
var out RegisterRequest
err = Decode(buf[1:], &out)
if err != nil {
t.Fatalf("err: %v", err)
}
if !reflect.DeepEqual(arg.Service, out.Service) {
t.Fatalf("bad: %#v %#v", arg.Service, out.Service)
}
if !reflect.DeepEqual(arg, &out) {
t.Fatalf("bad: %#v %#v", arg, out)
}
}