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

     1  package operationsmanager_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	operationsmanager "github.com/kyma-incubator/compass/components/director/internal/operations_manager"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestOrdOperationData_GetData(t *testing.T) {
    12  	// GIVEN
    13  	testCases := []struct {
    14  		Name          string
    15  		AppID         string
    16  		AppTemplateID string
    17  		ExpectedData  string
    18  		ExpectedErr   error
    19  	}{
    20  		{
    21  			Name:          "Success",
    22  			AppID:         "app-id",
    23  			AppTemplateID: "app-template-id",
    24  			ExpectedData:  "{\"applicationID\":\"app-id\",\"applicationTemplateID\":\"app-template-id\"}",
    25  		},
    26  		{
    27  			Name:         "Success - missing application template id",
    28  			AppID:        "app-id",
    29  			ExpectedData: "{\"applicationID\":\"app-id\"}",
    30  		},
    31  		{
    32  			Name:         "Success - missing application id",
    33  			ExpectedData: "{\"applicationID\":\"\"}",
    34  		},
    35  	}
    36  
    37  	for _, testCase := range testCases {
    38  		t.Run(testCase.Name, func(t *testing.T) {
    39  			// GIVEN
    40  			opData := operationsmanager.NewOrdOperationData(testCase.AppID, testCase.AppTemplateID)
    41  
    42  			// WHEN
    43  			result, err := opData.GetData()
    44  
    45  			// THEN
    46  			if testCase.ExpectedErr != nil {
    47  				require.Error(t, err)
    48  				assert.Contains(t, err.Error(), testCase.ExpectedErr.Error())
    49  			} else {
    50  				assert.Nil(t, err)
    51  				assert.Equal(t, testCase.ExpectedData, result)
    52  			}
    53  		})
    54  	}
    55  }