github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/formation_assignment_test.go (about) 1 package model_test 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/kyma-incubator/compass/components/director/internal/model" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestFormationAssignmentInput_ToModel(t *testing.T) { 12 // GIVEN 13 id := "id" 14 tenantID := "tenant-id" 15 16 faInput := &model.FormationAssignmentInput{ 17 FormationID: "formation-id", 18 Source: "source", 19 SourceType: "source-type", 20 Target: "target", 21 TargetType: "target-type", 22 State: "state", 23 Value: json.RawMessage(`{"testKey":"testValue"}`), 24 } 25 26 fa := &model.FormationAssignment{ 27 ID: id, 28 FormationID: "formation-id", 29 TenantID: tenantID, 30 Source: "source", 31 SourceType: "source-type", 32 Target: "target", 33 TargetType: "target-type", 34 State: "state", 35 Value: json.RawMessage(`{"testKey":"testValue"}`), 36 } 37 38 testCases := []struct { 39 Name string 40 Input *model.FormationAssignmentInput 41 Expected *model.FormationAssignment 42 }{ 43 { 44 Name: "Success", 45 Input: faInput, 46 Expected: fa, 47 }, 48 { 49 Name: "Empty", 50 Input: &model.FormationAssignmentInput{}, 51 Expected: &model.FormationAssignment{ 52 ID: id, 53 TenantID: tenantID, 54 }, 55 }, 56 { 57 Name: "Nil", 58 Input: nil, 59 Expected: nil, 60 }, 61 } 62 63 for _, testCase := range testCases { 64 t.Run(testCase.Name, func(t *testing.T) { 65 // WHEN 66 result := testCase.Input.ToModel(id, tenantID) 67 68 // THEN 69 require.Equal(t, testCase.Expected, result) 70 }) 71 } 72 }