forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add K8sService as channel and broker subscribers
- Loading branch information
1 parent
e6dbd1b
commit 275f3d4
Showing
6 changed files
with
118 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
frontend/packages/knative-plugin/src/components/pub-sub/__tests__/pub-sub-utils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
knativeServiceObj, | ||
sampleServices, | ||
} from '../../../topology/__tests__/topology-knative-test-data'; | ||
import { RESOURCE_KEY_SEPERATOR, craftResourceKey, getResourceNameFromKey } from '../pub-sub-utils'; | ||
|
||
describe('pub-sub-utils', () => { | ||
const service = sampleServices.data[0]; | ||
|
||
describe('craftResourceKey', () => { | ||
it('should return the name if the resource is not having kind and apiversion', () => { | ||
expect(craftResourceKey('test', { metadata: { name: '' } })).toBe( | ||
`${RESOURCE_KEY_SEPERATOR}test`, | ||
); | ||
}); | ||
|
||
it('should return undefined if the name is not passed', () => { | ||
expect(craftResourceKey('', { metadata: { name: '' } })).toBeUndefined(); | ||
}); | ||
|
||
it('should return a valid resource key', () => { | ||
expect(craftResourceKey('nodejs-ex', service)).toBe('core~v1~Service#nodejs-ex'); | ||
}); | ||
|
||
it('should differentiate k8s service and knative service', () => { | ||
expect(craftResourceKey('nodejs-ex', service)).toBe('core~v1~Service#nodejs-ex'); | ||
expect(craftResourceKey('nodejs-ex', knativeServiceObj)).toBe( | ||
'serving.knative.dev~v1~Service#nodejs-ex', | ||
); | ||
}); | ||
}); | ||
describe('getResourceNameFromKey', () => { | ||
it('should return the name of the resource from the resource key', () => { | ||
expect(getResourceNameFromKey(`${RESOURCE_KEY_SEPERATOR}test`)).toBe('test'); | ||
expect(getResourceNameFromKey(`core~v1~Service${RESOURCE_KEY_SEPERATOR}test`)).toBe('test'); | ||
expect( | ||
getResourceNameFromKey(`serving.knative.dev~v1~Service${RESOURCE_KEY_SEPERATOR}test`), | ||
).toBe('test'); | ||
}); | ||
|
||
it('should return empty string if invalid argument is passed', () => { | ||
expect(getResourceNameFromKey('')).toBe(''); | ||
expect(getResourceNameFromKey(null)).toBe(''); | ||
expect(getResourceNameFromKey(undefined)).toBe(''); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
frontend/packages/knative-plugin/src/components/pub-sub/pub-sub-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { FormikValues } from 'formik'; | ||
import { K8sResourceKind, referenceFor } from '@console/internal/module/k8s'; | ||
|
||
export const RESOURCE_KEY_SEPERATOR = '#'; | ||
|
||
export const craftResourceKey = (key: string, resource: K8sResourceKind): string | undefined => | ||
key ? `${referenceFor(resource)}${RESOURCE_KEY_SEPERATOR}${key}` : undefined; | ||
|
||
export const getResourceNameFromKey = (key: string): string => | ||
key?.split(RESOURCE_KEY_SEPERATOR).pop() ?? ''; | ||
|
||
export const sanitizeResourceName = (values: FormikValues): FormikValues => { | ||
const finalValues = { ...values }; | ||
finalValues.spec.subscriber.ref.name = getResourceNameFromKey(values.spec.subscriber.ref.name); | ||
return finalValues; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters