Skip to content

Commit 3cd7e86

Browse files
arthurschreibermShan0MichaelSun90
authored
test: use a JavaScript based config file format (#1634)
Co-authored-by: mShan0 <[email protected]> Co-authored-by: Michael Sun <[email protected]>
1 parent 1a703e2 commit 3cd7e86

22 files changed

+578
-443
lines changed

.github/workflows/nodejs.yml

+28-102
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,8 @@ jobs:
6666
docker-compose -f "test/docker-compose.linux.yml" up --detach
6767
6868
- name: Set up CI configuration
69-
run: |
70-
mkdir ~/.tedious
71-
72-
echo '{
73-
"config": {
74-
"server": "localhost",
75-
"authentication": {
76-
"type": "default",
77-
"options": {
78-
"userName": "sa",
79-
"password": "yourStrong(!)Password"
80-
}
81-
},
82-
"options": {
83-
"port": 1433,
84-
"database": "master",
85-
"encrypt": true
86-
}
87-
}
88-
}' | jq --arg certificate "$(cat ./test/fixtures/mssql.crt)" '.config.options.cryptoCredentialsDetails.ca |= $certificate' > ~/.tedious/test-connection.json
69+
shell: bash
70+
run: cp -f test/config.ci.ts test/config.ts
8971

9072
- name: Upgrade npm
9173
run: npm install -g npm
@@ -267,26 +249,7 @@ jobs:
267249
268250
- name: Set up CI configuration
269251
shell: bash
270-
run: |
271-
mkdir ~/.tedious
272-
273-
echo '{
274-
"config": {
275-
"server": "localhost",
276-
"authentication": {
277-
"type": "default",
278-
"options": {
279-
"userName": "sa",
280-
"password": "yourStrong(!)Password"
281-
}
282-
},
283-
"options": {
284-
"port": 1433,
285-
"database": "master",
286-
"trustServerCertificate": true
287-
}
288-
}
289-
}' | jq --arg certificate "$(cat ./test/fixtures/mssql.crt)" '.config.options.cryptoCredentialsDetails.ca |= $certificate' > ~/.tedious/test-connection.json
252+
run: cp -f test/config.ci.ts test/config.ts
290253

291254
- name: Upgrade npm
292255
run: npm install -g npm
@@ -383,29 +346,18 @@ jobs:
383346
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
384347
restore-keys: |
385348
${{ runner.os }}-node-
349+
386350
- run: npm ci
387351

388-
- run: mkdir ~/.tedious
352+
- name: Set up CI configuration
353+
shell: bash
354+
run: cp -f test/config.azure-default.ts test/config.ts
389355

390-
- name: Set up CI configuration (SQL Authentication)
391-
run: |
392-
echo '{
393-
"config": {
394-
"server": "${{ secrets.AZURE_SERVER }}",
395-
"authentication": {
396-
"type": "default",
397-
"options": {
398-
"userName": "${{ secrets.AZURE_USERNAME }}",
399-
"password": "${{ secrets.AZURE_PASSWORD }}"
400-
}
401-
},
402-
"options": {
403-
"port": 1433,
404-
"database": "tedious"
405-
}
406-
}
407-
}' > ~/.tedious/test-connection.json
408356
- name: run integration tests
357+
env:
358+
AZURE_SERVER: ${{ secrets.AZURE_SERVER }}
359+
AZURE_USERNAME: ${{ secrets.AZURE_USERNAME }}
360+
AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
409361
run: npx nyc --reporter=lcov npm run test-integration
410362

411363
- uses: codecov/codecov-action@v4
@@ -441,30 +393,17 @@ jobs:
441393
442394
- run: npm ci
443395

444-
- run: mkdir ~/.tedious
445-
446-
- name: Set up CI configuration (AD Authentication)
447-
run: |
448-
echo '{
449-
"config": {
450-
"server": "${{ secrets.AZURE_SERVER }}",
451-
"authentication": {
452-
"type": "azure-active-directory-password",
453-
"options": {
454-
"clientId": "${{ secrets.AZURE_AD_SP_CLIENT_ID }}",
455-
"tenantId": "${{ secrets.AZURE_AD_TENANT_ID }}",
456-
"userName": "${{ secrets.AZURE_AD_USERNAME }}",
457-
"password": "${{ secrets.AZURE_AD_PASSWORD }}"
458-
}
459-
},
460-
"options": {
461-
"port": 1433,
462-
"database": "tedious"
463-
}
464-
}
465-
}' > ~/.tedious/test-connection.json
396+
- name: Set up CI configuration
397+
shell: bash
398+
run: cp -f test/config.azure-ad-password.ts test/config.ts
466399

