github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/consumer/consumer_test.go (about) 1 package consumer_test 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/kyma-incubator/compass/components/director/pkg/model" 8 9 "github.com/kyma-incubator/compass/components/director/pkg/apperrors" 10 11 "github.com/kyma-incubator/compass/components/director/pkg/consumer" 12 13 "github.com/stretchr/testify/assert" 14 "github.com/stretchr/testify/require" 15 ) 16 17 func TestMapSystemAuthToConsumerType(t *testing.T) { 18 // GIVEN 19 testCases := []struct { 20 name string 21 sysAuthRefInput model.SystemAuthReferenceObjectType 22 expected consumer.ConsumerType 23 expectedErr error 24 }{ 25 { 26 name: "Success - Map to application", 27 sysAuthRefInput: model.ApplicationReference, 28 expected: consumer.Application, 29 }, 30 { 31 name: "Success - Map to runtime", 32 sysAuthRefInput: model.RuntimeReference, 33 expected: consumer.Runtime, 34 }, 35 { 36 name: "Success - Map to integration system", 37 sysAuthRefInput: model.IntegrationSystemReference, 38 expected: consumer.IntegrationSystem, 39 }, 40 { 41 name: "Error - Not exist reference", 42 sysAuthRefInput: "Not Exist", 43 expected: "", 44 expectedErr: errors.New("unknown reference object type"), 45 }, 46 } 47 48 for _, testCase := range testCases { 49 t.Run(testCase.name, func(t *testing.T) { 50 // WHEN 51 consumerType, err := consumer.MapSystemAuthToConsumerType(testCase.sysAuthRefInput) 52 // THEN 53 if err == nil { 54 require.NoError(t, testCase.expectedErr) 55 assert.Equal(t, consumerType, testCase.expected) 56 } else { 57 require.Error(t, testCase.expectedErr) 58 assert.EqualError(t, err, apperrors.NewInternalError("unknown reference object type").Error()) 59 } 60 }) 61 } 62 }