Skip to content

Commit

Permalink
add TestGetEntriesFromTree (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 18, 2023
1 parent a86a215 commit 4a24f06
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions internal/store/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"testing"

"github.com/JunNishimura/Goit/internal/object"
"github.com/JunNishimura/Goit/internal/sha"
)

Expand Down Expand Up @@ -495,3 +496,90 @@ func TestDeleteEntry(t *testing.T) {
})
}
}

func TestGetEntriesFromTree(t *testing.T) {
type args struct {
rootName string
nodes []*object.Node
}
type test struct {
name string
args args
want []*Entry
wantErr bool
}
tests := []*test{
func() *test {
hash, _ := hex.DecodeString("87f3c49bccf2597484ece08746d3ee5defaba335")

return &test{
name: "success",
args: args{
rootName: "",
nodes: []*object.Node{
{
Hash: hash,
Name: "a.txt",
Children: []*object.Node{},
},
{
Hash: hash,
Name: "b",
Children: []*object.Node{
{
Hash: hash,
Name: "a.txt",
Children: []*object.Node{},
},
{
Hash: hash,
Name: "b.txt",
Children: []*object.Node{},
},
},
},
{
Hash: hash,
Name: "c.txt",
Children: []*object.Node{},
},
},
},
want: []*Entry{
{
Hash: hash,
NameLength: uint16(len("a.txt")),
Path: []byte("a.txt"),
},
{
Hash: hash,
NameLength: uint16(len("b/a.txt")),
Path: []byte("b/a.txt"),
},
{
Hash: hash,
NameLength: uint16(len("b/b.txt")),
Path: []byte("b/b.txt"),
},
{
Hash: hash,
NameLength: uint16(len("c.txt")),
Path: []byte("c.txt"),
},
},
wantErr: false,
}
}(),
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetEntriesFromTree(tt.args.rootName, tt.args.nodes)
if (err != nil) != tt.wantErr {
t.Errorf("got = %v, want = %v", err, tt.wantErr)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("got = %v, want = %v", got, tt.want)
}
})
}
}

0 comments on commit 4a24f06

Please sign in to comment.