github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/systemfetcher/fixtures_test.go (about) 1 package systemfetcher_test 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/kyma-incubator/compass/components/director/internal/systemfetcher" 8 "github.com/kyma-incubator/compass/components/director/pkg/str" 9 "github.com/kyma-incubator/compass/components/director/pkg/tenant" 10 "github.com/stretchr/testify/require" 11 "github.com/tidwall/gjson" 12 13 "github.com/kyma-incubator/compass/components/director/internal/model" 14 ) 15 16 const ( 17 testExternal = "external" 18 testProvider = "Compass" 19 ) 20 21 func newModelBusinessTenantMapping(id, name string) *model.BusinessTenantMapping { 22 return &model.BusinessTenantMapping{ 23 ID: id, 24 Name: name, 25 ExternalTenant: testExternal, 26 Parent: "", 27 Type: tenant.Account, 28 Provider: testProvider, 29 Status: tenant.Active, 30 } 31 } 32 33 func fixInputValuesForSystem(t *testing.T, s systemfetcher.System) model.ApplicationFromTemplateInputValues { 34 systemPayload, err := json.Marshal(s.SystemPayload) 35 require.NoError(t, err) 36 return model.ApplicationFromTemplateInputValues{ 37 { 38 Placeholder: "name", 39 Value: gjson.GetBytes(systemPayload, "displayName").String(), 40 }, 41 } 42 } 43 44 func fixInputValuesForSystemWhichAppTemplateHasPlaceholders(t *testing.T, s systemfetcher.System) model.ApplicationFromTemplateInputValues { 45 systemPayload, err := json.Marshal(s.SystemPayload) 46 require.NoError(t, err) 47 return model.ApplicationFromTemplateInputValues{ 48 { 49 Placeholder: "name", 50 Value: gjson.GetBytes(systemPayload, "displayName").String(), 51 }, 52 } 53 } 54 55 func fixAppInputBySystem(t *testing.T, system systemfetcher.System) model.ApplicationRegisterInput { 56 systemPayload, err := json.Marshal(system.SystemPayload) 57 require.NoError(t, err) 58 59 initStatusCond := model.ApplicationStatusConditionInitial 60 return model.ApplicationRegisterInput{ 61 Name: gjson.GetBytes(systemPayload, "displayName").String(), 62 Description: str.Ptr(gjson.GetBytes(systemPayload, "productDescription").String()), 63 BaseURL: str.Ptr(gjson.GetBytes(systemPayload, "baseUrl").String()), 64 ProviderName: str.Ptr(gjson.GetBytes(systemPayload, "infrastructureProvider").String()), 65 SystemNumber: str.Ptr(gjson.GetBytes(systemPayload, "systemNumber").String()), 66 StatusCondition: &initStatusCond, 67 Labels: map[string]interface{}{ 68 "managed": "true", 69 }, 70 } 71 } 72 73 func fixWebhookModel(id string, whMode model.WebhookMode) model.Webhook { 74 return model.Webhook{ 75 ID: id, 76 ObjectID: id, 77 ObjectType: model.ApplicationWebhookReference, 78 Type: model.WebhookTypeConfigurationChanged, 79 Mode: &whMode, 80 } 81 }