-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testing): Infra/support for external contract tests (#5771)
* Getting started with external contract tests "app" * Build with esbuild and first test Set limits on cronjob Run at 11 * Remove entrypoint * bringing back jest-to-dd script * switching to using the new NationalRegistry client * cleaning up and fixing minor issues * a bit better docs * Revert "a bit better docs" This reverts commit ebe542e. * Revert "cleaning up and fixing minor issues" This reverts commit 5a4d596. * Revert "switching to using the new NationalRegistry client" This reverts commit a0b95b0. * renaming the spec file to match with the test target Co-authored-by: Petar Shomov <[email protected]>
- Loading branch information
Showing
18 changed files
with
302 additions
and
11 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 @@ | ||
{"extends":"../../.eslintrc","rules":{},"ignorePatterns":["!**/*"]} |
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,34 @@ | ||
{ | ||
"platform": "node", | ||
"external": [ | ||
"fsevents", | ||
"color-string", | ||
"color-convert", | ||
"@nestjs/microservices", | ||
"class-transformer", | ||
"cache-manager", | ||
"@nestjs/websockets/socket-module", | ||
"class-validator", | ||
"class-transformer", | ||
"@nestjs/microservices/microservices-module", | ||
"apollo-server-fastify", | ||
"@elastic/elasticsearch", | ||
"fastify-swagger", | ||
"@nestjs/mongoose", | ||
"@nestjs/typeorm", | ||
"dd-trace", | ||
"express", | ||
"http-errors", | ||
"graphql", | ||
"winston", | ||
"pg", | ||
"source-map-resolve", | ||
"atob", | ||
"logform", | ||
"pg-native", | ||
"form-data", | ||
"bull", | ||
"pseudomap" | ||
], | ||
"keepNames": true | ||
} |
31 changes: 31 additions & 0 deletions
31
apps/external-contracts-tests/infra/external-contracts-tests.ts
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,31 @@ | ||
import { service, ServiceBuilder } from '../../../infra/src/dsl/dsl' | ||
import { Base, NationalRegistry } from '../../../infra/src/dsl/xroad' | ||
import { settings } from '../../../infra/src/dsl/settings' | ||
|
||
export const serviceSetup = (): ServiceBuilder<'external-contracts-tests'> => { | ||
return service('external-contracts-tests') | ||
.namespace('external-contracts-tests') | ||
.extraAttributes({ | ||
dev: { schedule: '0 11 * * *' }, | ||
staging: { schedule: '0 11 * * *' }, | ||
prod: { schedule: '0 11 * * *' }, | ||
}) | ||
.env({}) | ||
.secrets({ | ||
SOFFIA_SOAP_URL: '/k8s/api/SOFFIA_SOAP_URL', | ||
SOFFIA_HOST_URL: '/k8s/api/SOFFIA_HOST_URL', | ||
SOFFIA_USER: settings.SOFFIA_USER, | ||
SOFFIA_PASS: settings.SOFFIA_PASS, | ||
}) | ||
.resources({ | ||
limits: { | ||
cpu: '1', | ||
memory: '1024Mi', | ||
}, | ||
requests: { | ||
cpu: '500m', | ||
memory: '512Mi', | ||
}, | ||
}) | ||
.xroad(Base, NationalRegistry) | ||
} |
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,33 @@ | ||
import { StatsD } from 'hot-shots' | ||
import { readFileSync } from 'fs' | ||
import { resolve } from 'path' | ||
|
||
// this is not in use yet, but will be part of the next phase in this development | ||
|
||
const client = new StatsD({ mock: true }) | ||
const jestReport = JSON.parse( | ||
readFileSync(resolve(process.argv[2]), { encoding: 'utf-8' }), | ||
) as { | ||
testResults: { | ||
assertionResults: { fullName: string; status: 'passed' | 'failed' }[] | ||
}[] | ||
} | ||
const testCasesInfo = jestReport.testResults.flatMap( | ||
(testResult) => | ||
testResult.assertionResults.map((test) => ({ | ||
name: test.fullName as string, | ||
status: test.status === 'passed' ? 'success' : 'failure', | ||
})) as { name: string; status: 'success' | 'failure' }[], | ||
) | ||
const successfulTests = testCasesInfo | ||
.filter((tc) => tc.status === 'success') | ||
.map((tc) => tc.name) | ||
const failedTests = testCasesInfo | ||
.filter((tc) => tc.status === 'failure') | ||
.map((tc) => tc.name) | ||
|
||
console.log(`Failed test: ${failedTests}`) | ||
console.log(`Successful tests: ${successfulTests}`) | ||
|
||
successfulTests.forEach((tc) => client.check(tc, client.CHECKS.OK)) | ||
failedTests.forEach((tc) => client.check(tc, client.CHECKS.CRITICAL)) |
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,15 @@ | ||
module.exports = { | ||
preset: '../../jest.preset.js', | ||
transform: { | ||
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest', | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: '<rootDir>/tsconfig.json', | ||
}, | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], | ||
displayName: 'external-contracts-tests', | ||
modulePathIgnorePatterns: ['<rootDir>/main.spec.ts'], | ||
} |
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,3 @@ | ||
import * as testSuites from './test-suites/' | ||
|
||
console.log('Forcing esbuild visit to testSuites:', testSuites) |
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 @@ | ||
export * from './soffia.spec' |
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,25 @@ | ||
// NOTE: To run this locally, you'll need to portforward soffia and set | ||
// the environment variable "SOFFIA_SOAP_URL" to https://localhost:8443 | ||
// kubectl port-forward svc/socat-soffia 8443:443 -n socat | ||
import { NationalRegistryApi } from '@island.is/clients/national-registry-v1' | ||
|
||
describe('is.island.external.national', () => { | ||
let client: NationalRegistryApi | ||
beforeAll(async () => { | ||
client = await NationalRegistryApi.instantiateClass({ | ||
baseSoapUrl: process.env.SOFFIA_SOAP_URL!, | ||
user: process.env.SOFFIA_USER!, | ||
password: process.env.SOFFIA_PASS!, | ||
host: process.env.SOFFIA_HOST_URL!, | ||
}) | ||
}) | ||
it('should get user correctly', async () => { | ||
const user = await client.getUser('0101302989') | ||
expect(user.Fulltnafn).toEqual('Gervimaður Ameríka') | ||
}) | ||
it('throws error if user is not found', async () => { | ||
await expect(client.getUser('0123456789')).rejects.toThrow( | ||
'user with nationalId 0123456789 not found in national Registry', | ||
) | ||
}) | ||
}) |
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,8 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
} | ||
} |
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
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
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,10 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
# shellcheck disable=SC1091 | ||
source "$DIR"/_common.sh | ||
|
||
# Building Docker images for jest tests | ||
exec "$DIR"/_docker.sh Dockerfile output-jest |
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.