The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/build/gcloud/storage/gsutil_test.go

159 lines
2.9 KiB

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)
})
}
}