2023-10-10 20:04:19 +02:00
|
|
|
package storev1
|
2022-11-19 21:34:49 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-09-22 15:38:10 +02:00
|
|
|
castorev1pb "code.tvl.fyi/tvix/castore/protos"
|
2022-11-19 21:34:49 +01:00
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"google.golang.org/protobuf/testing/protocmp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func requireProtoEq(t *testing.T, expected interface{}, actual interface{}) {
|
|
|
|
if diff := cmp.Diff(expected, actual, protocmp.Transform()); diff != "" {
|
|
|
|
t.Errorf("unexpected difference:\n%v", diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPopNextNode(t *testing.T) {
|
|
|
|
t.Run("empty directory", func(t *testing.T) {
|
2023-09-22 15:38:10 +02:00
|
|
|
d := &castorev1pb.Directory{
|
|
|
|
Directories: []*castorev1pb.DirectoryNode{},
|
|
|
|
Files: []*castorev1pb.FileNode{},
|
|
|
|
Symlinks: []*castorev1pb.SymlinkNode{},
|
2022-11-19 21:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
n := drainNextNode(d)
|
|
|
|
require.Equal(t, nil, n)
|
|
|
|
})
|
|
|
|
t.Run("only directories", func(t *testing.T) {
|
2023-09-22 15:38:10 +02:00
|
|
|
ds := &castorev1pb.Directory{
|
|
|
|
Directories: []*castorev1pb.DirectoryNode{{
|
2022-11-19 21:34:49 +01:00
|
|
|
Name: []byte("a"),
|
|
|
|
Digest: []byte{},
|
|
|
|
Size: 0,
|
|
|
|
}, {
|
|
|
|
Name: []byte("b"),
|
|
|
|
Digest: []byte{},
|
|
|
|
Size: 0,
|
|
|
|
}},
|
2023-09-22 15:38:10 +02:00
|
|
|
Files: []*castorev1pb.FileNode{},
|
|
|
|
Symlinks: []*castorev1pb.SymlinkNode{},
|
2022-11-19 21:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
n := drainNextNode(ds)
|
2023-09-22 15:38:10 +02:00
|
|
|
requireProtoEq(t, &castorev1pb.DirectoryNode{
|
2022-11-19 21:34:49 +01:00
|
|
|
Name: []byte("a"),
|
|
|
|
Digest: []byte{},
|
|
|
|
Size: 0,
|
|
|
|
}, n)
|
|
|
|
})
|
|
|
|
}
|