From 5db3510740f0d6da347b0e13af07f2d69fd4bfb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=9C=C9=B4=E1=B4=8B=C9=B4=E1=B4=A1=E1=B4=8F=C9=B4?= Date: Fri, 21 Aug 2020 22:34:13 +0800 Subject: [PATCH] tree_entry: add tests for #59 (#60) --- tree_entry_test.go | 54 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/tree_entry_test.go b/tree_entry_test.go index 7dea0a5dd..50b09ef0e 100644 --- a/tree_entry_test.go +++ b/tree_entry_test.go @@ -120,7 +120,7 @@ func TestEntries_Sort(t *testing.T) { } func TestEntries_CommitsInfo(t *testing.T) { - tree, err := testrepo.LsTree("0eedd79eba4394bbef888c804e899731644367fe") + tree, err := testrepo.LsTree("cfc3b2993f74726356887a5ec093de50486dc617") if err != nil { t.Fatal(err) } @@ -130,7 +130,7 @@ func TestEntries_CommitsInfo(t *testing.T) { t.Fatal(err) } - t.Run("", func(t *testing.T) { + t.Run("general directory", func(t *testing.T) { es, err := tree.Entries() if err != nil { t.Fatal(err) @@ -226,6 +226,13 @@ func TestEntries_CommitsInfo(t *testing.T) { Commit: &Commit{ ID: MustIDFromString("0eedd79eba4394bbef888c804e899731644367fe"), }, + }, { + Entry: &TreeEntry{ + name: "sameSHAs", + }, + Commit: &Commit{ + ID: MustIDFromString("cfc3b2993f74726356887a5ec093de50486dc617"), + }, }, { Entry: &TreeEntry{ name: "src", @@ -241,7 +248,7 @@ func TestEntries_CommitsInfo(t *testing.T) { } }) - t.Run("", func(t *testing.T) { + t.Run("directory with submodule", func(t *testing.T) { subtree, err := tree.Subtree("gogs") if err != nil { t.Fatal(err) @@ -274,4 +281,45 @@ func TestEntries_CommitsInfo(t *testing.T) { assert.Equal(t, expInfos[i].Commit.ID.String(), infos[i].Commit.ID.String(), "idx: %d", i) } }) + + t.Run("direcotry with files have same SHA", func(t *testing.T) { + subtree, err := tree.Subtree("sameSHAs") + if err != nil { + t.Fatal(err) + } + + es, err := subtree.Entries() + if err != nil { + t.Fatal(err) + } + + infos, err := es.CommitsInfo(c, CommitsInfoOptions{ + Path: "sameSHAs", + }) + if err != nil { + t.Fatal(err) + } + + expInfos := []*EntryCommitInfo{ + { + Entry: &TreeEntry{ + name: "file1.txt", + }, + Commit: &Commit{ + ID: MustIDFromString("cfc3b2993f74726356887a5ec093de50486dc617"), + }, + }, { + Entry: &TreeEntry{ + name: "file2.txt", + }, + Commit: &Commit{ + ID: MustIDFromString("cfc3b2993f74726356887a5ec093de50486dc617"), + }, + }, + } + for i := range expInfos { + assert.Equal(t, expInfos[i].Entry.Name(), infos[i].Entry.Name(), "idx: %d", i) + assert.Equal(t, expInfos[i].Commit.ID.String(), infos[i].Commit.ID.String(), "idx: %d", i) + } + }) }