467400
- name: run integration tests
401+
env:
402+
AZURE_SERVER: ${{ secrets.AZURE_SERVER }}
403+
AZURE_AD_SP_CLIENT_ID: ${{ secrets.AZURE_AD_SP_CLIENT_ID }}
404+
AZURE_AD_SP_TENANT_ID: ${{ secrets.AZURE_AD_SP_TENANT_ID }}
405+
AZURE_AD_USERNAME: ${{ secrets.AZURE_AD_USERNAME }}
406+
AZURE_AD_PASSWORD: ${{ secrets.AZURE_AD_PASSWORD }}
468407
run: npx nyc --reporter=lcov npm run test-integration
469408

470409
- uses: codecov/codecov-action@v4
@@ -500,29 +439,16 @@ jobs:
500439
501440
- run: npm ci
502441

503-
- run: mkdir ~/.tedious
504-
505-
- name: Set up CI configuration (AD Service Principal Authentication)
506-
run: |
507-
echo '{
508-
"config": {
509-
"server": "${{ secrets.AZURE_SERVER }}",
510-
"authentication": {
511-
"type": "azure-active-directory-service-principal-secret",
512-
"options": {
513-
"clientId": "${{ secrets.AZURE_AD_SP_CLIENT_ID }}",
514-
"tenantId": "${{ secrets.AZURE_AD_SP_TENANT_ID }}",
515-
"clientSecret": "${{ secrets.AZURE_AD_SP_CLIENT_SECRET }}"
516-
}
517-
},
518-
"options": {
519-
"port": 1433,
520-
"database": "tedious"
521-
}
522-
}
523-
}' > ~/.tedious/test-connection.json
442+
- name: set up test configuration
443+
shell: bash
444+
run: cp -f test/config.azure-ad-sp-secret.ts test/config.ts
524445

525446
- name: run integration tests
447+
env:
448+
AZURE_SERVER: ${{ secrets.AZURE_SERVER }}
449+
AZURE_AD_SP_CLIENT_ID: ${{ secrets.AZURE_AD_SP_CLIENT_ID }}
450+
AZURE_AD_SP_TENANT_ID: ${{ secrets.AZURE_AD_SP_TENANT_ID }}
451+
AZURE_AD_SP_CLIENT_SECRET: ${{ secrets.AZURE_AD_SP_CLIENT_SECRET }}
526452
run: npx nyc --reporter=lcov npm run test-integration
527453

528454
- uses: codecov/codecov-action@v4

appveyor.yml

+24-50
Original file line numberDiff line numberDiff line change
@@ -30,64 +30,38 @@ before_test:
3030
- sc config sqlbrowser start= auto
3131
- net start sqlbrowser
3232

33-
- mkdir C:\Users\appveyor\.tedious
34-
- ps: >-
35-
Set-Content -Value $('{
36-
"config": {
37-
"server": "localhost",
38-
"authentication": {
39-
"type": "default",
40-
"options": {
41-
"userName": "sa",
42-
"password": "Password12!"
43-
}
44-
},
45-
"options": {
46-
"database": "master",
47-
"trustServerCertificate": true
48-
}
49-
},
50-
51-
"ntlm": {
52-
"server": "localhost",
53-
"authentication": {
54-
"type": "ntlm",
55-
"options": {
56-
"userName": "' + $env:username + '",
57-
"password": "' + [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", '') + '",
58-
"domain": "' + $env:computername + '"
59-
}
60-
},
61-
"options": {
62-
"database": "master",
63-
"trustServerCertificate": true
64-
}
65-
}
66-
}') -Path C:\Users\appveyor\.tedious\test-connection.json
67-
68-
6933
test_script:
7034
- node --version
7135
- npm --version
7236

73-
- cmd: |
74-
SET EXITVAL=0
37+
- pwsh: |-
38+
$ErrorActionPreference = "Stop"
39+
40+
npm run-script test
41+
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
7542
76-
npm run-script test || SET EXITVAL=1
43+
Copy-Item -Force test/config.appveyor.ts test/config.ts
7744
78-
SET TEDIOUS_TDS_VERSION=7_4
79-
npm run-script test-integration || SET EXITVAL=1
45+
$env:NTLM_USERNAME = $env:USERNAME
46+
$env:NTLM_PASSWORD = [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", '')
47+
$env:NTLM_DOMAIN = $env:COMPUTERNAME
8048
81-
SET TEDIOUS_TDS_VERSION=7_3_B
82-
npm run-script test-integration || SET EXITVAL=1
49+
$env:TEDIOUS_TDS_VERSION = '7_4'
50+
npm run-script test-integration
51+
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
8352
84-
SET TEDIOUS_TDS_VERSION=7_3_A
85-
npm run-script test-integration || SET EXITVAL=1
53+
$env:TEDIOUS_TDS_VERSION = '7_3_B'
54+
npm run-script test-integration
55+
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
8656
87-
SET TEDIOUS_TDS_VERSION=7_2
88-
npm run-script test-integration || SET EXITVAL=1
57+
$env:TEDIOUS_TDS_VERSION = '7_3_A'
58+
npm run-script test-integration
59+
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
8960
90-
SET TEDIOUS_TDS_VERSION=7_1
91-
npm run-script test-integration || SET EXITVAL=1
61+
$env:TEDIOUS_TDS_VERSION = '7_2'
62+
npm run-script test-integration
63+
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
9264
93-
EXIT /B %EXITVAL%
65+
$env:TEDIOUS_TDS_VERSION = '7_1'
66+
npm run-script test-integration
67+
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }

