grafana/pkg/services/cloudmigration/slicesext/slicesext_test.go
Bruno d1952bb681
Cloud migrations: create snapshot files (#89693)
* Cloud migrations: create snapshot and store it on disk

* fix merge conflicts

* implement StartSnapshot for gms client

* pass snapshot directory as argument to snapshot builder

* ensure snapshot folder is set

* make swagger-gen

* remove Test_ExecuteAsyncWorkflow

* pass signed in user to buildSnapshot method / use github.com/grafana/grafana-cloud-migration-snapshot to create snapshot files

* fix FakeServiceImpl.CreateSnapshot

* remove new line
2024-07-03 10:38:26 -03:00

81 lines
1.6 KiB
Go

package slicesext
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestChunks(t *testing.T) {
t.Parallel()
t.Run("chunkSize must be greater than 0", func(t *testing.T) {
t.Parallel()
assert.PanicsWithValue(t, "chunk size must be greater than or equal to 0", func() {
Chunks(-1, []string{})
})
})
t.Run("basic", func(t *testing.T) {
t.Parallel()
cases := []struct {
description string
chunkSize int
input []int
expected [][]int
}{
{
description: "empty slice",
chunkSize: 2,
input: []int{},
expected: [][]int{},
},
{
description: "nil slice",
chunkSize: 2,
input: nil,
expected: [][]int{},
},
{
description: "chunk size is 0",
chunkSize: 0,
input: []int{1, 2, 3},
expected: [][]int{},
},
{
description: "chunk size is greater than slice length",
chunkSize: 3,
input: []int{1},
expected: [][]int{{1}},
},
{
description: "chunk size is 1",
chunkSize: 1,
input: []int{1, 2, 3},
expected: [][]int{{1}, {2}, {3}},
},
{
description: "chunk size is 2 and slice length is 3",
chunkSize: 2,
input: []int{1, 2, 3},
expected: [][]int{{1, 2}, {3}},
},
{
description: "chunk size is 2 and slice length is 6",
chunkSize: 2,
input: []int{1, 2, 3, 4, 5, 6},
expected: [][]int{{1, 2}, {3, 4}, {5, 6}},
},
}
for _, tt := range cases {
t.Run(tt.description, func(t *testing.T) {
result := Chunks(tt.chunkSize, tt.input)
assert.Equal(t, tt.expected, result)
})
}
})
}