grafana/pkg/build/gcloud/storage/gsutil_test.go
Dimitris Sotirakis 4e73766067
CI: Move store-storybook to OSS (#55212)
* Move store-storybook to OSS

* grabpl -> build for store-storybook command

* Replace zerolog with builtin log

* Remove flags from store-storybook

* Fix lint
2022-09-15 11:06:43 +03:00

160 lines
2.9 KiB
Go

package storage
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_asChunks(t *testing.T) {
type args struct {
files []File
chunkSize int
}
tcs := []struct {
name string
args args
expected [][]File
}{
{
name: "Happy path #1",
args: args{
files: []File{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
{FullPath: "/1"},
{FullPath: "/2"},
{FullPath: "/3"},
},
chunkSize: 5,
},
expected: [][]File{
{{FullPath: "/a"}, {FullPath: "/b"}, {FullPath: "/c"}, {FullPath: "/1"}, {FullPath: "/2"}},
{{FullPath: "/3"}},
},
},
{
name: "Happy path #2",
args: args{
files: []File{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
{FullPath: "/1"},
{FullPath: "/2"},
{FullPath: "/3"},
},
chunkSize: 2,
},
expected: [][]File{
{{FullPath: "/a"}, {FullPath: "/b"}},
{{FullPath: "/c"}, {FullPath: "/1"}},
{{FullPath: "/2"}, {FullPath: "/3"}},
},
},
{
name: "Happy path #3",
args: args{
files: []File{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
},
chunkSize: 1,
},
expected: [][]File{
{{FullPath: "/a"}},
{{FullPath: "/b"}},
{{FullPath: "/c"}},
},
},
{
name: "A chunkSize with 0 value returns the input as a single chunk",
args: args{
files: []File{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
},
chunkSize: 0,
},
expected: [][]File{
{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
},
},
},
{
name: "A chunkSize with negative value returns the input as a single chunk",
args: args{
files: []File{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
},
chunkSize: -1,
},
expected: [][]File{
{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
},
},
},
{
name: "A chunkSize greater than the size on input returns the input as a single chunk",
args: args{
files: []File{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
},
chunkSize: 5,
},
expected: [][]File{
{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
},
},
},
{
name: "A chunkSize equal the size on input returns the input as a single chunk",
args: args{
files: []File{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
},
chunkSize: 3,
},
expected: [][]File{
{
{FullPath: "/a"},
{FullPath: "/b"},
{FullPath: "/c"},
},
},
},
{
name: "An empty input returns empty chunks",
args: args{
files: []File{},
chunkSize: 3,
},
expected: [][]File{},
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
result := asChunks(tc.args.files, tc.args.chunkSize)
require.Equal(t, tc.expected, result)
})
}
}