github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/config/validator_test.go (about)

     1  package config_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kyma-project/kyma-environment-broker/internal/config"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  const (
    12  	additionalComponentsConfigKey = "additional-components"
    13  )
    14  
    15  func TestValidate(t *testing.T) {
    16  	// setup
    17  	cfgValidator := config.NewConfigMapKeysValidator()
    18  
    19  	t.Run("should validate whether config contains required fields", func(t *testing.T) {
    20  		// given
    21  		cfgString := `additional-components:
    22    - name: "additional-component1"
    23      namespace: "kyma-system"
    24  optional-field: "optional"`
    25  
    26  		// when
    27  		err := cfgValidator.Validate(cfgString)
    28  
    29  		// then
    30  		require.NoError(t, err)
    31  	})
    32  
    33  	t.Run("should return error indicating missing required fields", func(t *testing.T) {
    34  		// given
    35  		cfgString := `optional-field: "optional"`
    36  
    37  		// when
    38  		err := cfgValidator.Validate(cfgString)
    39  
    40  		// then
    41  		require.Error(t, err)
    42  		assert.Contains(t, err.Error(), additionalComponentsConfigKey)
    43  	})
    44  }