github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/runtime/fixtures_test.go (about) 1 package runtime_test 2 3 import ( 4 "net/url" 5 "testing" 6 "time" 7 8 pkgmodel "github.com/kyma-incubator/compass/components/director/pkg/model" 9 10 "github.com/kyma-incubator/compass/components/director/internal/domain/runtime" 11 "github.com/kyma-incubator/compass/components/director/internal/repo" 12 13 "github.com/kyma-incubator/compass/components/director/internal/model" 14 "github.com/kyma-incubator/compass/components/director/pkg/graphql" 15 "github.com/kyma-incubator/compass/components/director/pkg/pagination" 16 "github.com/stretchr/testify/require" 17 ) 18 19 const ( 20 tenantID = "b91b59f7-2563-40b2-aba9-fef726037aa3" 21 runtimeID = "runtimeID" 22 runtimeType = "runtimeType" 23 ) 24 25 var fixColumns = []string{"id", "name", "description", "status_condition", "status_timestamp", "creation_timestamp", "application_namespace"} 26 27 func fixRuntimePage(runtimes []*model.Runtime) *model.RuntimePage { 28 return &model.RuntimePage{ 29 Data: runtimes, 30 PageInfo: &pagination.Page{ 31 StartCursor: "start", 32 EndCursor: "end", 33 HasNextPage: false, 34 }, 35 TotalCount: len(runtimes), 36 } 37 } 38 39 func fixGQLRuntimePage(runtimes []*graphql.Runtime) *graphql.RuntimePage { 40 return &graphql.RuntimePage{ 41 Data: runtimes, 42 PageInfo: &graphql.PageInfo{ 43 StartCursor: "start", 44 EndCursor: "end", 45 HasNextPage: false, 46 }, 47 TotalCount: len(runtimes), 48 } 49 } 50 51 func fixModelRuntime(t *testing.T, id, tenant, name, description, appNamespace string) *model.Runtime { 52 time, err := time.Parse(time.RFC3339, "2002-10-02T10:00:00-05:00") 53 require.NoError(t, err) 54 55 return &model.Runtime{ 56 ID: id, 57 Status: &model.RuntimeStatus{ 58 Condition: model.RuntimeStatusConditionInitial, 59 }, 60 Name: name, 61 Description: &description, 62 CreationTimestamp: time, 63 ApplicationNamespace: &appNamespace, 64 } 65 } 66 67 func fixGQLRuntime(t *testing.T, id, name, description, appNamespace string) *graphql.Runtime { 68 time, err := time.Parse(time.RFC3339, "2002-10-02T10:00:00-05:00") 69 require.NoError(t, err) 70 71 return &graphql.Runtime{ 72 ID: id, 73 Status: &graphql.RuntimeStatus{ 74 Condition: graphql.RuntimeStatusConditionInitial, 75 }, 76 Name: name, 77 Description: &description, 78 Metadata: &graphql.RuntimeMetadata{ 79 CreationTimestamp: graphql.Timestamp(time), 80 }, 81 ApplicationNamespace: &appNamespace, 82 } 83 } 84 85 func fixDetailedModelRuntime(t *testing.T, id, name, description, appNamespace string) *model.Runtime { 86 time, err := time.Parse(time.RFC3339, "2002-10-02T10:00:00-05:00") 87 require.NoError(t, err) 88 89 return &model.Runtime{ 90 ID: id, 91 Status: &model.RuntimeStatus{ 92 Condition: model.RuntimeStatusConditionInitial, 93 Timestamp: time, 94 }, 95 Name: name, 96 Description: &description, 97 CreationTimestamp: time, 98 ApplicationNamespace: &appNamespace, 99 } 100 } 101 102 func fixDetailedEntityRuntime(t *testing.T, id, name, description, appNamespace string) *runtime.Runtime { 103 time, err := time.Parse(time.RFC3339, "2002-10-02T10:00:00-05:00") 104 require.NoError(t, err) 105 106 return &runtime.Runtime{ 107 ID: id, 108 StatusCondition: string(model.RuntimeStatusConditionInitial), 109 StatusTimestamp: time, 110 Name: name, 111 Description: repo.NewValidNullableString(description), 112 CreationTimestamp: time, 113 ApplicationNamespace: repo.NewValidNullableString(appNamespace), 114 } 115 } 116 117 func fixDetailedGQLRuntime(t *testing.T, id, name, description, appNamespace string) *graphql.Runtime { 118 time, err := time.Parse(time.RFC3339, "2002-10-02T10:00:00-05:00") 119 require.NoError(t, err) 120 121 return &graphql.Runtime{ 122 ID: id, 123 Status: &graphql.RuntimeStatus{ 124 Condition: graphql.RuntimeStatusConditionInitial, 125 Timestamp: graphql.Timestamp(time), 126 }, 127 Name: name, 128 Description: &description, 129 Metadata: &graphql.RuntimeMetadata{ 130 CreationTimestamp: graphql.Timestamp(time), 131 }, 132 ApplicationNamespace: &appNamespace, 133 } 134 } 135 136 func fixModelRuntimeRegisterInput(name, description, appNamespace string, webhooks []*model.WebhookInput) model.RuntimeRegisterInput { 137 return model.RuntimeRegisterInput{ 138 Name: name, 139 Description: &description, 140 Labels: map[string]interface{}{ 141 "test": []string{"val", "val2"}, 142 }, 143 Webhooks: webhooks, 144 ApplicationNamespace: &appNamespace, 145 } 146 } 147 148 func fixGQLRuntimeRegisterInput(name, description, appNamespace string, webhooks []*graphql.WebhookInput) graphql.RuntimeRegisterInput { 149 labels := graphql.Labels{ 150 "test": []string{"val", "val2"}, 151 } 152 153 return graphql.RuntimeRegisterInput{ 154 Name: name, 155 Description: &description, 156 Labels: labels, 157 Webhooks: webhooks, 158 ApplicationNamespace: &appNamespace, 159 } 160 } 161 162 func fixModelRuntimeUpdateInput(name, description string) model.RuntimeUpdateInput { 163 return model.RuntimeUpdateInput{ 164 Name: name, 165 Description: &description, 166 Labels: map[string]interface{}{ 167 "test": []string{"val", "val2"}, 168 }, 169 } 170 } 171 172 func fixGQLRuntimeUpdateInput(name, description string) graphql.RuntimeUpdateInput { 173 labels := graphql.Labels{ 174 "test": []string{"val", "val2"}, 175 } 176 177 return graphql.RuntimeUpdateInput{ 178 Name: name, 179 Description: &description, 180 Labels: labels, 181 } 182 } 183 184 func fixModelAuth() *model.Auth { 185 return &model.Auth{ 186 Credential: model.CredentialData{ 187 Basic: &model.BasicCredentialData{ 188 Username: "foo", 189 Password: "bar", 190 }, 191 }, 192 AdditionalHeaders: map[string][]string{"test": {"foo", "bar"}}, 193 AdditionalQueryParams: map[string][]string{"test": {"foo", "bar"}}, 194 RequestAuth: &model.CredentialRequestAuth{ 195 Csrf: &model.CSRFTokenCredentialRequestAuth{ 196 TokenEndpointURL: "foo.url", 197 Credential: model.CredentialData{ 198 Basic: &model.BasicCredentialData{ 199 Username: "boo", 200 Password: "far", 201 }, 202 }, 203 AdditionalHeaders: map[string][]string{"test": {"foo", "bar"}}, 204 AdditionalQueryParams: map[string][]string{"test": {"foo", "bar"}}, 205 }, 206 }, 207 } 208 } 209 210 func fixGQLAuth() *graphql.Auth { 211 return &graphql.Auth{ 212 Credential: &graphql.BasicCredentialData{ 213 Username: "foo", 214 Password: "bar", 215 }, 216 AdditionalHeaders: graphql.HTTPHeaders{"test": {"foo", "bar"}}, 217 AdditionalQueryParams: graphql.QueryParams{"test": {"foo", "bar"}}, 218 RequestAuth: &graphql.CredentialRequestAuth{ 219 Csrf: &graphql.CSRFTokenCredentialRequestAuth{ 220 TokenEndpointURL: "foo.url", 221 Credential: &graphql.BasicCredentialData{ 222 Username: "boo", 223 Password: "far", 224 }, 225 AdditionalHeaders: graphql.HTTPHeaders{"test": {"foo", "bar"}}, 226 AdditionalQueryParams: graphql.QueryParams{"test": {"foo", "bar"}}, 227 }, 228 }, 229 } 230 } 231 232 func fixModelSystemAuth(id, tenant, runtimeID string, auth *model.Auth) pkgmodel.SystemAuth { 233 return pkgmodel.SystemAuth{ 234 ID: id, 235 TenantID: &tenant, 236 RuntimeID: &runtimeID, 237 Value: auth, 238 } 239 } 240 241 func fixGQLSystemAuth(id string, auth *graphql.Auth) *graphql.RuntimeSystemAuth { 242 return &graphql.RuntimeSystemAuth{ 243 ID: id, 244 Auth: auth, 245 } 246 } 247 248 func fixModelRuntimeEventingConfiguration(t *testing.T, rawURL string) *model.RuntimeEventingConfiguration { 249 validURL := fixValidURL(t, rawURL) 250 return &model.RuntimeEventingConfiguration{ 251 EventingConfiguration: model.EventingConfiguration{ 252 DefaultURL: validURL, 253 }, 254 } 255 } 256 257 func fixGQLRuntimeEventingConfiguration(url string) *graphql.RuntimeEventingConfiguration { 258 return &graphql.RuntimeEventingConfiguration{ 259 DefaultURL: url, 260 } 261 } 262 263 func fixValidURL(t *testing.T, rawURL string) url.URL { 264 eventingURL, err := url.Parse(rawURL) 265 require.NoError(t, err) 266 require.NotNil(t, eventingURL) 267 return *eventingURL 268 } 269 270 func fixModelRuntimeContext(id, runtimeID, key, val string) *model.RuntimeContext { 271 return &model.RuntimeContext{ 272 ID: id, 273 RuntimeID: runtimeID, 274 Key: key, 275 Value: val, 276 } 277 } 278 279 func fixGqlRuntimeContext(id, key, val string) *graphql.RuntimeContext { 280 return &graphql.RuntimeContext{ 281 ID: id, 282 Key: key, 283 Value: val, 284 } 285 } 286 287 func fixGQLRtmCtxPage(rtmCtxs []*graphql.RuntimeContext) *graphql.RuntimeContextPage { 288 return &graphql.RuntimeContextPage{ 289 Data: rtmCtxs, 290 PageInfo: &graphql.PageInfo{ 291 StartCursor: "start", 292 EndCursor: "end", 293 HasNextPage: false, 294 }, 295 TotalCount: len(rtmCtxs), 296 } 297 } 298 299 func fixRtmCtxPage(rtmCtxs []*model.RuntimeContext) *model.RuntimeContextPage { 300 return &model.RuntimeContextPage{ 301 Data: rtmCtxs, 302 PageInfo: &pagination.Page{ 303 StartCursor: "start", 304 EndCursor: "end", 305 HasNextPage: false, 306 }, 307 TotalCount: len(rtmCtxs), 308 } 309 } 310 311 func givenTenant() string { 312 return "8f237125-50be-4bb4-96ce-389e2b931f46" 313 }