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

     1  package model_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
     7  
     8  	"github.com/kyma-incubator/compass/components/director/internal/model"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestTombstoneInput_ToTombstone(t *testing.T) {
    13  	// GIVEN
    14  	id := "test"
    15  	ordID := "foo"
    16  	appID := "bar"
    17  	appTemplateVersionID := "nar"
    18  	removalDate := "Sample"
    19  
    20  	testCases := []struct {
    21  		Name         string
    22  		Input        *model.TombstoneInput
    23  		ResourceType resource.Type
    24  		ResourceID   string
    25  		Expected     *model.Tombstone
    26  	}{
    27  		{
    28  			Name: "All properties given for App",
    29  			Input: &model.TombstoneInput{
    30  				OrdID:       ordID,
    31  				RemovalDate: removalDate,
    32  			},
    33  			Expected: &model.Tombstone{
    34  				ID:            id,
    35  				OrdID:         ordID,
    36  				ApplicationID: &appID,
    37  				RemovalDate:   removalDate,
    38  			},
    39  			ResourceType: resource.Application,
    40  			ResourceID:   appID,
    41  		},
    42  		{
    43  			Name: "All properties given for App Template Version",
    44  			Input: &model.TombstoneInput{
    45  				OrdID:       ordID,
    46  				RemovalDate: removalDate,
    47  			},
    48  			Expected: &model.Tombstone{
    49  				ID:                           id,
    50  				OrdID:                        ordID,
    51  				ApplicationTemplateVersionID: &appTemplateVersionID,
    52  				RemovalDate:                  removalDate,
    53  			},
    54  			ResourceType: resource.ApplicationTemplateVersion,
    55  			ResourceID:   appTemplateVersionID,
    56  		},
    57  		{
    58  			Name:     "Nil",
    59  			Input:    nil,
    60  			Expected: nil,
    61  		},
    62  	}
    63  
    64  	for _, testCase := range testCases {
    65  		t.Run(testCase.Name, func(t *testing.T) {
    66  			// WHEN
    67  			result := testCase.Input.ToTombstone(id, testCase.ResourceType, testCase.ResourceID)
    68  
    69  			// THEN
    70  			assert.Equal(t, testCase.Expected, result)
    71  		})
    72  	}
    73  }