Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 47 additions & 129 deletions packages/core/src/test/codewhisperer/commands/transformByQ.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,48 @@ import { convertDateToTimestamp, convertToTimeString } from '../../../shared/dat

describe('transformByQ', function () {
let tempDir: string
const validSctFile = `<?xml version="1.0" encoding="UTF-8"?>
<tree>
<instances>
<ProjectModel>
<entities>
<sources>
<DbServer vendor="oracle" name="sample.rds.amazonaws.com">
</DbServer>
</sources>
<targets>
<DbServer vendor="aurora_postgresql" />
</targets>
</entities>
<relations>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema1"/>
<FullNameNodeInfo typeNode="table" nameNode="table1"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema2"/>
<FullNameNodeInfo typeNode="table" nameNode="table2"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema3"/>
<FullNameNodeInfo typeNode="table" nameNode="table3"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
</relations>
</ProjectModel>
</instances>
</tree>`

beforeEach(async function () {
tempDir = (await TestFolder.create()).path
Expand Down Expand Up @@ -401,49 +443,7 @@ describe('transformByQ', function () {
})

it(`WHEN validateMetadataFile on fully valid .sct file THEN passes validation`, async function () {
const sampleFileContents = `<?xml version="1.0" encoding="UTF-8"?>
<tree>
<instances>
<ProjectModel>
<entities>
<sources>
<DbServer vendor="oracle" name="sample.rds.amazonaws.com">
</DbServer>
</sources>
<targets>
<DbServer vendor="aurora_postgresql" />
</targets>
</entities>
<relations>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema1"/>
<FullNameNodeInfo typeNode="table" nameNode="table1"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema2"/>
<FullNameNodeInfo typeNode="table" nameNode="table2"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema3"/>
<FullNameNodeInfo typeNode="table" nameNode="table3"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
</relations>
</ProjectModel>
</instances>
</tree>`
const isValidMetadata = await validateSQLMetadataFile(sampleFileContents, { tabID: 'abc123' })
const isValidMetadata = await validateSQLMetadataFile(validSctFile, { tabID: 'abc123' })
assert.strictEqual(isValidMetadata, true)
assert.strictEqual(transformByQState.getSourceDB(), DB.ORACLE)
assert.strictEqual(transformByQState.getTargetDB(), DB.AURORA_POSTGRESQL)
Expand All @@ -455,96 +455,14 @@ describe('transformByQ', function () {
})

it(`WHEN validateMetadataFile on .sct file with unsupported source DB THEN fails validation`, async function () {
const sampleFileContents = `<?xml version="1.0" encoding="UTF-8"?>
<tree>
<instances>
<ProjectModel>
<entities>
<sources>
<DbServer vendor="not-oracle" name="sample.rds.amazonaws.com">
</DbServer>
</sources>
<targets>
<DbServer vendor="aurora_postgresql" />
</targets>
</entities>
<relations>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema1"/>
<FullNameNodeInfo typeNode="table" nameNode="table1"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema2"/>
<FullNameNodeInfo typeNode="table" nameNode="table2"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema3"/>
<FullNameNodeInfo typeNode="table" nameNode="table3"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
</relations>
</ProjectModel>
</instances>
</tree>`
const isValidMetadata = await validateSQLMetadataFile(sampleFileContents, { tabID: 'abc123' })
const sctFileWithInvalidSource = validSctFile.replace('oracle', 'not-oracle')
const isValidMetadata = await validateSQLMetadataFile(sctFileWithInvalidSource, { tabID: 'abc123' })
assert.strictEqual(isValidMetadata, false)
})

it(`WHEN validateMetadataFile on .sct file with unsupported target DB THEN fails validation`, async function () {
const sampleFileContents = `<?xml version="1.0" encoding="UTF-8"?>
<tree>
<instances>
<ProjectModel>
<entities>
<sources>
<DbServer vendor="oracle" name="sample.rds.amazonaws.com">
</DbServer>
</sources>
<targets>
<DbServer vendor="not-postgresql" />
</targets>
</entities>
<relations>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema1"/>
<FullNameNodeInfo typeNode="table" nameNode="table1"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema2"/>
<FullNameNodeInfo typeNode="table" nameNode="table2"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
<server-node-location>
<FullNameNodeInfoList>
<nameParts>
<FullNameNodeInfo typeNode="schema" nameNode="schema3"/>
<FullNameNodeInfo typeNode="table" nameNode="table3"/>
</nameParts>
</FullNameNodeInfoList>
</server-node-location>
</relations>
</ProjectModel>
</instances>
</tree>`
const isValidMetadata = await validateSQLMetadataFile(sampleFileContents, { tabID: 'abc123' })
const sctFileWithInvalidTarget = validSctFile.replace('aurora_postgresql', 'not-postgresql')
const isValidMetadata = await validateSQLMetadataFile(sctFileWithInvalidTarget, { tabID: 'abc123' })
assert.strictEqual(isValidMetadata, false)
})
})
Loading