github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/graphql/runtime_context_validation_test.go (about)

     1  package graphql_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/pkg/graphql"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestRuntimeContextInput_Validate_Key(t *testing.T) {
    11  	testCases := []struct {
    12  		Name          string
    13  		Value         string
    14  		ExpectedValid bool
    15  	}{
    16  		{
    17  			Name:          "ExpectedValid",
    18  			Value:         "tenant_id",
    19  			ExpectedValid: true,
    20  		},
    21  		{
    22  			Name:          "Invalid - Empty",
    23  			Value:         "",
    24  			ExpectedValid: false,
    25  		},
    26  		{
    27  			Name:          "Invalid - Invalid Name",
    28  			Value:         "value/with-inv@lid-char$",
    29  			ExpectedValid: false,
    30  		},
    31  	}
    32  
    33  	for _, testCase := range testCases {
    34  		t.Run(testCase.Name, func(t *testing.T) {
    35  			//GIVEN
    36  			sut := fixValidRuntimeContextInput()
    37  			sut.Key = testCase.Value
    38  			// WHEN
    39  			err := sut.Validate()
    40  			// THEN
    41  			if testCase.ExpectedValid {
    42  				require.NoError(t, err)
    43  			} else {
    44  				require.Error(t, err)
    45  			}
    46  		})
    47  	}
    48  }
    49  
    50  func fixValidRuntimeContextInput() graphql.RuntimeContextInput {
    51  	return graphql.RuntimeContextInput{
    52  		Key: "test",
    53  	}
    54  }