test/config.appveyor.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { ConnectionConfiguration } from '../src/connection';
2+
3+
export default {
4+
'server': 'localhost',
5+
'authentication': {
6+
'type': 'ntlm',
7+
'options': {
8+
'userName': process.env.NTLM_USERNAME,
9+
'password': process.env.NTLM_PASSWORD,
10+
'domain': process.env.NTLM_DOMAIN
11+
}
12+
},
13+
'options': {
14+
'instanceName': 'SQL2017',
15+
'database': 'master',
16+
'trustServerCertificate': true
17+
}
18+
} as ConnectionConfiguration;

test/config.azure-ad-password.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { type ConnectionConfiguration } from '../src/connection';
2+
3+
export default {
4+
'server': process.env.AZURE_SERVER,
5+
'authentication': {
6+
'type': 'azure-active-directory-password',
7+
'options': {
8+
'clientId': process.env.AZURE_AD_SP_CLIENT_ID,
9+
'tenantId': process.env.AZURE_AD_SP_TENANT_ID,
10+
'userName': process.env.AZURE_AD_USERNAME,
11+
'password': process.env.AZURE_AD_PASSWORD
12+
}
13+
},
14+
'options': {
15+
'port': 1433,
16+
'database': 'tedious'
17+
}
18+
} as ConnectionConfiguration;

test/config.azure-ad-sp-secret.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { type ConnectionConfiguration } from '../src/connection';
2+
3+
export default {
4+
'server': process.env.AZURE_SERVER,
5+
'authentication': {
6+
'type': 'azure-active-directory-service-principal-secret',
7+
'options': {
8+
'clientId': process.env.AZURE_AD_SP_CLIENT_ID,
9+
'tenantId': process.env.AZURE_AD_SP_TENANT_ID,
10+
'clientSecret': process.env.AZURE_AD_SP_CLIENT_SECRET
11+
}
12+
},
13+
'options': {
14+
'port': 1433,
15+
'database': 'tedious'
16+
}
17+
} as ConnectionConfiguration;

test/config.azure-default.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { type ConnectionConfiguration } from '../src/connection';
2+
3+
export default {
4+
'server': process.env.AZURE_SERVER,
5+
'authentication': {
6+
'type': 'default',
7+
'options': {
8+
'userName': process.env.AZURE_USERNAME,
9+
'password': process.env.AZURE_PASSWORD
10+
}
11+
},
12+
'options': {
13+
'port': 1433,
14+
'database': 'tedious'
15+
}
16+
} as ConnectionConfiguration;

test/config.ci.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Configuration to use for integration tests.
2+
import { type ConnectionConfiguration } from '../src/connection';
3+
import { readFileSync } from 'fs';
4+
import { resolve } from 'path';
5+
6+
export default {
7+
'server': 'localhost',
8+
'authentication': {
9+
'type': 'default',
10+
'options': {
11+
'userName': 'sa',
12+
'password': 'yourStrong(!)Password'
13+
}
14+
},
15+
'options': {
16+
'port': 1433,
17+
'database': 'master',
18+
'encrypt': true,
19+
'cryptoCredentialsDetails': {
20+
ca: readFileSync(resolve(__dirname, './fixtures/mssql.crt'))
21+
}
22+
}
23+
} as ConnectionConfiguration;

test/config.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Configuration to use for integration tests.
2+
import { type ConnectionConfiguration } from '../src/connection';
3+
4+
export default {
5+
'server': 'mssql',
6+
'authentication': {
7+
'type': 'default',
8+
'options': {
9+
'userName': 'sa',
10+
'password': 'yourStrong(!)Password'
11+
}
12+
},
13+
'options': {
14+
'port': 1433,
15+
'database': 'master',
16+
'trustServerCertificate': true
17+
}
18+
} as ConnectionConfiguration;

0 commit comments

Comments
 (0)