Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Azure/sql-action into dep…
Browse files Browse the repository at this point in the history
…endabot/npm_and_yarn/minimatch-3.1.2
  • Loading branch information
zijchen committed Dec 7, 2023
2 parents 3de5dd6 + da3c40e commit c9d64e2
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 150 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/check-lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ jobs:
- name: Check out
uses: actions/checkout@v3

- name: Copy the committed main.js file
run: mv lib/main.js /tmp

- name: Validate build
run: |
npm install
npm run build
- name: Check if main.js has differences
run: git diff --exit-code lib/main.js
run: git diff --ignore-all-space --exit-code lib/main.js /tmp/main.js
id: diff

# If main.js was different than expected, upload the actual version
Expand All @@ -24,4 +27,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: main.js
path: lib/index.js
path: lib/main.js
1 change: 1 addition & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
deploy:
environment: Automation test # this environment requires approval before running the action
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
Expand Down
31 changes: 27 additions & 4 deletions __tests__/AzureSqlAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('AzureSqlAction tests', () => {
describe('validate sqlpackage calls for DacpacAction', () => {
const inputs = [
['Publish', '/TargetTimeout:20'],
['Publish', '/p:DropObjectsNotInSource=true /p:BlockOnPossibleDataLoss=false /v:RELEASEVERSION="1.0.0"'],
['Script', '/DeployScriptPath:script.sql'],
['DriftReport', '/OutputPath:report.xml'],
['DeployReport', '/OutputPath:report.xml']
Expand Down Expand Up @@ -56,10 +57,10 @@ describe('AzureSqlAction tests', () => {
describe('sql script action tests for different auth types', () => {
// Format: [test case description, connection string, expected sqlcmd arguments]
const testCases = [
['SQL login', 'Server=testServer.database.windows.net;Database=testDB;User Id=testUser;Password=placeholder', '-S testServer.database.windows.net -d testDB -U "testUser" -i "./TestFile.sql" -t 20'],
['AAD password', 'Server=testServer.database.windows.net;Database=testDB;Authentication=Active Directory Password;User Id=testAADUser;Password=placeholder', '-S testServer.database.windows.net -d testDB --authentication-method=ActiveDirectoryPassword -U "testAADUser" -i "./TestFile.sql" -t 20'],
['AAD service principal', 'Server=testServer.database.windows.net;Database=testDB;Authentication=Active Directory Service Principal;User Id=appId;Password=placeholder', '-S testServer.database.windows.net -d testDB --authentication-method=ActiveDirectoryServicePrincipal -U "appId" -i "./TestFile.sql" -t 20'],
['AAD default', 'Server=testServer.database.windows.net;Database=testDB;Authentication=Active Directory Default;', '-S testServer.database.windows.net -d testDB --authentication-method=ActiveDirectoryDefault -i "./TestFile.sql" -t 20']
['SQL login', 'Server=testServer.database.windows.net;Database=testDB;User Id=testUser;Password=placeholder', '-S testServer.database.windows.net,1433 -d testDB -U "testUser" -i "./TestFile.sql" -t 20'],
['AAD password', 'Server=testServer.database.windows.net;Database=testDB;Authentication=Active Directory Password;User Id=testAADUser;Password=placeholder', '-S testServer.database.windows.net,1433 -d testDB --authentication-method=ActiveDirectoryPassword -U "testAADUser" -i "./TestFile.sql" -t 20'],
['AAD service principal', 'Server=testServer.database.windows.net;Database=testDB;Authentication=Active Directory Service Principal;User Id=appId;Password=placeholder', '-S testServer.database.windows.net,1433 -d testDB --authentication-method=ActiveDirectoryServicePrincipal -U "appId" -i "./TestFile.sql" -t 20'],
['AAD default', 'Server=testServer.database.windows.net;Database=testDB;Authentication=Active Directory Default;', '-S testServer.database.windows.net,1433 -d testDB --authentication-method=ActiveDirectoryDefault -i "./TestFile.sql" -t 20']
];

it.each(testCases)('%s', async (testCase, connectionString, expectedSqlCmdCall) => {
Expand All @@ -86,6 +87,28 @@ describe('AzureSqlAction tests', () => {
})
});

describe('sql script action tests for different port numbers', () => {
// Format: [test case description, connection string, expected sqlcmd arguments]
const testCases = [
['Default port', 'Server=testServer.database.windows.net;Database=testDB;User Id=testUser;Password=placeholder', '-S testServer.database.windows.net,1433 -d testDB -U "testUser" -i "./TestFile.sql" -t 20'],
['Custom port', 'Server=testServer.database.windows.net,1234;Database=testDB;User Id=testUser;Password=placeholder', '-S testServer.database.windows.net,1234 -d testDB -U "testUser" -i "./TestFile.sql" -t 20']
];

it.each(testCases)('%s', async (testCase, connectionString, expectedSqlCmdCall) => {
const inputs = getInputs(ActionType.SqlAction, connectionString) as IActionInputs;
const action = new AzureSqlAction(inputs);
const sqlcmdExe = process.platform === 'win32' ? 'sqlcmd.exe' : 'sqlcmd';

const execSpy = jest.spyOn(exec, 'exec').mockResolvedValue(0);
const exportVariableSpy = jest.spyOn(core, 'exportVariable').mockReturnValue();

await action.execute();

expect(execSpy).toHaveBeenCalledTimes(1);
expect(execSpy).toHaveBeenCalledWith(`"${sqlcmdExe}" ${expectedSqlCmdCall}`);
})
});

it('throws if SqlCmd.exe fails to execute sql', async () => {
let inputs = getInputs(ActionType.SqlAction) as IActionInputs;
let action = new AzureSqlAction(inputs);
Expand Down
14 changes: 8 additions & 6 deletions __tests__/SqlConnectionConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,20 @@ describe('SqlConnectionConfig tests', () => {
});

describe('parse server name in connection strings', () => {
// all server names will be 'test1.database.windows.net'
// servernames are optionally combined with tcp prefix, port number, and servername formats
const connectionStrings = [
[`Server=test1.database.windows.net;Database=testdb;User Id=user;Password=placeholder;Authentication=SQLPassword`, 'test1.database.windows.net', 'Validates server name without prefix'],
[`Server=tcp:test1.database.windows.net;Database=testdb;User Id=user;Password=placeholder;Authentication=SQLPassword`, 'test1.database.windows.net', 'Validates server name with tcp prefix'],
[`Server=tcp:test1.database.windows.net,1433;Database=testdb;User Id=user;Password=placeholder;Authentication=SQLPassword`, 'test1.database.windows.net', 'Validates server name with tcp prefix and port'],
[`Server=test1.database.windows.net,1433;Database=testdb;User Id=user;Password=placeholder;Authentication=SQLPassword`, 'test1.database.windows.net', 'Validates server name with no prefix and port'],
[`Server=test1.database.windows.net;Database=testdb;User Id=user;Password=placeholder;Authentication=SQLPassword`, 'test1.database.windows.net', '', 'Validates server name without prefix'],
[`Server=tcp:test1.database.windows.net;Database=testdb;User Id=user;Password=placeholder;Authentication=SQLPassword`, 'test1.database.windows.net', '', 'Validates server name with tcp prefix'],
[`Server=tcp:test1.database.windows.net,1433;Database=testdb;User Id=user;Password=placeholder;Authentication=SQLPassword`, 'test1.database.windows.net', '1433', 'Validates server name with tcp prefix and port'],
[`Server=database.windows.net,1433;Database=testdb;User Id=user;Password=placeholder;Authentication=SQLPassword`, 'database.windows.net', '1433', 'Validates server name with no prefix and port'],
[`Server=test2.20ee0ae768cc.database.windows.net,3342;Database=testdb;User Id=user;Password=placeholder;Authentication=SQLPassword`, 'test2.20ee0ae768cc.database.windows.net', '3342', 'Validates server name with no prefix and port'],
];

it.each(connectionStrings)('should parse server name successfully', (connectionStringInput, expectedServerName) => {
it.each(connectionStrings)('should parse server name successfully', (connectionStringInput, expectedServerName, expectedPortNumber) => {
const config = new SqlConnectionConfig(connectionStringInput);

expect(config.Config.server).toMatch(expectedServerName);
expect(config.Config.port?.toString()).toMatch(expectedPortNumber);
expect(config.Config.database).toMatch('testdb');
expect(config.ConnectionString).toMatch(connectionStringInput);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js

Large diffs are not rendered by default.

Loading

0 comments on commit c9d64e2

Please sign in to comment.