Skip to content

Commit

Permalink
test: use a JavaScript based config file format (tediousjs#1634)
Browse files Browse the repository at this point in the history
Co-authored-by: mShan0 <[email protected]>
Co-authored-by: Michael Sun <[email protected]>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent 1a703e2 commit 3cd7e86
Show file tree
Hide file tree
Showing 22 changed files with 578 additions and 443 deletions.
130 changes: 28 additions & 102 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,8 @@ jobs:
docker-compose -f "test/docker-compose.linux.yml" up --detach
- name: Set up CI configuration
run: |
mkdir ~/.tedious
echo '{
"config": {
"server": "localhost",
"authentication": {
"type": "default",
"options": {
"userName": "sa",
"password": "yourStrong(!)Password"
}
},
"options": {
"port": 1433,
"database": "master",
"encrypt": true
}
}
}' | jq --arg certificate "$(cat ./test/fixtures/mssql.crt)" '.config.options.cryptoCredentialsDetails.ca |= $certificate' > ~/.tedious/test-connection.json
shell: bash
run: cp -f test/config.ci.ts test/config.ts

- name: Upgrade npm
run: npm install -g npm
Expand Down Expand Up @@ -267,26 +249,7 @@ jobs:
- name: Set up CI configuration
shell: bash
run: |
mkdir ~/.tedious
echo '{
"config": {
"server": "localhost",
"authentication": {
"type": "default",
"options": {
"userName": "sa",
"password": "yourStrong(!)Password"
}
},
"options": {
"port": 1433,
"database": "master",
"trustServerCertificate": true
}
}
}' | jq --arg certificate "$(cat ./test/fixtures/mssql.crt)" '.config.options.cryptoCredentialsDetails.ca |= $certificate' > ~/.tedious/test-connection.json
run: cp -f test/config.ci.ts test/config.ts

- name: Upgrade npm
run: npm install -g npm
Expand Down Expand Up @@ -383,29 +346,18 @@ jobs:
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci

- run: mkdir ~/.tedious
- name: Set up CI configuration
shell: bash
run: cp -f test/config.azure-default.ts test/config.ts

- name: Set up CI configuration (SQL Authentication)
run: |
echo '{
"config": {
"server": "${{ secrets.AZURE_SERVER }}",
"authentication": {
"type": "default",
"options": {
"userName": "${{ secrets.AZURE_USERNAME }}",
"password": "${{ secrets.AZURE_PASSWORD }}"
}
},
"options": {
"port": 1433,
"database": "tedious"
}
}
}' > ~/.tedious/test-connection.json
- name: run integration tests
env:
AZURE_SERVER: ${{ secrets.AZURE_SERVER }}
AZURE_USERNAME: ${{ secrets.AZURE_USERNAME }}
AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
run: npx nyc --reporter=lcov npm run test-integration

- uses: codecov/codecov-action@v4
Expand Down Expand Up @@ -441,30 +393,17 @@ jobs:
- run: npm ci

- run: mkdir ~/.tedious

- name: Set up CI configuration (AD Authentication)
run: |
echo '{
"config": {
"server": "${{ secrets.AZURE_SERVER }}",
"authentication": {
"type": "azure-active-directory-password",
"options": {
"clientId": "${{ secrets.AZURE_AD_SP_CLIENT_ID }}",
"tenantId": "${{ secrets.AZURE_AD_TENANT_ID }}",
"userName": "${{ secrets.AZURE_AD_USERNAME }}",
"password": "${{ secrets.AZURE_AD_PASSWORD }}"
}
},
"options": {
"port": 1433,
"database": "tedious"
}
}
}' > ~/.tedious/test-connection.json
- name: Set up CI configuration
shell: bash
run: cp -f test/config.azure-ad-password.ts test/config.ts

