Skip to content

Commit

Permalink
add TestNewGetPaths (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 23, 2023
1 parent d961e8d commit b0c9bb4
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions internal/object/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,89 @@ import (
"testing"
)

func TestNewGetPaths(t *testing.T) {
type fields struct {
node Node
}
type test struct {
name string
fields fields
want []string
}
tests := []*test{
func() *test {
hash, _ := hex.DecodeString("87f3c49bccf2597484ece08746d3ee5defaba335")

return &test{
name: "success: empty",
fields: fields{
node: Node{
Hash: hash,
Name: "test.txt",
Children: nil,
},
},
want: []string{"test.txt"},
}
}(),
func() *test {
hash, _ := hex.DecodeString("87f3c49bccf2597484ece08746d3ee5defaba335")

return &test{
name: "success: empty",
fields: fields{
node: Node{
Hash: hash,
Name: "dir",
Children: []*Node{
{
Hash: hash,
Name: "dir2",
Children: []*Node{
{
Hash: hash,
Name: "test.txt",
Children: nil,
},
{
Hash: hash,
Name: "test2.txt",
Children: nil,
},
},
},
{
Hash: hash,
Name: "test.txt",
Children: nil,
},
{
Hash: hash,
Name: "test2.txt",
Children: nil,
},
},
},
},
want: []string{
"dir/dir2/test.txt",
"dir/dir2/test2.txt",
"dir/test.txt",
"dir/test2.txt",
},
}
}(),
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.fields.node.GetPaths()
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("got = %v, want = %v", got, tt.want)
}
})
}
}

func TestNewTree(t *testing.T) {
type args struct {
object *Object
Expand Down

0 comments on commit b0c9bb4

Please sign in to comment.