github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/apptemplateversion/converter_test.go (about) 1 package apptemplateversion_test 2 3 import ( 4 "testing" 5 6 "github.com/kyma-incubator/compass/components/director/internal/domain/apptemplateversion" 7 8 "github.com/kyma-incubator/compass/components/director/internal/model" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestConverter_ToEntity(t *testing.T) { 13 // GIVEN 14 appTemplateVersionModel := fixModelApplicationTemplateVersion(appTemplateVersionID) 15 appTemplateVersionEntity := fixEntityApplicationTemplateVersion(t, appTemplateVersionID) 16 17 testCases := []struct { 18 Name string 19 Input *model.ApplicationTemplateVersion 20 Expected *apptemplateversion.Entity 21 }{ 22 { 23 Name: "All properties given", 24 Input: appTemplateVersionModel, 25 Expected: appTemplateVersionEntity, 26 }, 27 { 28 Name: "Empty", 29 Input: &model.ApplicationTemplateVersion{}, 30 Expected: &apptemplateversion.Entity{}, 31 }, 32 { 33 Name: "Nil", 34 Input: nil, 35 Expected: nil, 36 }, 37 } 38 39 for _, testCase := range testCases { 40 t.Run(testCase.Name, func(t *testing.T) { 41 conv := apptemplateversion.NewConverter() 42 43 // WHEN 44 res := conv.ToEntity(testCase.Input) 45 46 // then 47 assert.Equal(t, testCase.Expected, res) 48 }) 49 } 50 } 51 52 func TestConverter_FromEntity(t *testing.T) { 53 // GIVEN 54 55 appTemplateEntity := fixEntityApplicationTemplateVersion(t, appTemplateVersionID) 56 appTemplateModel := fixModelApplicationTemplateVersion(appTemplateVersionID) 57 58 testCases := []struct { 59 Name string 60 Input *apptemplateversion.Entity 61 Expected *model.ApplicationTemplateVersion 62 }{ 63 { 64 Name: "All properties given", 65 Input: appTemplateEntity, 66 Expected: appTemplateModel, 67 }, 68 { 69 Name: "Empty", 70 Input: &apptemplateversion.Entity{}, 71 Expected: &model.ApplicationTemplateVersion{}, 72 }, 73 { 74 Name: "Nil", 75 Input: nil, 76 Expected: nil, 77 }, 78 } 79 80 for _, testCase := range testCases { 81 t.Run(testCase.Name, func(t *testing.T) { 82 conv := apptemplateversion.NewConverter() 83 84 // WHEN 85 res := conv.FromEntity(testCase.Input) 86 87 // then 88 assert.Equal(t, testCase.Expected, res) 89 }) 90 } 91 }