- name: run integration tests
env:
AZURE_SERVER: ${{ secrets.AZURE_SERVER }}
AZURE_AD_SP_CLIENT_ID: ${{ secrets.AZURE_AD_SP_CLIENT_ID }}
AZURE_AD_SP_TENANT_ID: ${{ secrets.AZURE_AD_SP_TENANT_ID }}
AZURE_AD_USERNAME: ${{ secrets.AZURE_AD_USERNAME }}
AZURE_AD_PASSWORD: ${{ secrets.AZURE_AD_PASSWORD }}
run: npx nyc --reporter=lcov npm run test-integration

- uses: codecov/codecov-action@v4
Expand Down Expand Up @@ -500,29 +439,16 @@ jobs:
- run: npm ci

- run: mkdir ~/.tedious

- name: Set up CI configuration (AD Service Principal Authentication)
run: |
echo '{
"config": {
"server": "${{ secrets.AZURE_SERVER }}",
"authentication": {
"type": "azure-active-directory-service-principal-secret",
"options": {
"clientId": "${{ secrets.AZURE_AD_SP_CLIENT_ID }}",
"tenantId": "${{ secrets.AZURE_AD_SP_TENANT_ID }}",
"clientSecret": "${{ secrets.AZURE_AD_SP_CLIENT_SECRET }}"
}
},
"options": {
"port": 1433,
"database": "tedious"
}
}
}' > ~/.tedious/test-connection.json
- name: set up test configuration
shell: bash
run: cp -f test/config.azure-ad-sp-secret.ts test/config.ts

- name: run integration tests
env:
AZURE_SERVER: ${{ secrets.AZURE_SERVER }}
AZURE_AD_SP_CLIENT_ID: ${{ secrets.AZURE_AD_SP_CLIENT_ID }}
AZURE_AD_SP_TENANT_ID: ${{ secrets.AZURE_AD_SP_TENANT_ID }}
AZURE_AD_SP_CLIENT_SECRET: ${{ secrets.AZURE_AD_SP_CLIENT_SECRET }}
run: npx nyc --reporter=lcov npm run test-integration

- uses: codecov/codecov-action@v4
Expand Down
74 changes: 24 additions & 50 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,64 +30,38 @@ before_test:
- sc config sqlbrowser start= auto
- net start sqlbrowser

- mkdir C:\Users\appveyor\.tedious
- ps: >-
Set-Content -Value $('{
"config": {
"server": "localhost",
"authentication": {
"type": "default",
"options": {
"userName": "sa",
"password": "Password12!"
}
},
"options": {
"database": "master",
"trustServerCertificate": true
}
},
"ntlm": {
"server": "localhost",
"authentication": {
"type": "ntlm",
"options": {
"userName": "' + $env:username + '",
"password": "' + [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", '') + '",
"domain": "' + $env:computername + '"
}
},
"options": {
"database": "master",
"trustServerCertificate": true
}
}
}') -Path C:\Users\appveyor\.tedious\test-connection.json
test_script:
- node --version
- npm --version

- cmd: |
SET EXITVAL=0
- pwsh: |-
$ErrorActionPreference = "Stop"
npm run-script test
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
npm run-script test || SET EXITVAL=1
Copy-Item -Force test/config.appveyor.ts test/config.ts
SET TEDIOUS_TDS_VERSION=7_4
npm run-script test-integration || SET EXITVAL=1
$env:NTLM_USERNAME = $env:USERNAME
$env:NTLM_PASSWORD = [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", '')
$env:NTLM_DOMAIN = $env:COMPUTERNAME
SET TEDIOUS_TDS_VERSION=7_3_B
npm run-script test-integration || SET EXITVAL=1
$env:TEDIOUS_TDS_VERSION = '7_4'
npm run-script test-integration
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
SET TEDIOUS_TDS_VERSION=7_3_A
npm run-script test-integration || SET EXITVAL=1
$env:TEDIOUS_TDS_VERSION = '7_3_B'
npm run-script test-integration
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
SET TEDIOUS_TDS_VERSION=7_2
npm run-script test-integration || SET EXITVAL=1
$env:TEDIOUS_TDS_VERSION = '7_3_A'
npm run-script test-integration
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
SET TEDIOUS_TDS_VERSION=7_1
npm run-script test-integration || SET EXITVAL=1
$env:TEDIOUS_TDS_VERSION = '7_2'
npm run-script test-integration
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
EXIT /B %EXITVAL%
$env:TEDIOUS_TDS_VERSION = '7_1'
npm run-script test-integration
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
18 changes: 18 additions & 0 deletions test/config.appveyor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ConnectionConfiguration } from '../src/connection';

