本文整理汇总了Golang中github.com/d4l3k/messagediff.PrettyDiff函数的典型用法代码示例。如果您正苦于以下问题:Golang PrettyDiff函数的具体用法?Golang PrettyDiff怎么用?Golang PrettyDiff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PrettyDiff函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSortByAge
func TestSortByAge(t *testing.T) {
q := newJobQueue()
q.Push("f1", 0, 20)
q.Push("f2", 0, 40)
q.Push("f3", 0, 30)
q.Push("f4", 0, 10)
q.SortOldestFirst()
_, actual := q.Jobs()
if l := len(actual); l != 4 {
t.Fatalf("Weird length %d returned from Jobs()", l)
}
expected := []string{"f4", "f1", "f3", "f2"}
if diff, equal := messagediff.PrettyDiff(expected, actual); !equal {
t.Errorf("SortOldestFirst() diff:\n%s", diff)
}
q.SortNewestFirst()
_, actual = q.Jobs()
if l := len(actual); l != 4 {
t.Fatalf("Weird length %d returned from Jobs()", l)
}
expected = []string{"f2", "f3", "f1", "f4"}
if diff, equal := messagediff.PrettyDiff(expected, actual); !equal {
t.Errorf("SortNewestFirst() diff:\n%s", diff)
}
}
开发者ID:WeavingCode,项目名称:syncthing,代码行数:31,代码来源:queue_test.go
示例2: TestSortBySize
func TestSortBySize(t *testing.T) {
q := newJobQueue()
q.Push("f1", 20, time.Time{})
q.Push("f2", 40, time.Time{})
q.Push("f3", 30, time.Time{})
q.Push("f4", 10, time.Time{})
q.SortSmallestFirst()
_, actual := q.Jobs()
if l := len(actual); l != 4 {
t.Fatalf("Weird length %d returned from Jobs()", l)
}
expected := []string{"f4", "f1", "f3", "f2"}
if diff, equal := messagediff.PrettyDiff(expected, actual); !equal {
t.Errorf("SortSmallestFirst() diff:\n%s", diff)
}
q.SortLargestFirst()
_, actual = q.Jobs()
if l := len(actual); l != 4 {
t.Fatalf("Weird length %d returned from Jobs()", l)
}
expected = []string{"f2", "f3", "f1", "f4"}
if diff, equal := messagediff.PrettyDiff(expected, actual); !equal {
t.Errorf("SortLargestFirst() diff:\n%s", diff)
}
}
开发者ID:letiemble,项目名称:syncthing,代码行数:31,代码来源:queue_test.go
示例3: TestListDropFolder
func TestListDropFolder(t *testing.T) {
ldb := db.OpenMemory()
s0 := db.NewFileSet("test0", ldb)
local1 := []protocol.FileInfo{
{Name: "a", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
{Name: "b", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
{Name: "c", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
}
s0.Replace(protocol.LocalDeviceID, local1)
s1 := db.NewFileSet("test1", ldb)
local2 := []protocol.FileInfo{
{Name: "d", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1002}}}},
{Name: "e", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1002}}}},
{Name: "f", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1002}}}},
}
s1.Replace(remoteDevice0, local2)
// Check that we have both folders and their data is in the global list
expectedFolderList := []string{"test0", "test1"}
actualFolderList := ldb.ListFolders()
if diff, equal := messagediff.PrettyDiff(expectedFolderList, actualFolderList); !equal {
t.Fatalf("FolderList mismatch. Diff:\n%s", diff)
}
if l := len(globalList(s0)); l != 3 {
t.Errorf("Incorrect global length %d != 3 for s0", l)
}
if l := len(globalList(s1)); l != 3 {
t.Errorf("Incorrect global length %d != 3 for s1", l)
}
// Drop one of them and check that it's gone.
db.DropFolder(ldb, "test1")
expectedFolderList = []string{"test0"}
actualFolderList = ldb.ListFolders()
if diff, equal := messagediff.PrettyDiff(expectedFolderList, actualFolderList); !equal {
t.Fatalf("FolderList mismatch. Diff:\n%s", diff)
}
if l := len(globalList(s0)); l != 3 {
t.Errorf("Incorrect global length %d != 3 for s0", l)
}
if l := len(globalList(s1)); l != 0 {
t.Errorf("Incorrect global length %d != 0 for s1", l)
}
}
开发者ID:letiemble,项目名称:syncthing,代码行数:49,代码来源:set_test.go
示例4: TestKeyspaceComplement
func TestKeyspaceComplement(t *testing.T) {
t.Parallel()
testData := []struct {
a, want *Keyspace
}{
{
&Keyspace{1, 10},
&Keyspace{10, 1},
},
{
nil,
&Keyspace{1, 0},
},
{
&Keyspace{1, 0},
nil,
},
}
for i, td := range testData {
out := td.a.Complement()
if diff, equal := messagediff.PrettyDiff(td.want, out); !equal {
t.Errorf("%d. %+v.Complement() = %+v not %+v\n%s", i, td.a, out, td.want, diff)
}
}
}
开发者ID:BobbWu,项目名称:degdb,代码行数:26,代码来源:keyspace_test.go
示例5: ExampleAtom
func ExampleAtom() {
got := data2()
want := data1()
diff, equal := messagediff.PrettyDiff(want, got)
fmt.Printf("%v %s", equal, diff)
// Output: false modified: [0].FirstChild.NextSibling.Attr = " baz"
}
开发者ID:brgmnn,项目名称:syncthing,代码行数:7,代码来源:atom_test.go
示例6: TestDeviceAddressesStatic
func TestDeviceAddressesStatic(t *testing.T) {
name, _ := os.Hostname()
expected := map[protocol.DeviceID]DeviceConfiguration{
device1: {
DeviceID: device1,
Addresses: []string{"tcp://192.0.2.1", "tcp://192.0.2.2"},
},
device2: {
DeviceID: device2,
Addresses: []string{"tcp://192.0.2.3:6070", "tcp://[2001:db8::42]:4242"},
},
device3: {
DeviceID: device3,
Addresses: []string{"tcp://[2001:db8::44]:4444", "tcp://192.0.2.4:6090"},
},
device4: {
DeviceID: device4,
Name: name, // Set when auto created
Addresses: []string{"dynamic"},
Compression: protocol.CompressMetadata,
},
}
cfg, err := Load("testdata/deviceaddressesstatic.xml", device4)
if err != nil {
t.Error(err)
}
actual := cfg.Devices()
if diff, equal := messagediff.PrettyDiff(expected, actual); !equal {
t.Errorf("Devices differ. Diff:\n%s", diff)
}
}
开发者ID:kluppy,项目名称:syncthing,代码行数:33,代码来源:config_test.go
示例7: TestParse
func TestParse(t *testing.T) {
testData := []struct {
in string
want []*protocol.Triple
}{{
`[{"subj":"foo", "pred":"bar", "obj":"moo"}, {}]`,
[]*protocol.Triple{
{
Subj: "foo",
Pred: "bar",
Obj: "moo",
},
{},
},
}}
for i, td := range testData {
out, err := Parse(td.in)
if err != nil {
t.Error(err)
}
if diff, eq := messagediff.PrettyDiff(td.want, out); !eq {
t.Errorf("%d. Parse(%#v) = %#v\ndiff %s", i, td.in, out, diff)
}
}
}
开发者ID:nunb,项目名称:degdb,代码行数:25,代码来源:query_test.go
示例8: TestDirNames
func TestDirNames(t *testing.T) {
names := dirNames("testdata")
expected := []string{"default", "foo", "testfolder"}
if diff, equal := messagediff.PrettyDiff(expected, names); !equal {
t.Errorf("Unexpected dirNames return: %#v\n%s", names, diff)
}
}
开发者ID:letiemble,项目名称:syncthing,代码行数:7,代码来源:gui_test.go
示例9: TestWalk
func TestWalk(t *testing.T) {
ignores := ignore.New(false)
err := ignores.Load("testdata/.stignore")
if err != nil {
t.Fatal(err)
}
t.Log(ignores)
fchan, err := Walk(Config{
Dir: "testdata",
BlockSize: 128 * 1024,
Matcher: ignores,
Hashers: 2,
})
if err != nil {
t.Fatal(err)
}
var tmp []protocol.FileInfo
for f := range fchan {
tmp = append(tmp, f)
}
sort.Sort(fileList(tmp))
files := fileList(tmp).testfiles()
if diff, equal := messagediff.PrettyDiff(testdata, files); !equal {
t.Errorf("Walk returned unexpected data. Diff:\n%s", diff)
}
}
开发者ID:carriercomm,项目名称:syncthing,代码行数:30,代码来源:walk_test.go
示例10: TestShardQueryByHash
func TestShardQueryByHash(t *testing.T) {
t.Parallel()
testData := []struct {
step *protocol.ArrayOp
want map[uint64]*protocol.ArrayOp
}{
{
nil,
nil,
},
{
&protocol.ArrayOp{
Triples: []*protocol.Triple{
{Subj: "foo"},
{Subj: "bar"},
},
},
map[uint64]*protocol.ArrayOp{
0xe271865701f54561: {
Triples: []*protocol.Triple{
{Subj: "foo"},
{Subj: "bar"},
},
},
0x923658dbfd3ae604: {
Triples: []*protocol.Triple{
{Subj: "foo"},
{Subj: "bar"},
},
},
},
},
{
&protocol.ArrayOp{
Triples: []*protocol.Triple{
{Pred: "bar"},
},
},
map[uint64]*protocol.ArrayOp{
0: {
Triples: []*protocol.Triple{
{Pred: "bar"},
},
},
},
},
}
for i, td := range testData {
out := ShardQueryByHash(td.step)
if diff, eq := messagediff.PrettyDiff(td.want, out); !eq {
t.Errorf("%d. Parse(%#v) = %#v\ndiff %s", i, td.step, out, diff)
}
}
}
开发者ID:nonempty,项目名称:degdb,代码行数:55,代码来源:query_test.go
示例11: TestStaggeredVersioningVersionCount
func TestStaggeredVersioningVersionCount(t *testing.T) {
/* Default settings:
{30, 3600}, // first hour -> 30 sec between versions
{3600, 86400}, // next day -> 1 h between versions
{86400, 592000}, // next 30 days -> 1 day between versions
{604800, maxAge}, // next year -> 1 week between versions
*/
loc, _ := time.LoadLocation("Local")
now, _ := time.ParseInLocation(TimeFormat, "20160415-140000", loc)
files := []string{
// 14:00:00 is "now"
"test~20160415-140000", // 0 seconds ago
"test~20160415-135959", // 1 second ago
"test~20160415-135958", // 2 seconds ago
"test~20160415-135900", // 1 minute ago
"test~20160415-135859", // 1 minute 1 second ago
"test~20160415-135830", // 1 minute 30 seconds ago
"test~20160415-135829", // 1 minute 31 seconds ago
"test~20160415-135700", // 3 minutes ago
"test~20160415-135630", // 3 minutes 30 seconds ago
"test~20160415-133000", // 30 minutes ago
"test~20160415-132900", // 31 minutes ago
"test~20160415-132500", // 35 minutes ago
"test~20160415-132000", // 40 minutes ago
"test~20160415-130000", // 60 minutes ago
"test~20160415-124000", // 80 minutes ago
"test~20160415-122000", // 100 minutes ago
"test~20160415-110000", // 120 minutes ago
}
sort.Strings(files)
delete := []string{
"test~20160415-140000", // 0 seconds ago
"test~20160415-135959", // 1 second ago
"test~20160415-135900", // 1 minute ago
"test~20160415-135830", // 1 minute 30 second ago
"test~20160415-130000", // 60 minutes ago
"test~20160415-124000", // 80 minutes ago
}
sort.Strings(delete)
os.MkdirAll("testdata/.stversions", 0755)
defer os.RemoveAll("testdata")
testCleanDone = make(chan struct{})
v := NewStaggered("", "testdata", map[string]string{"maxAge": strconv.Itoa(365 * 86400)}).(Staggered)
<-testCleanDone
rem := v.toRemove(files, now)
if diff, equal := messagediff.PrettyDiff(delete, rem); !equal {
t.Errorf("Incorrect deleted files; got %v, expected %v\n%v", rem, delete, diff)
}
}
开发者ID:letiemble,项目名称:syncthing,代码行数:55,代码来源:staggered_test.go
示例12: TestNoListenAddresses
func TestNoListenAddresses(t *testing.T) {
cfg, err := Load("testdata/nolistenaddress.xml", device1)
if err != nil {
t.Error(err)
}
expected := []string{""}
actual := cfg.Options().ListenAddresses
if diff, equal := messagediff.PrettyDiff(expected, actual); !equal {
t.Errorf("Unexpected ListenAddresses. Diff:\n%s", diff)
}
}
开发者ID:kluppy,项目名称:syncthing,代码行数:12,代码来源:config_test.go
示例13: TestQuery
func TestQuery(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
nodes := launchSwarm(5, t)
defer killSwarm(nodes)
primary := nodes[0]
triples := protocol.CloneTriples(testTriples)
if err := primary.signAndInsertTriples(triples, primary.crypto); err != nil {
t.Fatal(err)
}
testData := []struct {
query *protocol.QueryRequest
want []*protocol.Triple
}{
{
&protocol.QueryRequest{
Type: protocol.BASIC,
Steps: []*protocol.ArrayOp{{
Triples: []*protocol.Triple{{
Subj: "/m/02mjmr",
}},
}},
},
[]*protocol.Triple{
{
Subj: "/m/02mjmr",
Pred: "/type/object/name",
Obj: "Barack Obama",
},
{
Subj: "/m/02mjmr",
Pred: "/type/object/type",
Obj: "/people/person",
},
},
},
}
for i, td := range testData {
trips, err := primary.ExecuteQuery(td.query)
if err != nil {
t.Error(err)
}
trips = stripCreated(stripSigning(trips))
if diff, equal := messagediff.PrettyDiff(td.want, trips); !equal {
t.Errorf("%d. s.ExecuteQuery(%+v) = %+v\n%s", i, td.query, trips, diff)
}
}
}
开发者ID:BobbWu,项目名称:degdb,代码行数:53,代码来源:query_test.go
示例14: TestBringToFront
func TestBringToFront(t *testing.T) {
q := newJobQueue()
q.Push("f1", 0, 0)
q.Push("f2", 0, 0)
q.Push("f3", 0, 0)
q.Push("f4", 0, 0)
_, queued := q.Jobs()
if diff, equal := messagediff.PrettyDiff([]string{"f1", "f2", "f3", "f4"}, queued); !equal {
t.Errorf("Order does not match. Diff:\n%s", diff)
}
q.BringToFront("f1") // corner case: does nothing
_, queued = q.Jobs()
if diff, equal := messagediff.PrettyDiff([]string{"f1", "f2", "f3", "f4"}, queued); !equal {
t.Errorf("Order does not match. Diff:\n%s", diff)
}
q.BringToFront("f3")
_, queued = q.Jobs()
if diff, equal := messagediff.PrettyDiff([]string{"f3", "f1", "f2", "f4"}, queued); !equal {
t.Errorf("Order does not match. Diff:\n%s", diff)
}
q.BringToFront("f2")
_, queued = q.Jobs()
if diff, equal := messagediff.PrettyDiff([]string{"f2", "f3", "f1", "f4"}, queued); !equal {
t.Errorf("Order does not match. Diff:\n%s", diff)
}
q.BringToFront("f4") // corner case: last element
_, queued = q.Jobs()
if diff, equal := messagediff.PrettyDiff([]string{"f4", "f2", "f3", "f1"}, queued); !equal {
t.Errorf("Order does not match. Diff:\n%s", diff)
}
}
开发者ID:WeavingCode,项目名称:syncthing,代码行数:40,代码来源:queue_test.go
示例15: TestSortTriples
func TestSortTriples(t *testing.T) {
t.Parallel()
testData := []struct {
a, want []*Triple
}{
{
[]*Triple{
{
Subj: "b",
},
{
Subj: "c",
},
{
Subj: "a",
Pred: "b",
},
{
Subj: "a",
Pred: "a",
},
},
[]*Triple{
{
Subj: "a",
Pred: "a",
},
{
Subj: "a",
Pred: "b",
},
{
Subj: "b",
},
{
Subj: "c",
},
},
},
}
for i, td := range testData {
out := CloneTriples(td.a)
SortTriples(out)
if diff, equal := messagediff.PrettyDiff(td.want, out); !equal {
t.Errorf("%d. SortTriples(%+v) = %+v not %+v\n%s", i, td.a, out, td.want, diff)
}
}
}
开发者ID:BobbWu,项目名称:degdb,代码行数:49,代码来源:protocol_test.go
示例16: TestInsertAndRetreiveTriples
func TestInsertAndRetreiveTriples(t *testing.T) {
t.Parallel()
s := testServer(t)
go s.network.Listen()
time.Sleep(10 * time.Millisecond)
base := fmt.Sprintf("http://localhost:%d", s.network.Port)
testTriples := testTriplesKeyspace(s.network.LocalKeyspace())
triples, err := json.Marshal(testTriples)
if err != nil {
t.Error(err)
}
buf := bytes.NewBuffer(triples)
resp, err := http.Post(base+"/api/v1/insert", "application/json", buf)
if err != nil {
t.Error(err)
}
out, _ := ioutil.ReadAll(resp.Body)
if !bytes.Contains(out, []byte(strconv.Itoa(len(testTriples)))) {
t.Errorf("http.Post(/api/v1/insert) = %+v; missing %+v", string(out), len(testTriples))
}
// Takes a bit of time to write
time.Sleep(100 * time.Millisecond)
var signedTriples []*protocol.Triple
resp, err = http.Get(base + "/api/v1/triples")
if err != nil {
t.Error(err)
}
err = json.NewDecoder(resp.Body).Decode(&signedTriples)
if err != nil {
t.Error(err)
}
strippedTriples := stripCreated(stripSigning(signedTriples))
protocol.SortTriples(strippedTriples)
if diff, equal := messagediff.PrettyDiff(testTriples, strippedTriples); !equal {
t.Errorf("http.Get(/api/v1/insert) = %+v\n;not %+v\n%s", strippedTriples, testTriples, diff)
}
}
开发者ID:BobbWu,项目名称:degdb,代码行数:47,代码来源:http_test.go
示例17: TestOverriddenValues
func TestOverriddenValues(t *testing.T) {
expected := OptionsConfiguration{
ListenAddresses: []string{"tcp://:23000"},
GlobalAnnServers: []string{"udp4://syncthing.nym.se:22026"},
GlobalAnnEnabled: false,
LocalAnnEnabled: false,
LocalAnnPort: 42123,
LocalAnnMCAddr: "quux:3232",
MaxSendKbps: 1234,
MaxRecvKbps: 2341,
ReconnectIntervalS: 6000,
RelaysEnabled: false,
RelayReconnectIntervalM: 20,
StartBrowser: false,
NATEnabled: false,
NATLeaseM: 90,
NATRenewalM: 15,
NATTimeoutS: 15,
RestartOnWakeup: false,
AutoUpgradeIntervalH: 24,
KeepTemporariesH: 48,
CacheIgnoredFiles: true,
ProgressUpdateIntervalS: 10,
SymlinksEnabled: false,
LimitBandwidthInLan: true,
MinHomeDiskFreePct: 5.2,
URURL: "https://localhost/newdata",
URInitialDelayS: 800,
URPostInsecurely: true,
ReleasesURL: "https://localhost/releases",
AlwaysLocalNets: []string{},
OverwriteRemoteDevNames: true,
TempIndexMinBlocks: 100,
UnackedNotificationIDs: []string{},
}
cfg, err := Load("testdata/overridenvalues.xml", device1)
if err != nil {
t.Error(err)
}
if diff, equal := messagediff.PrettyDiff(expected, cfg.Options()); !equal {
t.Errorf("Overridden config differs. Diff:\n%s", diff)
}
}
开发者ID:kluppy,项目名称:syncthing,代码行数:45,代码来源:config_test.go
示例18: TestDefaultValues
func TestDefaultValues(t *testing.T) {
expected := OptionsConfiguration{
ListenAddresses: []string{"default"},
GlobalAnnServers: []string{"default"},
GlobalAnnEnabled: true,
LocalAnnEnabled: true,
LocalAnnPort: 21027,
LocalAnnMCAddr: "[ff12::8384]:21027",
MaxSendKbps: 0,
MaxRecvKbps: 0,
ReconnectIntervalS: 60,
RelaysEnabled: true,
RelayReconnectIntervalM: 10,
StartBrowser: true,
NATEnabled: true,
NATLeaseM: 60,
NATRenewalM: 30,
NATTimeoutS: 10,
RestartOnWakeup: true,
AutoUpgradeIntervalH: 12,
KeepTemporariesH: 24,
CacheIgnoredFiles: false,
ProgressUpdateIntervalS: 5,
SymlinksEnabled: true,
LimitBandwidthInLan: false,
MinHomeDiskFreePct: 1,
URURL: "https://data.syncthing.net/newdata",
URInitialDelayS: 1800,
URPostInsecurely: false,
ReleasesURL: "https://upgrades.syncthing.net/meta.json",
AlwaysLocalNets: []string{},
OverwriteRemoteDevNames: false,
TempIndexMinBlocks: 10,
UnackedNotificationIDs: []string{},
}
cfg := New(device1)
if diff, equal := messagediff.PrettyDiff(expected, cfg.Options); !equal {
t.Errorf("Default config differs. Diff:\n%s", diff)
}
}
开发者ID:kluppy,项目名称:syncthing,代码行数:42,代码来源:config_test.go
示例19: TestPartitionedBloomGob
// Ensures that PartitionedBloomFilter can be serialized and deserialized without errors.
func TestPartitionedBloomGob(t *testing.T) {
f := NewPartitionedBloomFilter(100, 0.1)
for i := 0; i < 1000; i++ {
f.Add([]byte(strconv.Itoa(i)))
}
var buf bytes.Buffer
if err := gob.NewEncoder(&buf).Encode(f); err != nil {
t.Error(err)
}
f2 := NewPartitionedBloomFilter(100, 0.1)
if err := gob.NewDecoder(&buf).Decode(f2); err != nil {
t.Error(err)
}
if diff, equal := messagediff.PrettyDiff(f, f2); !equal {
t.Errorf("PartitionedBoomFilter Gob Encode and Decode = %+v; not %+v\n%s", f2, f, diff)
}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:21,代码来源:partitioned_test.go
示例20: TestBucketsGob
// Ensures that Buckets can be serialized and deserialized without errors.
func TestBucketsGob(t *testing.T) {
b := NewBuckets(5, 2)
for i := 0; i < 5; i++ {
b.Increment(uint(i), 1)
}
var buf bytes.Buffer
if err := gob.NewEncoder(&buf).Encode(b); err != nil {
t.Error(err)
}
b2 := NewBuckets(5, 2)
if err := gob.NewDecoder(&buf).Decode(b2); err != nil {
t.Error(err)
}
if diff, equal := messagediff.PrettyDiff(b, b2); !equal {
t.Errorf("Buckets Gob Encode and Decode = %+v; not %+v\n%s", b2, b, diff)
}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:21,代码来源:buckets_test.go
注:本文中的github.com/d4l3k/messagediff.PrettyDiff函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论