github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/repo/fixtures_test.go (about) 1 package repo_test 2 3 import ( 4 "github.com/kyma-incubator/compass/components/director/pkg/resource" 5 "github.com/pkg/errors" 6 ) 7 8 const ( 9 userTableName = "users" 10 appTableName = "apps" 11 bundlesTableName = "bundles" 12 webhooksTableName = "webhooks" 13 biaTableName = "bia" 14 15 appID = "appID" 16 appID2 = "appID2" 17 appName = "appName" 18 appName2 = "appName" 19 appDescription = "appDesc" 20 appDescription2 = "appDesc" 21 22 bundleID = "bundleID" 23 bundleName = "bundleName" 24 bundleDescription = "bundleDesc" 25 26 biaID = "biaID" 27 biaName = "biaName" 28 biaDescription = "biaDesc" 29 30 whID = "whID" 31 ftID = "ftID" 32 33 userID = "given_id" 34 tenantID = "75093633-1578-497f-890a-d438a74a4127" 35 firstName = "given_first_name" 36 lastName = "given_last_name" 37 age = 55 38 39 tenantIsolationConditionWithoutOwnerCheckFmt = "(id IN (SELECT id FROM %s WHERE tenant_id = %s))" 40 tenantIsolationConditionWithOwnerCheckFmt = "(id IN (SELECT id FROM %s WHERE tenant_id = %s AND owner = true))" 41 tenantIsolationConditionForBIA = "(id IN (SELECT id FROM %s WHERE tenant_id = %s AND owner = true) OR owner_id = %s)" 42 ) 43 44 var fixUser = User{ 45 ID: userID, 46 Tenant: tenantID, 47 FirstName: firstName, 48 LastName: lastName, 49 Age: age, 50 } 51 52 var fixApp = &App{ 53 ID: appID, 54 Name: appName, 55 Description: appDescription, 56 } 57 58 var fixApp2 = &App{ 59 ID: appID2, 60 Name: appName, 61 Description: appDescription, 62 } 63 64 var fixBundle = &Bundle{ 65 ID: bundleID, 66 Name: bundleName, 67 Description: bundleDescription, 68 AppID: appID, 69 } 70 71 var fixBIA = &BundleInstanceAuth{ 72 ID: biaID, 73 Name: biaName, 74 Description: biaDescription, 75 OwnerID: tenantID, 76 BundleID: bundleID, 77 } 78 79 var fixWebhook = &Webhook{ 80 ID: whID, 81 FormationTemplateID: ftID, 82 } 83 84 // User is a exemplary type to test generic Repositories 85 type User struct { 86 ID string `db:"id"` 87 Tenant string `db:"tenant_id"` 88 FirstName string `db:"first_name"` 89 LastName string `db:"last_name"` 90 Age int 91 } 92 93 func (a User) GetID() string { 94 return a.ID 95 } 96 97 const UserType = resource.Type("UserType") 98 99 type UserCollection []User 100 101 func (u UserCollection) Len() int { 102 return len(u) 103 } 104 105 type App struct { 106 ID string `db:"id"` 107 Name string `db:"name"` 108 Description string `db:"description"` 109 } 110 111 func (a *App) GetID() string { 112 return a.ID 113 } 114 115 var appColumns = []string{"id", "name", "description"} 116 117 type AppCollection []App 118 119 func (a AppCollection) Len() int { 120 return len(a) 121 } 122 123 func (a *App) DecorateWithTenantID(tenant string) interface{} { 124 return struct { 125 *App 126 TenantID string `db:"tenant_id"` 127 }{ 128 App: a, 129 TenantID: tenant, 130 } 131 } 132 133 type Bundle struct { 134 ID string `db:"id"` 135 Name string `db:"name"` 136 Description string `db:"description"` 137 AppID string `db:"app_id"` 138 } 139 140 func (a *Bundle) GetID() string { 141 return a.ID 142 } 143 144 func (a *Bundle) GetParent(_ resource.Type) (resource.Type, string) { 145 return resource.Application, a.AppID 146 } 147 148 func (a *Bundle) DecorateWithTenantID(tenant string) interface{} { 149 return struct { 150 *Bundle 151 TenantID string `db:"tenant_id"` 152 }{ 153 Bundle: a, 154 TenantID: tenant, 155 } 156 } 157 158 var bundleColumns = []string{"id", "name", "description", "app_id"} 159 var webhookColumns = []string{"id", "formation_template_id"} 160 161 type Webhook struct { 162 ID string `db:"id"` 163 FormationTemplateID string `db:"formation_template_id"` 164 } 165 166 func (w *Webhook) GetID() string { 167 return w.ID 168 } 169 170 func (w *Webhook) GetParent(_ resource.Type) (resource.Type, string) { 171 return resource.FormationTemplate, w.FormationTemplateID 172 } 173 174 type BundleInstanceAuth struct { 175 ID string `db:"id"` 176 Name string `db:"name"` 177 Description string `db:"description"` 178 OwnerID string `db:"owner_id"` 179 BundleID string `db:"bundle_id"` 180 } 181 182 func (a *BundleInstanceAuth) GetID() string { 183 return a.ID 184 } 185 186 func (a *BundleInstanceAuth) GetParent(_ resource.Type) (resource.Type, string) { 187 return resource.Bundle, a.BundleID 188 } 189 190 func (a *BundleInstanceAuth) DecorateWithTenantID(tenant string) interface{} { 191 return struct { 192 *BundleInstanceAuth 193 TenantID string `db:"tenant_id"` 194 }{ 195 BundleInstanceAuth: a, 196 TenantID: tenant, 197 } 198 } 199 200 func someError() error { 201 return errors.New("some error") 202 }