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

     1  package model_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/kyma-incubator/compass/components/director/internal/model"
    10  )
    11  
    12  func TestToLabel(t *testing.T) {
    13  	// GIVEN
    14  	id := "foo"
    15  	tenant := "sample"
    16  
    17  	labelKey := "key"
    18  	labelValue := "value"
    19  
    20  	testCases := []struct {
    21  		Name     string
    22  		Input    *model.LabelInput
    23  		Expected *model.Label
    24  	}{
    25  		{
    26  			Name: "All properties given",
    27  			Input: &model.LabelInput{
    28  				Key:        labelKey,
    29  				Value:      labelValue,
    30  				ObjectID:   id,
    31  				ObjectType: model.ApplicationLabelableObject,
    32  			},
    33  			Expected: &model.Label{
    34  				ID:         id,
    35  				Key:        labelKey,
    36  				Value:      labelValue,
    37  				ObjectID:   id,
    38  				ObjectType: model.ApplicationLabelableObject,
    39  			},
    40  		},
    41  		{
    42  			Name: "All properties given for scenario label",
    43  			Input: &model.LabelInput{
    44  				Key:        model.ScenariosKey,
    45  				Value:      labelValue,
    46  				ObjectID:   id,
    47  				ObjectType: model.ApplicationLabelableObject,
    48  			},
    49  			Expected: &model.Label{
    50  				ID:         id,
    51  				Tenant:     &tenant,
    52  				Key:        model.ScenariosKey,
    53  				Value:      labelValue,
    54  				ObjectID:   id,
    55  				ObjectType: model.ApplicationLabelableObject,
    56  			},
    57  		},
    58  		{
    59  			Name:  "Empty",
    60  			Input: &model.LabelInput{},
    61  			Expected: &model.Label{
    62  				ID: id,
    63  			},
    64  		},
    65  	}
    66  
    67  	for i, testCase := range testCases {
    68  		t.Run(fmt.Sprintf("%d: %s", i, testCase.Name), func(t *testing.T) {
    69  			// WHEN
    70  			result := testCase.Input.ToLabel(id, tenant)
    71  
    72  			// then
    73  			assert.Equal(t, testCase.Expected, result)
    74  		})
    75  	}
    76  }