|
1 | 1 | import React from 'react';
|
2 | 2 |
|
3 | 3 | import { createDevApp } from '@backstage/dev-utils';
|
| 4 | +import { TestApiProvider } from '@backstage/test-utils'; |
4 | 5 |
|
| 6 | +import { |
| 7 | + openshiftImageRegistryApiRef, |
| 8 | + OpenshiftImageRegistryApiV1, |
| 9 | +} from '../src/api'; |
5 | 10 | import {
|
6 | 11 | OpenshiftImageRegistryPage,
|
7 | 12 | openshiftImageRegistryPlugin,
|
8 | 13 | } from '../src/plugin';
|
| 14 | +// Contains just the openshift namespace for now |
| 15 | +import namespaces from './namespaces.json'; |
| 16 | +// Extracted from an OpenShift 4.13 cluster, reduced to Go, Java, Node.js and Python entries |
| 17 | +// oc get -n openshift \ |
| 18 | +// imagestream/golang \ |
| 19 | +// imagestream/java \ |
| 20 | +// imagestream/nodejs \ |
| 21 | +// imagestream/python \ |
| 22 | +// -o json | jq . \ |
| 23 | +// > plugins/openshift-image-registry/dev/openshift-imagestreams.json |
| 24 | +import openshiftImageStreams from './openshift-imagestreams.json'; |
| 25 | +// The origin list view doesn't contain all neccessary infomation, so this list view |
| 26 | +// is build from three API calls to match the data in openshift-imagestreams.json |
| 27 | +// |
| 28 | +// oc get -n openshift \ |
| 29 | +// imagestreamtag/golang:1.18-ubi7 \ |
| 30 | +// imagestreamtag/java:11 \ |
| 31 | +// imagestreamtag/nodejs:14-ubi7 \ |
| 32 | +// imagestreamtag/python:2.7-ubi8 \ |
| 33 | +// -o json | jq . \ |
| 34 | +// > plugins/openshift-image-registry/dev/openshift-imagestreamtags.json |
| 35 | +import openshiftImageStreamTags from './openshift-imagestreamtags.json'; |
| 36 | + |
| 37 | +class MockOpenshiftImageRegistryApi implements OpenshiftImageRegistryApiV1 { |
| 38 | + async getAllImageStreams(): Promise<any> { |
| 39 | + return openshiftImageStreams.items; |
| 40 | + } |
| 41 | + async getImageStreams(ns: string): Promise<any> { |
| 42 | + return openshiftImageStreams.items.filter( |
| 43 | + item => item.metadata.namespace === ns, |
| 44 | + ); |
| 45 | + } |
| 46 | + async getImageStream(ns: string, imageName: string): Promise<any> { |
| 47 | + return openshiftImageStreams.items.find( |
| 48 | + item => |
| 49 | + item.metadata.namespace === ns && item.metadata.name === imageName, |
| 50 | + ); |
| 51 | + } |
| 52 | + async getImageStreamTags(ns: string, imageName: string): Promise<any> { |
| 53 | + if (imageName.includes(':')) { |
| 54 | + return openshiftImageStreamTags.items.find( |
| 55 | + item => |
| 56 | + item.metadata.namespace === ns && item.metadata.name === imageName, |
| 57 | + ); |
| 58 | + } |
| 59 | + return openshiftImageStreamTags.items.find( |
| 60 | + item => |
| 61 | + item.metadata.namespace === ns && |
| 62 | + (item.metadata.name === imageName || |
| 63 | + item.metadata.name.startsWith(`${imageName}:`)), |
| 64 | + ); |
| 65 | + } |
| 66 | + async getImageStreamTag( |
| 67 | + ns: string, |
| 68 | + imageName: string, |
| 69 | + tag: string, |
| 70 | + ): Promise<any> { |
| 71 | + return openshiftImageStreamTags.items.find( |
| 72 | + item => |
| 73 | + item.metadata.namespace === ns && |
| 74 | + item.metadata.name === `${imageName}:${tag}`, |
| 75 | + ); |
| 76 | + } |
| 77 | + async getNamespaces(): Promise<any> { |
| 78 | + return namespaces.items; |
| 79 | + } |
| 80 | +} |
9 | 81 |
|
10 | 82 | createDevApp()
|
11 | 83 | .registerPlugin(openshiftImageRegistryPlugin)
|
12 | 84 | .addPage({
|
13 |
| - element: <OpenshiftImageRegistryPage />, |
14 |
| - title: 'Root Page', |
| 85 | + element: ( |
| 86 | + <TestApiProvider |
| 87 | + apis={[ |
| 88 | + [openshiftImageRegistryApiRef, new MockOpenshiftImageRegistryApi()], |
| 89 | + ]} |
| 90 | + > |
| 91 | + <OpenshiftImageRegistryPage /> |
| 92 | + </TestApiProvider> |
| 93 | + ), |
| 94 | + title: 'Image Registry', |
15 | 95 | path: '/openshift-image-registry',
|
16 | 96 | })
|
17 | 97 | .render();
|
0 commit comments