github.com/kubeshop/testkube@v1.17.23/cmd/tcl/testworkflow-toolkit/common/combinations_test.go (about)

     1  // Copyright 2024 Testkube.
     2  //
     3  // Licensed as a Testkube Pro file under the Testkube Community
     4  // License (the "License"); you may not use this file except in compliance with
     5  // the License. You may obtain a copy of the License at
     6  //
     7  //	https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt
     8  
     9  package common
    10  
    11  import (
    12  	"testing"
    13  
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  func TestGetShardValues_LessThanCount(t *testing.T) {
    18  	values := map[string][]interface{}{"a": {5, 10, 15}}
    19  	assert.Equal(t, map[string][]interface{}{"a": {5}}, GetShardValues(values, 0, 5))
    20  	assert.Equal(t, map[string][]interface{}{"a": {10}}, GetShardValues(values, 1, 5))
    21  	assert.Equal(t, map[string][]interface{}{"a": {15}}, GetShardValues(values, 2, 5))
    22  	assert.Equal(t, map[string][]interface{}{"a": {}}, GetShardValues(values, 3, 5))
    23  	assert.Equal(t, map[string][]interface{}{"a": {}}, GetShardValues(values, 4, 5))
    24  }
    25  
    26  func TestGetShardValues_EqualCount(t *testing.T) {
    27  	values := map[string][]interface{}{"a": {5, 10, 15}}
    28  	assert.Equal(t, map[string][]interface{}{"a": {5}}, GetShardValues(values, 0, 3))
    29  	assert.Equal(t, map[string][]interface{}{"a": {10}}, GetShardValues(values, 1, 3))
    30  	assert.Equal(t, map[string][]interface{}{"a": {15}}, GetShardValues(values, 2, 3))
    31  }
    32  
    33  func TestGetShardValues_UnevenCount(t *testing.T) {
    34  	values := map[string][]interface{}{"a": {5, 10, 15, 20, 25}}
    35  	assert.Equal(t, map[string][]interface{}{"a": {5, 10}}, GetShardValues(values, 0, 3))
    36  	assert.Equal(t, map[string][]interface{}{"a": {15, 20}}, GetShardValues(values, 1, 3))
    37  	assert.Equal(t, map[string][]interface{}{"a": {25}}, GetShardValues(values, 2, 3))
    38  }