export default {
'server': 'localhost',
'authentication': {
'type': 'ntlm',
'options': {
'userName': process.env.NTLM_USERNAME,
'password': process.env.NTLM_PASSWORD,
'domain': process.env.NTLM_DOMAIN
}
},
'options': {
'instanceName': 'SQL2017',
'database': 'master',
'trustServerCertificate': true
}
} as ConnectionConfiguration;
18 changes: 18 additions & 0 deletions test/config.azure-ad-password.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { type ConnectionConfiguration } from '../src/connection';

export default {
'server': process.env.AZURE_SERVER,
'authentication': {
'type': 'azure-active-directory-password',
'options': {
'clientId': process.env.AZURE_AD_SP_CLIENT_ID,
'tenantId': process.env.AZURE_AD_SP_TENANT_ID,
'userName': process.env.AZURE_AD_USERNAME,
'password': process.env.AZURE_AD_PASSWORD
}
},
'options': {
'port': 1433,
'database': 'tedious'
}
} as ConnectionConfiguration;
17 changes: 17 additions & 0 deletions test/config.azure-ad-sp-secret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type ConnectionConfiguration } from '../src/connection';

export default {
'server': process.env.AZURE_SERVER,
'authentication': {
'type': 'azure-active-directory-service-principal-secret',
'options': {
'clientId': process.env.AZURE_AD_SP_CLIENT_ID,
'tenantId': process.env.AZURE_AD_SP_TENANT_ID,
'clientSecret': process.env.AZURE_AD_SP_CLIENT_SECRET
}
},
'options': {
'port': 1433,
'database': 'tedious'
}
} as ConnectionConfiguration;
16 changes: 16 additions & 0 deletions test/config.azure-default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { type ConnectionConfiguration } from '../src/connection';

export default {
'server': process.env.AZURE_SERVER,
'authentication': {
'type': 'default',
'options': {
'userName': process.env.AZURE_USERNAME,
'password': process.env.AZURE_PASSWORD
}
},
'options': {
'port': 1433,
'database': 'tedious'
}
} as ConnectionConfiguration;
23 changes: 23 additions & 0 deletions test/config.ci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Configuration to use for integration tests.
import { type ConnectionConfiguration } from '../src/connection';
import { readFileSync } from 'fs';
import { resolve } from 'path';

export default {
'server': 'localhost',
'authentication': {
'type': 'default',
'options': {
'userName': 'sa',
'password': 'yourStrong(!)Password'
}
},
'options': {
'port': 1433,
'database': 'master',
'encrypt': true,
'cryptoCredentialsDetails': {
ca: readFileSync(resolve(__dirname, './fixtures/mssql.crt'))
}
}
} as ConnectionConfiguration;
18 changes: 18 additions & 0 deletions test/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Configuration to use for integration tests.
import { type ConnectionConfiguration } from '../src/connection';

export default {
'server': 'mssql',
'authentication': {
'type': 'default',
'options': {
'userName': 'sa',
'password': 'yourStrong(!)Password'
}
},
'options': {
'port': 1433,
'database': 'master',
'trustServerCertificate': true
}
} as ConnectionConfiguration;
Loading

0 comments on commit 3cd7e86

Please sign in to comment.