-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(v2/frontend): integrate ML Metadata tab with v2 metadata (#5308)
* chore(v2/frontend): integrate ML Metadata tab with v2 metadata * fix test * test: add unit tests for getContextByTypeAndName
- Loading branch information
Showing
5 changed files
with
140 additions
and
29 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
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,86 @@ | ||
import { | ||
Api, | ||
Context, | ||
GetContextByTypeAndNameRequest, | ||
GetContextByTypeAndNameResponse, | ||
} from '@kubeflow/frontend'; | ||
import { expectWarnings, testBestPractices } from 'src/TestUtils'; | ||
import { Workflow, WorkflowSpec, WorkflowStatus } from 'third_party/argo-ui/argo_template'; | ||
import { getRunContext } from './MlmdUtils'; | ||
|
||
testBestPractices(); | ||
|
||
const WORKFLOW_NAME = 'run-st448'; | ||
const WORKFLOW_EMPTY: Workflow = { | ||
metadata: { | ||
name: WORKFLOW_NAME, | ||
}, | ||
// there are many unrelated fields here, omit them | ||
spec: {} as WorkflowSpec, | ||
status: {} as WorkflowStatus, | ||
}; | ||
|
||
const V2_CONTEXT = new Context(); | ||
V2_CONTEXT.setName(WORKFLOW_NAME); | ||
V2_CONTEXT.setType('kfp.PipelineRun'); | ||
|
||
const TFX_CONTEXT = new Context(); | ||
TFX_CONTEXT.setName('run.run-st448'); | ||
TFX_CONTEXT.setType('run'); | ||
|
||
const V1_CONTEXT = new Context(); | ||
V1_CONTEXT.setName(WORKFLOW_NAME); | ||
V1_CONTEXT.setType('KfpRun'); | ||
|
||
describe('MlmdUtils', () => { | ||
describe('getRunContext', () => { | ||
it('gets KFP v2 context', async () => { | ||
mockGetContextByTypeAndName([V2_CONTEXT]); | ||
const context = await getRunContext({ | ||
...WORKFLOW_EMPTY, | ||
metadata: { | ||
...WORKFLOW_EMPTY.metadata, | ||
annotations: { 'pipelines.kubeflow.org/v2_pipeline': 'true' }, | ||
}, | ||
}); | ||
expect(context).toEqual(V2_CONTEXT); | ||
}); | ||
|
||
it('gets TFX context', async () => { | ||
mockGetContextByTypeAndName([TFX_CONTEXT, V1_CONTEXT]); | ||
const context = await getRunContext(WORKFLOW_EMPTY); | ||
expect(context).toEqual(TFX_CONTEXT); | ||
}); | ||
|
||
it('gets KFP v1 context', async () => { | ||
const verify = expectWarnings(); | ||
mockGetContextByTypeAndName([V1_CONTEXT]); | ||
const context = await getRunContext(WORKFLOW_EMPTY); | ||
expect(context).toEqual(V1_CONTEXT); | ||
verify(); | ||
}); | ||
|
||
it('throws error when not found', async () => { | ||
const verify = expectWarnings(); | ||
mockGetContextByTypeAndName([]); | ||
await expect(getRunContext(WORKFLOW_EMPTY)).rejects.toThrow(); | ||
verify(); | ||
}); | ||
}); | ||
}); | ||
|
||
function mockGetContextByTypeAndName(contexts: Context[]) { | ||
const getContextByTypeAndNameSpy = jest.spyOn( | ||
Api.getInstance().metadataStoreService, | ||
'getContextByTypeAndName', | ||
); | ||
getContextByTypeAndNameSpy.mockImplementation((req: GetContextByTypeAndNameRequest) => { | ||
const response = new GetContextByTypeAndNameResponse(); | ||
const found = contexts.find( | ||
context => | ||
context.getType() === req.getTypeName() && context.getName() === req.getContextName(), | ||
); | ||
response.setContext(found); | ||
return response; | ||
}); | ||
} |
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
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