|
1 | 1 | import {getVoidLogger} from '@backstage/backend-common'; |
2 | 2 | import {ApiEntity, ComponentEntity} from "@backstage/catalog-model"; |
3 | 3 |
|
4 | | -import {Broker, EventType, KnativeEventMeshProvider} from "./knativeEventMeshProvider"; |
| 4 | +import {Broker, EventType, KnativeEventMeshProvider, Source, Subscribable} from "./knativeEventMeshProvider"; |
5 | 5 | import {KnativeEventMeshProviderConfig} from "./types"; |
6 | 6 |
|
7 | 7 | describe('KnativeEventMeshProvider', () => { |
@@ -222,4 +222,211 @@ describe('KnativeEventMeshProvider', () => { |
222 | 222 |
|
223 | 223 | } |
224 | 224 | }); |
| 225 | + |
| 226 | + describe('buildSubscribableEntity', () => { |
| 227 | + const providerConfig:KnativeEventMeshProviderConfig = { |
| 228 | + id: 'test', |
| 229 | + baseUrl: 'http://example.com', |
| 230 | + schedule: undefined, |
| 231 | + }; |
| 232 | + |
| 233 | + const provider = new KnativeEventMeshProvider(providerConfig, logger, (null as any)); |
| 234 | + |
| 235 | + type TestCase = { |
| 236 | + name:string; |
| 237 | + input:Subscribable; |
| 238 | + expected:ComponentEntity; |
| 239 | + }; |
| 240 | + |
| 241 | + const testCases:TestCase[] = [ |
| 242 | + { |
| 243 | + name: 'minimal information', |
| 244 | + input: { |
| 245 | + name: 'test', |
| 246 | + namespace: 'test', |
| 247 | + uid: 'test', |
| 248 | + kind: 'test-kind', |
| 249 | + group: 'test-group', |
| 250 | + }, |
| 251 | + expected: { |
| 252 | + apiVersion: 'backstage.io/v1alpha1', |
| 253 | + kind: 'Component', |
| 254 | + metadata: { |
| 255 | + name: 'test', |
| 256 | + namespace: 'test', |
| 257 | + annotations: { |
| 258 | + "backstage.io/managed-by-location": "url:http://example.com", |
| 259 | + "backstage.io/managed-by-origin-location": "url:http://example.com", |
| 260 | + }, |
| 261 | + labels: {}, |
| 262 | + tags: [], |
| 263 | + }, |
| 264 | + spec: { |
| 265 | + type: 'test-group:test-kind', |
| 266 | + owner: 'knative', |
| 267 | + system: 'knative-event-mesh', |
| 268 | + lifecycle: 'test', |
| 269 | + providesApis: [], |
| 270 | + }, |
| 271 | + }, |
| 272 | + }, |
| 273 | + { |
| 274 | + name: 'all information', |
| 275 | + input: { |
| 276 | + name: 'test-subscribable', |
| 277 | + namespace: 'test-ns', |
| 278 | + uid: 'test-uid', |
| 279 | + labels: { |
| 280 | + "test-label": "test-label-value", |
| 281 | + }, |
| 282 | + annotations: { |
| 283 | + "test-annotation": "test-annotation-value", |
| 284 | + }, |
| 285 | + providedEventTypes: [ |
| 286 | + "test-ns/test-type", |
| 287 | + ], |
| 288 | + kind: "test-kind", |
| 289 | + group: "test-group", |
| 290 | + }, |
| 291 | + expected: { |
| 292 | + apiVersion: 'backstage.io/v1alpha1', |
| 293 | + kind: 'Component', |
| 294 | + metadata: { |
| 295 | + name: 'test-subscribable', |
| 296 | + namespace: 'test-ns', |
| 297 | + annotations: { |
| 298 | + "test-annotation": "test-annotation-value", |
| 299 | + "backstage.io/managed-by-location": "url:http://example.com", |
| 300 | + "backstage.io/managed-by-origin-location": "url:http://example.com", |
| 301 | + }, |
| 302 | + labels: { |
| 303 | + "test-label": "test-label-value", |
| 304 | + }, |
| 305 | + tags: [], |
| 306 | + }, |
| 307 | + spec: { |
| 308 | + type: 'test-group:test-kind', |
| 309 | + owner: 'knative', |
| 310 | + system: 'knative-event-mesh', |
| 311 | + lifecycle: 'test', |
| 312 | + providesApis: [ |
| 313 | + "api:test-ns/test-type" |
| 314 | + ], |
| 315 | + }, |
| 316 | + }, |
| 317 | + } |
| 318 | + ]; |
| 319 | + |
| 320 | + for (const testCase of testCases) { |
| 321 | + test(`Name: ${testCase.name}`, async () => { |
| 322 | + const result = provider.buildSubscribableEntity(testCase.input); |
| 323 | + expect(result).toEqual(testCase.expected); |
| 324 | + }); |
| 325 | + |
| 326 | + } |
| 327 | + }); |
| 328 | + |
| 329 | + describe('buildSourceEntity', () => { |
| 330 | + const providerConfig:KnativeEventMeshProviderConfig = { |
| 331 | + id: 'test', |
| 332 | + baseUrl: 'http://example.com', |
| 333 | + schedule: undefined, |
| 334 | + }; |
| 335 | + |
| 336 | + const provider = new KnativeEventMeshProvider(providerConfig, logger, (null as any)); |
| 337 | + |
| 338 | + type TestCase = { |
| 339 | + name:string; |
| 340 | + input:Source; |
| 341 | + expected:ComponentEntity; |
| 342 | + }; |
| 343 | + |
| 344 | + const testCases:TestCase[] = [ |
| 345 | + { |
| 346 | + name: 'minimal information', |
| 347 | + input: { |
| 348 | + name: 'test', |
| 349 | + namespace: 'test', |
| 350 | + uid: 'test', |
| 351 | + group: 'test-group', |
| 352 | + kind: 'test-kind', |
| 353 | + }, |
| 354 | + expected: { |
| 355 | + apiVersion: 'backstage.io/v1alpha1', |
| 356 | + kind: 'Component', |
| 357 | + metadata: { |
| 358 | + name: 'test', |
| 359 | + namespace: 'test', |
| 360 | + annotations: { |
| 361 | + "backstage.io/managed-by-location": "url:http://example.com", |
| 362 | + "backstage.io/managed-by-origin-location": "url:http://example.com", |
| 363 | + }, |
| 364 | + labels: {}, |
| 365 | + tags: [], |
| 366 | + }, |
| 367 | + spec: { |
| 368 | + type: 'test-group:test-kind', |
| 369 | + owner: 'knative', |
| 370 | + system: 'knative-event-mesh', |
| 371 | + lifecycle: 'test', |
| 372 | + providesApis: [], |
| 373 | + }, |
| 374 | + }, |
| 375 | + }, |
| 376 | + { |
| 377 | + name: 'all information', |
| 378 | + input: { |
| 379 | + name: 'test-source', |
| 380 | + namespace: 'test-ns', |
| 381 | + uid: 'test-uid', |
| 382 | + labels: { |
| 383 | + "test-label": "test-label-value", |
| 384 | + }, |
| 385 | + annotations: { |
| 386 | + "test-annotation": "test-annotation-value", |
| 387 | + }, |
| 388 | + providedEventTypes: [ |
| 389 | + "test-ns/test-type", |
| 390 | + ], |
| 391 | + group: "test-group", |
| 392 | + kind: "test-kind", |
| 393 | + }, |
| 394 | + expected: { |
| 395 | + apiVersion: 'backstage.io/v1alpha1', |
| 396 | + kind: 'Component', |
| 397 | + metadata: { |
| 398 | + name: 'test-source', |
| 399 | + namespace: 'test-ns', |
| 400 | + annotations: { |
| 401 | + "test-annotation": "test-annotation-value", |
| 402 | + "backstage.io/managed-by-location": "url:http://example.com", |
| 403 | + "backstage.io/managed-by-origin-location": "url:http://example.com", |
| 404 | + }, |
| 405 | + labels: { |
| 406 | + "test-label": "test-label-value", |
| 407 | + }, |
| 408 | + tags: [], |
| 409 | + }, |
| 410 | + spec: { |
| 411 | + type: 'test-group:test-kind', |
| 412 | + owner: 'knative', |
| 413 | + system: 'knative-event-mesh', |
| 414 | + lifecycle: 'test', |
| 415 | + providesApis: [ |
| 416 | + "api:test-ns/test-type" |
| 417 | + ], |
| 418 | + }, |
| 419 | + }, |
| 420 | + } |
| 421 | + ]; |
| 422 | + |
| 423 | + for (const testCase of testCases) { |
| 424 | + test(`Name: ${testCase.name}`, async () => { |
| 425 | + const result = provider.buildSourceEntity(testCase.input); |
| 426 | + expect(result).toEqual(testCase.expected); |
| 427 | + }); |
| 428 | + |
| 429 | + } |
| 430 | + }); |
| 431 | + |
225 | 432 | }); |
0 commit comments