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

     1  package runtime_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kyma-project/kyma-environment-broker/internal"
     7  
     8  	"github.com/kyma-project/kyma-environment-broker/internal/runtime"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestGenericComponentDisabler(t *testing.T) {
    13  	type toDisable struct {
    14  		Name string
    15  	}
    16  	tests := []struct {
    17  		name            string
    18  		givenComponents internal.ComponentConfigurationInputList
    19  		expComponents   internal.ComponentConfigurationInputList
    20  		toDisable       toDisable
    21  	}{
    22  		{
    23  			name: "Disable component if the name and namespace match with predicate",
    24  			toDisable: toDisable{
    25  				Name: "ory",
    26  			},
    27  			givenComponents: internal.ComponentConfigurationInputList{
    28  				{Component: "dex"},
    29  				{Component: "ory"},
    30  			},
    31  			expComponents: internal.ComponentConfigurationInputList{
    32  				{Component: "dex"},
    33  			},
    34  		},
    35  		{
    36  			name: "Disable component if name does not match",
    37  			toDisable: toDisable{
    38  				Name: "not-valid",
    39  			},
    40  			givenComponents: internal.ComponentConfigurationInputList{
    41  				{Component: "dex"},
    42  				{Component: "ory"},
    43  			},
    44  			expComponents: internal.ComponentConfigurationInputList{
    45  				{Component: "dex"},
    46  				{Component: "ory"},
    47  			},
    48  		},
    49  	}
    50  	for _, test := range tests {
    51  		t.Run(test.name, func(t *testing.T) {
    52  			// given
    53  			sut := runtime.NewGenericComponentDisabler(test.toDisable.Name)
    54  
    55  			// when
    56  			modifiedComponents := sut.Disable(test.givenComponents)
    57  
    58  			// then
    59  			assert.EqualValues(t, test.expComponents, modifiedComponents)
    60  		})
    61  	}
    62  }