github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/scenariogroups/scenarioGroups_test.go (about)

     1  package scenariogroups_test
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/kyma-incubator/compass/components/director/internal/domain/scenariogroups"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestLoadFromContext(t *testing.T) {
    14  	value := []string{"foo"}
    15  
    16  	testCases := []struct {
    17  		Name    string
    18  		Context context.Context
    19  
    20  		ExpectedResult []string
    21  	}{
    22  		{
    23  			Name:           "Success",
    24  			Context:        context.WithValue(context.TODO(), scenariogroups.ScenarioGroupsContextKey, value),
    25  			ExpectedResult: value,
    26  		},
    27  		{
    28  			Name:           "Nil value",
    29  			Context:        context.TODO(),
    30  			ExpectedResult: []string{},
    31  		},
    32  	}
    33  
    34  	for i, testCase := range testCases {
    35  		t.Run(fmt.Sprintf("%d: %s", i, testCase.Name), func(t *testing.T) {
    36  			// WHEN
    37  			result := scenariogroups.LoadFromContext(testCase.Context)
    38  
    39  			assert.Equal(t, testCase.ExpectedResult, result)
    40  		})
    41  	}
    42  }
    43  
    44  func TestSaveToLoadFromContext(t *testing.T) {
    45  	// GIVEN
    46  	value := []string{"foo"}
    47  	ctx := context.TODO()
    48  
    49  	// WHEN
    50  	result := scenariogroups.SaveToContext(ctx, value)
    51  
    52  	// then
    53  	assert.Equal(t, value, result.Value(scenariogroups.ScenarioGroupsContextKey))
    54  }