-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
141 additions
and
121 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,62 @@ | ||
import * as fs from 'fs'; | ||
import * as semver from 'semver'; | ||
import AzureSqlActionHelper from "../src/AzureSqlActionHelper"; | ||
import AzureSqlAction, { IBuildAndPublishInputs, IDacpacActionInputs, ActionType, SqlPackageAction, IActionInputs } from "../src/AzureSqlAction"; | ||
import { getInputsWithCustomSqlPackageAction } from './AzureSqlAction.test'; | ||
|
||
jest.mock('fs'); | ||
|
||
describe('AzureSqlActionHelper tests', () => { | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
const versions = [ // returned from sqlpackage, validated version expected | ||
['162.3.563.1', '162.3.563'], // GA version | ||
['162.4.101.0', '162.4.101'], // GA version | ||
['162.3.562-preview', '162.3.562'], // preview version | ||
['15.0.5164.1', '15.0.5164'] // old version | ||
]; | ||
|
||
// checks parsing logic used from semver | ||
describe('tests semver parsing for potential sqlpackage version values', () => { | ||
it.each(versions)('should parse %s version correctly', (versionReturned, versionExpected) => { | ||
let semverExpected = semver.coerce(versionExpected); | ||
let semverTested = semver.coerce(versionReturned); | ||
|
||
expect(semverTested).toEqual(semverExpected); | ||
}); | ||
}); | ||
|
||
// checks sorting logic used from semver | ||
describe('tests sorting of versions to select latest version', () => { | ||
it('should select latest version', () => { | ||
let versionArray: semver.SemVer[] = []; | ||
versions.forEach(([versionReturned, versionExpected]) => { | ||
versionArray.push(semver.coerce(versionReturned) ?? new semver.SemVer('0.0.0')); | ||
}); | ||
|
||
let latestVersion = semver.rsort(versionArray)[0]; | ||
let latestVersionExpected = semver.coerce(versions[1][1]); | ||
|
||
expect(latestVersion).toEqual(latestVersionExpected); | ||
}); | ||
}); | ||
|
||
|
||
// ensures the sqlpackagepath input overrides the version check | ||
describe('sqlpackagepath input should override version check', () => { | ||
const sqlpackagepaths = ['//custom/path/to/sqlpackage', 'c:/Program Files/Sqlpackage/sqlpackage']; | ||
it.each(sqlpackagepaths)('should return sqlpackagepath if provided', (path) => { | ||
let inputs = getInputsWithCustomSqlPackageAction(ActionType.DacpacAction, SqlPackageAction['Publish'], '') as IDacpacActionInputs; | ||
inputs.sqlpackagePath = path; | ||
|
||
jest.spyOn(fs, "existsSync").mockReturnValue(true); | ||
let sqlpackagePath = AzureSqlActionHelper.getSqlPackagePath(inputs); | ||
|
||
expect(sqlpackagePath).toEqual(path); | ||
}); | ||
}); | ||
|
||
}); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.