github.com/michael-k/docker@v1.7.0-rc2/pkg/tarsum/fileinfosums_test.go (about) 1 package tarsum 2 3 import "testing" 4 5 func newFileInfoSums() FileInfoSums { 6 return FileInfoSums{ 7 fileInfoSum{name: "file3", sum: "2abcdef1234567890", pos: 2}, 8 fileInfoSum{name: "dup1", sum: "deadbeef1", pos: 5}, 9 fileInfoSum{name: "file1", sum: "0abcdef1234567890", pos: 0}, 10 fileInfoSum{name: "file4", sum: "3abcdef1234567890", pos: 3}, 11 fileInfoSum{name: "dup1", sum: "deadbeef0", pos: 4}, 12 fileInfoSum{name: "file2", sum: "1abcdef1234567890", pos: 1}, 13 } 14 } 15 16 func TestSortFileInfoSums(t *testing.T) { 17 dups := newFileInfoSums().GetAllFile("dup1") 18 if len(dups) != 2 { 19 t.Errorf("expected length 2, got %d", len(dups)) 20 } 21 dups.SortByNames() 22 if dups[0].Pos() != 4 { 23 t.Errorf("sorted dups should be ordered by position. Expected 4, got %d", dups[0].Pos()) 24 } 25 26 fis := newFileInfoSums() 27 expected := "0abcdef1234567890" 28 fis.SortBySums() 29 got := fis[0].Sum() 30 if got != expected { 31 t.Errorf("Expected %q, got %q", expected, got) 32 } 33 34 fis = newFileInfoSums() 35 expected = "dup1" 36 fis.SortByNames() 37 gotFis := fis[0] 38 if gotFis.Name() != expected { 39 t.Errorf("Expected %q, got %q", expected, gotFis.Name()) 40 } 41 // since a duplicate is first, ensure it is ordered first by position too 42 if gotFis.Pos() != 4 { 43 t.Errorf("Expected %d, got %d", 4, gotFis.Pos()) 44 } 45 }