From c439c543d07f3c076ca135c5d05eb6afd829cb1f Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 17 Mar 2016 08:03:29 +0100 Subject: [PATCH] tests: messagediff argument order should be expected, actual So that the diff describes the changes that happened in actual as compared to expected. The opposite is confusing. --- lib/config/config_test.go | 20 ++++++++++---------- lib/db/set_test.go | 4 ++-- lib/model/queue_test.go | 20 ++++++++++---------- lib/scanner/walk_test.go | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/config/config_test.go b/lib/config/config_test.go index 698977b3b..19edf00da 100644 --- a/lib/config/config_test.go +++ b/lib/config/config_test.go @@ -65,7 +65,7 @@ func TestDefaultValues(t *testing.T) { cfg := New(device1) - if diff, equal := messagediff.PrettyDiff(cfg.Options, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, cfg.Options); !equal { t.Errorf("Default config differs. Diff:\n%s", diff) } } @@ -133,13 +133,13 @@ func TestDeviceConfig(t *testing.T) { if cfg.Version != CurrentVersion { t.Errorf("%d: Incorrect version %d != %d", i, cfg.Version, CurrentVersion) } - if diff, equal := messagediff.PrettyDiff(cfg.Folders, expectedFolders); !equal { + if diff, equal := messagediff.PrettyDiff(expectedFolders, cfg.Folders); !equal { t.Errorf("%d: Incorrect Folders. Diff:\n%s", i, diff) } - if diff, equal := messagediff.PrettyDiff(cfg.Devices, expectedDevices); !equal { + if diff, equal := messagediff.PrettyDiff(expectedDevices, cfg.Devices); !equal { t.Errorf("%d: Incorrect Devices. Diff:\n%s", i, diff) } - if diff, equal := messagediff.PrettyDiff(cfg.Folders[0].DeviceIDs(), expectedDeviceIDs); !equal { + if diff, equal := messagediff.PrettyDiff(expectedDeviceIDs, cfg.Folders[0].DeviceIDs()); !equal { t.Errorf("%d: Incorrect DeviceIDs. Diff:\n%s", i, diff) } } @@ -153,7 +153,7 @@ func TestNoListenAddress(t *testing.T) { expected := []string{""} actual := cfg.Options().ListenAddress - if diff, equal := messagediff.PrettyDiff(actual, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, actual); !equal { t.Errorf("Unexpected ListenAddress. Diff:\n%s", diff) } } @@ -197,7 +197,7 @@ func TestOverriddenValues(t *testing.T) { t.Error(err) } - if diff, equal := messagediff.PrettyDiff(cfg.Options(), expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, cfg.Options()); !equal { t.Errorf("Overridden config differs. Diff:\n%s", diff) } } @@ -231,7 +231,7 @@ func TestDeviceAddressesDynamic(t *testing.T) { } actual := cfg.Devices() - if diff, equal := messagediff.PrettyDiff(actual, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, actual); !equal { t.Errorf("Devices differ. Diff:\n%s", diff) } } @@ -268,7 +268,7 @@ func TestDeviceCompression(t *testing.T) { } actual := cfg.Devices() - if diff, equal := messagediff.PrettyDiff(actual, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, actual); !equal { t.Errorf("Devices differ. Diff:\n%s", diff) } } @@ -302,7 +302,7 @@ func TestDeviceAddressesStatic(t *testing.T) { } actual := cfg.Devices() - if diff, equal := messagediff.PrettyDiff(actual, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, actual); !equal { t.Errorf("Devices differ. Diff:\n%s", diff) } } @@ -325,7 +325,7 @@ func TestVersioningConfig(t *testing.T) { "foo": "bar", "baz": "quux", } - if diff, equal := messagediff.PrettyDiff(vc.Params, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, vc.Params); !equal { t.Errorf("vc.Params differ. Diff:\n%s", diff) } } diff --git a/lib/db/set_test.go b/lib/db/set_test.go index b193884b3..cfe363b2c 100644 --- a/lib/db/set_test.go +++ b/lib/db/set_test.go @@ -533,7 +533,7 @@ func TestListDropFolder(t *testing.T) { expectedFolderList := []string{"test0", "test1"} actualFolderList := ldb.ListFolders() - if diff, equal := messagediff.PrettyDiff(actualFolderList, expectedFolderList); !equal { + if diff, equal := messagediff.PrettyDiff(expectedFolderList, actualFolderList); !equal { t.Fatalf("FolderList mismatch. Diff:\n%s", diff) } if l := len(globalList(s0)); l != 3 { @@ -549,7 +549,7 @@ func TestListDropFolder(t *testing.T) { expectedFolderList = []string{"test0"} actualFolderList = ldb.ListFolders() - if diff, equal := messagediff.PrettyDiff(actualFolderList, expectedFolderList); !equal { + if diff, equal := messagediff.PrettyDiff(expectedFolderList, actualFolderList); !equal { t.Fatalf("FolderList mismatch. Diff:\n%s", diff) } if l := len(globalList(s0)); l != 3 { diff --git a/lib/model/queue_test.go b/lib/model/queue_test.go index 295ade4eb..36ab5fe54 100644 --- a/lib/model/queue_test.go +++ b/lib/model/queue_test.go @@ -127,35 +127,35 @@ func TestBringToFront(t *testing.T) { q.Push("f4", 0, 0) _, queued := q.Jobs() - if diff, equal := messagediff.PrettyDiff(queued, []string{"f1", "f2", "f3", "f4"}); !equal { + 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(queued, []string{"f1", "f2", "f3", "f4"}); !equal { + 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(queued, []string{"f3", "f1", "f2", "f4"}); !equal { + 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(queued, []string{"f2", "f3", "f1", "f4"}); !equal { + 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(queued, []string{"f4", "f2", "f3", "f1"}); !equal { + if diff, equal := messagediff.PrettyDiff([]string{"f4", "f2", "f3", "f1"}, queued); !equal { t.Errorf("Order does not match. Diff:\n%s", diff) } } @@ -176,7 +176,7 @@ func TestShuffle(t *testing.T) { } t.Logf("%v", queued) - if _, equal := messagediff.PrettyDiff(queued, []string{"f1", "f2", "f3", "f4"}); !equal { + if _, equal := messagediff.PrettyDiff([]string{"f1", "f2", "f3", "f4"}, queued); !equal { // The queue was shuffled return } @@ -200,7 +200,7 @@ func TestSortBySize(t *testing.T) { } expected := []string{"f4", "f1", "f3", "f2"} - if diff, equal := messagediff.PrettyDiff(actual, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, actual); !equal { t.Errorf("SortSmallestFirst() diff:\n%s", diff) } @@ -212,7 +212,7 @@ func TestSortBySize(t *testing.T) { } expected = []string{"f2", "f3", "f1", "f4"} - if diff, equal := messagediff.PrettyDiff(actual, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, actual); !equal { t.Errorf("SortLargestFirst() diff:\n%s", diff) } } @@ -232,7 +232,7 @@ func TestSortByAge(t *testing.T) { } expected := []string{"f4", "f1", "f3", "f2"} - if diff, equal := messagediff.PrettyDiff(actual, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, actual); !equal { t.Errorf("SortOldestFirst() diff:\n%s", diff) } @@ -244,7 +244,7 @@ func TestSortByAge(t *testing.T) { } expected = []string{"f2", "f3", "f1", "f4"} - if diff, equal := messagediff.PrettyDiff(actual, expected); !equal { + if diff, equal := messagediff.PrettyDiff(expected, actual); !equal { t.Errorf("SortNewestFirst() diff:\n%s", diff) } } diff --git a/lib/scanner/walk_test.go b/lib/scanner/walk_test.go index d1140415d..5b36e0727 100644 --- a/lib/scanner/walk_test.go +++ b/lib/scanner/walk_test.go @@ -120,7 +120,7 @@ func TestWalk(t *testing.T) { sort.Sort(fileList(tmp)) files := fileList(tmp).testfiles() - if diff, equal := messagediff.PrettyDiff(files, testdata); !equal { + if diff, equal := messagediff.PrettyDiff(testdata, files); !equal { t.Errorf("Walk returned unexpected data. Diff:\n%s", diff) } }