diff --git a/sdk/purview/purview-scanning-rest/karma.conf.js b/sdk/purview/purview-scanning-rest/karma.conf.js index 6f3632a5ce59..174887994236 100644 --- a/sdk/purview/purview-scanning-rest/karma.conf.js +++ b/sdk/purview/purview-scanning-rest/karma.conf.js @@ -4,12 +4,9 @@ // https://github.com/karma-runner/karma-chrome-launcher process.env.CHROME_BIN = require("puppeteer").executablePath(); require("dotenv").config(); -const { - jsonRecordingFilterFunction, - isPlaybackMode, - isSoftRecordMode, - isRecordMode, -} = require("@azure-tools/test-recorder"); +const { relativeRecordingsPath } = require("@azure-tools/test-recorder"); + +process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); module.exports = function (config) { config.set({ @@ -31,16 +28,14 @@ module.exports = function (config) { "karma-coverage", "karma-sourcemap-loader", "karma-junit-reporter", - "karma-json-to-file-reporter", "karma-source-map-support", - "karma-json-preprocessor", ], // list of files / patterns to load in the browser files: [ "dist-test/index.browser.js", { pattern: "dist-test/index.browser.js.map", type: "html", included: false, served: true }, - ].concat(isPlaybackMode() || isSoftRecordMode() ? ["recordings/browsers/**/*.json"] : []), + ], // list of files / patterns to exclude exclude: [], @@ -49,7 +44,6 @@ module.exports = function (config) { // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { "**/*.js": ["sourcemap", "env"], - "recordings/browsers/**/*.json": ["json"], // IMPORTANT: COMMENT following line if you want to debug in your browsers!! // Preprocess source file to calculate code coverage, however this will make source file unreadable // "dist-test/index.js": ["coverage"] @@ -61,12 +55,13 @@ module.exports = function (config) { "AZURE_CLIENT_SECRET", "AZURE_CLIENT_ID", "AZURE_TENANT_ID", + "RECORDINGS_RELATIVE_PATH", ], // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ["mocha", "coverage", "junit", "json-to-file"], + reporters: ["mocha", "coverage", "junit"], coverageReporter: { // specify a common output directory @@ -89,11 +84,6 @@ module.exports = function (config) { properties: {}, // key value pair of properties to add to the section of the report }, - jsonToFileReporter: { - filter: jsonRecordingFilterFunction, - outputPath: ".", - }, - // web server port port: 9876, @@ -128,9 +118,6 @@ module.exports = function (config) { browserNoActivityTimeout: 60000000, browserDisconnectTimeout: 10000, browserDisconnectTolerance: 3, - browserConsoleLogOptions: { - terminal: !isRecordMode(), - }, client: { mocha: { diff --git a/sdk/purview/purview-scanning-rest/package.json b/sdk/purview/purview-scanning-rest/package.json index b482250ed11a..7901f691583f 100644 --- a/sdk/purview/purview-scanning-rest/package.json +++ b/sdk/purview/purview-scanning-rest/package.json @@ -50,9 +50,6 @@ "disableDocsMs": true, "apiRefLink": "https://docs.microsoft.com/rest/api/purview" }, - "browser": { - "./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js" - }, "scripts": { "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", "build:browser": "tsc -p . && dev-tool run bundle", @@ -66,8 +63,8 @@ "execute:samples": "dev-tool samples run samples-dev", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", - "integration-test:browser": "karma start --single-run", - "integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 5000000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"", + "integration-test:browser": "dev-tool run test:browser", + "integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'", "integration-test": "npm run integration-test:node && npm run integration-test:browser", "generate:client": "autorest --typescript swagger/README.md && npm run format", "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", @@ -76,8 +73,8 @@ "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser", "test:node": "npm run clean && npm run build:test && npm run unit-test:node", "test": "npm run clean && npm run build:test && npm run unit-test", - "unit-test:browser": "karma start --single-run", - "unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"", + "unit-test:browser": "dev-tool run test:browser", + "unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'", "unit-test": "npm run unit-test:node && npm run unit-test:browser" }, "sideEffects": false, @@ -95,7 +92,8 @@ "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@azure/identity": "^2.0.1", "@azure/test-utils": "^1.0.0", - "@azure-tools/test-recorder": "^1.0.0", + "@azure-tools/test-credential": "^1.0.0", + "@azure-tools/test-recorder": "^2.0.0", "@microsoft/api-extractor": "^7.18.11", "@types/chai": "^4.1.6", "@types/mocha": "^7.0.2", @@ -110,8 +108,6 @@ "karma-env-preprocessor": "^0.1.1", "karma-firefox-launcher": "^1.1.0", "karma-ie-launcher": "^1.0.0", - "karma-json-preprocessor": "^0.3.3", - "karma-json-to-file-reporter": "^1.0.1", "karma-junit-reporter": "^2.0.1", "karma-mocha-reporter": "^2.2.5", "karma-mocha": "^2.0.1", diff --git a/sdk/purview/purview-scanning-rest/recordings/browsers/list_data_sources/recording_should_list_all_available_data_sources.json b/sdk/purview/purview-scanning-rest/recordings/browsers/list_data_sources/recording_should_list_all_available_data_sources.json index 392be2c41cf9..0a3c945aea07 100644 --- a/sdk/purview/purview-scanning-rest/recordings/browsers/list_data_sources/recording_should_list_all_available_data_sources.json +++ b/sdk/purview/purview-scanning-rest/recordings/browsers/list_data_sources/recording_should_list_all_available_data_sources.json @@ -1,52 +1,66 @@ { - "recordings": [ - { - "method": "POST", - "url": "https://login.microsoftonline.com/88888888-8888-8888-8888-888888888888/oauth2/v2.0/token", - "query": {}, - "requestBody": "response_type=token&grant_type=client_credentials&client_id=azure_client_id&client_secret=azure_client_secret&scope=https%3A%2F%2Fpurview.azure.net%2F.default", - "status": 200, - "response": "{\"token_type\":\"Bearer\",\"expires_in\":86399,\"ext_expires_in\":86399,\"access_token\":\"access_token\"}", - "responseHeaders": { - "cache-control": "no-store, no-cache", - "content-length": "1318", - "content-type": "application/json; charset=utf-8", - "date": "Sat, 17 Apr 2021 03:02:04 GMT", - "expires": "-1", - "nel": "{\"report_to\":\"network-errors\",\"max_age\":86400,\"success_fraction\":0.001,\"failure_fraction\":1.0}", - "p3p": "CP=\"DSP CUR OTPi IND OTRi ONL FIN\"", - "pragma": "no-cache", - "referrer-policy": "strict-origin-when-cross-origin", - "report-to": "{\"group\":\"network-errors\",\"max_age\":86400,\"endpoints\":[{\"url\":\"https://identity.nel.measure.office.net/api/report?catId=GW+estsfd+san\"}]}", - "strict-transport-security": "max-age=31536000; includeSubDomains", - "x-content-type-options": "nosniff", - "x-ms-ests-server": "2.1.11654.16 - WUS2 ProdSlices", - "x-ms-request-id": "44f468db-faed-48d7-995e-05f817e02f00" - } - }, - { - "method": "GET", - "url": "https://endpoint/datasources", - "query": { - "api-version": "2018-12-01-preview" - }, - "requestBody": null, - "status": 200, - "response": "{\"value\":[{\"properties\":{\"createdAt\":\"2021-04-01T19:18:25.6411232Z\",\"lastModifiedAt\":\"2021-04-01T19:18:25.6411233Z\",\"parentCollection\":null},\"kind\":\"Collection\",\"id\":\"datasources/Collection-vaR\",\"name\":\"Collection-vaR\"},{\"properties\":{\"endpoint\":\"https://joherediteststorage.blob.core.windows.net/\",\"resourceGroup\":\"joheredi-test\",\"subscriptionId\":\"faa080af-c1d8-40ad-9cce-e1a450ca5b57\",\"location\":\"westus\",\"resourceName\":\"joherediteststorage\",\"createdAt\":\"2021-04-01T19:19:37.3396977Z\",\"lastModifiedAt\":\"2021-04-01T19:19:37.3396984Z\",\"parentCollection\":{\"type\":\"DataSourceReference\",\"referenceName\":\"Collection-vaR\"}},\"kind\":\"AzureStorage\",\"id\":\"datasources/AzureBlob-BzV\",\"name\":\"AzureBlob-BzV\"}],\"count\":2}", - "responseHeaders": { - "content-length": "709", - "content-type": "application/json; charset=utf-8", - "date": "Sat, 17 Apr 2021 03:02:05 GMT", - "server": "Kestrel", - "status": "200", - "strict-transport-security": "max-age=31536000; includeSubDomains", - "x-ms-correlation-request-id": "36683dfa-4a94-4628-b8d3-d34ade2fd6e4" - } - } - ], - "uniqueTestInfo": { - "uniqueName": {}, - "newDate": {} - }, - "hash": "5fee9200fb758f2d6abdead4d3526b3e" -} \ No newline at end of file + "Entries": [ + { + "RequestUri": "https://endpoint/datasources?api-version=2018-12-01-preview", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "en-US", + "Authorization": "Sanitized", + "Connection": "keep-alive", + "Referer": "http://localhost:9876/", + "sec-ch-ua": "", + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-site", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/93.0.4577.0 Safari/537.36", + "x-ms-client-request-id": "082c00f6-4bc1-48ed-9b46-24ed4e6bf430", + "x-ms-useragent": "core-rest-pipeline/1.5.1 OS/Linuxx86_64" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "api-supported-versions": "2018-12-01-preview, 2021-10-01-preview", + "Content-Length": "636", + "Content-Type": "application/json; charset=utf-8", + "Date": "Sat, 12 Feb 2022 01:20:12 GMT", + "Request-Context": "appId=cid-v1:caaf2286-a721-4ba8-a2bd-9a1b7993b4fd", + "Server": "Kestrel", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "x-ms-correlation-request-id": "c2c7ad8d-ffb8-4dd5-9c12-45ecc3286a35" + }, + "ResponseBody": { + "value": [ + { + "properties": { + "endpoint": "https://joheredistorage2.blob.core.windows.net/", + "resourceGroup": "joheredi-test", + "subscriptionId": "faa080af-c1d8-40ad-9cce-e1a450ca5b57", + "location": "westus", + "resourceName": "joheredistorage2", + "resourceId": null, + "dataUseGovernance": "Disabled", + "createdAt": "2021-09-29T18:51:31.9201233Z", + "lastModifiedAt": "2021-09-29T18:51:31.9201233Z", + "parentCollection": null, + "collection": { + "lastModifiedAt": "2021-09-29T18:51:31.9201233Z", + "referenceName": "la7eio", + "type": "CollectionReference" + }, + "dataSourceCollectionMovingState": 0 + }, + "kind": "AzureStorage", + "id": "datasources/AzureBlob-Fq7", + "name": "AzureBlob-Fq7" + } + ], + "count": 1 + } + } + ], + "Variables": {} +} diff --git a/sdk/purview/purview-scanning-rest/recordings/node/list_data_sources/recording_should_list_all_available_data_sources.js b/sdk/purview/purview-scanning-rest/recordings/node/list_data_sources/recording_should_list_all_available_data_sources.js deleted file mode 100644 index c138792143fc..000000000000 --- a/sdk/purview/purview-scanning-rest/recordings/node/list_data_sources/recording_should_list_all_available_data_sources.js +++ /dev/null @@ -1,129 +0,0 @@ -let nock = require('nock'); - -module.exports.hash = "bb6f75c4b6d1125ece9d9a06e93e8a82"; - -module.exports.testInfo = { "uniqueName": {}, "newDate": {} } - -nock('https://login.microsoftonline.com:443', { "encodedQueryParams": true }) - .get('/common/discovery/instance') - .query(true) - .reply(200, { "tenant_discovery_endpoint": "https://login.microsoftonline.com/88888888-8888-8888-8888-888888888888/v2.0/.well-known/openid-configuration", "api-version": "1.1", "metadata": [{ "preferred_network": "login.microsoftonline.com", "preferred_cache": "login.windows.net", "aliases": ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"] }, { "preferred_network": "login.partner.microsoftonline.cn", "preferred_cache": "login.partner.microsoftonline.cn", "aliases": ["login.partner.microsoftonline.cn", "login.chinacloudapi.cn"] }, { "preferred_network": "login.microsoftonline.de", "preferred_cache": "login.microsoftonline.de", "aliases": ["login.microsoftonline.de"] }, { "preferred_network": "login.microsoftonline.us", "preferred_cache": "login.microsoftonline.us", "aliases": ["login.microsoftonline.us", "login.usgovcloudapi.net"] }, { "preferred_network": "login-us.microsoftonline.com", "preferred_cache": "login-us.microsoftonline.com", "aliases": ["login-us.microsoftonline.com"] }] }, [ - 'Cache-Control', - 'max-age=86400, private', - 'Content-Type', - 'application/json; charset=utf-8', - 'Strict-Transport-Security', - 'max-age=31536000; includeSubDomains', - 'X-Content-Type-Options', - 'nosniff', - 'Access-Control-Allow-Origin', - '*', - 'Access-Control-Allow-Methods', - 'GET, OPTIONS', - 'P3P', - 'CP="DSP CUR OTPi IND OTRi ONL FIN"', - 'x-ms-request-id', - '0e573fdf-76a7-46eb-bf0e-4cc88ffc6a00', - 'x-ms-ests-server', - '2.1.12171.15 - SCUS ProdSlices', - 'Set-Cookie', - 'fpc=AkslAjbvK_VJk8S5fj5N8ek; expires=Sat, 04-Dec-2021 16:43:54 GMT; path=/; secure; HttpOnly; SameSite=None', - 'Set-Cookie', - 'esctx=AQABAAAAAAD--DLA3VO7QrddgJg7WevrEtTw6DAP_Ryjw9F79kQ1uosjHdtynNDbpPTE86OET0ecUEcX7kVdDxPIjrGczPlXEIBu3DMYimEowSE4Oek1CzlQdxlxwJUrnOM2H97f3zEh9IDb_nn63R0FWKmTUpbCqeLiEciuxNdEh5_J4zEXBjp9vQWe1QxcAwv0JTNy8VMgAA; domain=.login.microsoftonline.com; path=/; secure; HttpOnly; SameSite=None', - 'Set-Cookie', - 'x-ms-gateway-slice=estsfd; path=/; secure; samesite=none; httponly', - 'Set-Cookie', - 'stsservicecookie=estsfd; path=/; secure; samesite=none; httponly', - 'Date', - 'Thu, 04 Nov 2021 16:43:54 GMT', - 'Content-Length', - '980' - ]); - -nock('https://login.microsoftonline.com:443', { "encodedQueryParams": true }) - .get('/88888888-8888-8888-8888-888888888888/v2.0/.well-known/openid-configuration') - .reply(200, { "token_endpoint": "https://login.microsoftonline.com/88888888-8888-8888-8888-888888888888/oauth2/v2.0/token", "token_endpoint_auth_methods_supported": ["client_secret_post", "private_key_jwt", "client_secret_basic"], "jwks_uri": "https://login.microsoftonline.com/88888888-8888-8888-8888-888888888888/discovery/v2.0/keys", "response_modes_supported": ["query", "fragment", "form_post"], "subject_types_supported": ["pairwise"], "id_token_signing_alg_values_supported": ["RS256"], "response_types_supported": ["code", "id_token", "code id_token", "id_token token"], "scopes_supported": ["openid", "profile", "email", "offline_access"], "issuer": "https://login.microsoftonline.com/88888888-8888-8888-8888-888888888888/v2.0", "request_uri_parameter_supported": false, "userinfo_endpoint": "https://graph.microsoft.com/oidc/userinfo", "authorization_endpoint": "https://login.microsoftonline.com/88888888-8888-8888-8888-888888888888/oauth2/v2.0/authorize", "device_authorization_endpoint": "https://login.microsoftonline.com/88888888-8888-8888-8888-888888888888/oauth2/v2.0/devicecode", "http_logout_supported": true, "frontchannel_logout_supported": true, "end_session_endpoint": "https://login.microsoftonline.com/88888888-8888-8888-8888-888888888888/oauth2/v2.0/logout", "claims_supported": ["sub", "iss", "cloud_instance_name", "cloud_instance_host_name", "cloud_graph_host_name", "msgraph_host", "aud", "exp", "iat", "auth_time", "acr", "nonce", "preferred_username", "name", "tid", "ver", "at_hash", "c_hash", "email"], "kerberos_endpoint": "https://login.microsoftonline.com/88888888-8888-8888-8888-888888888888/kerberos", "tenant_region_scope": "WW", "cloud_instance_name": "microsoftonline.com", "cloud_graph_host_name": "graph.windows.net", "msgraph_host": "graph.microsoft.com", "rbac_url": "https://pas.windows.net" }, [ - 'Cache-Control', - 'max-age=86400, private', - 'Content-Type', - 'application/json; charset=utf-8', - 'Strict-Transport-Security', - 'max-age=31536000; includeSubDomains', - 'X-Content-Type-Options', - 'nosniff', - 'Access-Control-Allow-Origin', - '*', - 'Access-Control-Allow-Methods', - 'GET, OPTIONS', - 'P3P', - 'CP="DSP CUR OTPi IND OTRi ONL FIN"', - 'x-ms-request-id', - 'b2a01c86-1f7c-49a8-bfe3-f1bc3a891900', - 'x-ms-ests-server', - '2.1.12197.4 - NCUS ProdSlices', - 'Set-Cookie', - 'fpc=AmsLqgzpBGJEskHPRPh35v0; expires=Sat, 04-Dec-2021 16:43:54 GMT; path=/; secure; HttpOnly; SameSite=None', - 'Set-Cookie', - 'esctx=AQABAAAAAAD--DLA3VO7QrddgJg7Wevr6TvLJENUrk8P7hIYyul-YLJoyaFeq6vv7Voyw7MOLzTTYxbqQNbc9jXzpesUjoEVisvyiOJAJy7xSvTo7bp4AYgkKfjwT9QY_A0PfUzXqv3HyNZnwWM0YGY1GCC9jAYQYhyPN_6Lc6IpjKZvzkRnruYWxqMhiDD1Ppg8XdSy4PIgAA; domain=.login.microsoftonline.com; path=/; secure; HttpOnly; SameSite=None', - 'Set-Cookie', - 'x-ms-gateway-slice=estsfd; path=/; secure; samesite=none; httponly', - 'Set-Cookie', - 'stsservicecookie=estsfd; path=/; secure; samesite=none; httponly', - 'Date', - 'Thu, 04 Nov 2021 16:43:54 GMT', - 'Content-Length', - '1753' - ]); - -nock('https://login.microsoftonline.com:443', { "encodedQueryParams": true }) - .post('/88888888-8888-8888-8888-888888888888/oauth2/v2.0/token', "client_id=azure_client_id&scope=https%3A%2F%2Fsanitized%2F&grant_type=client_credentials&x-client-SKU=msal.js.node&x-client-VER=1.3.2&x-client-OS=linux&x-client-CPU=x64&x-ms-lib-capability=retry-after, h429&x-client-current-telemetry=5|771,2,,,|,&x-client-last-telemetry=5|0|||0,0&client-request-id=70d23244-1d55-425d-b7ca-e85507c3710f&client_secret=azure_client_secret&claims=%7B%22access_token%22%3A%7B%22xms_cc%22%3A%7B%22values%22%3A%5B%22CP1%22%5D%7D%7D%7D") - .reply(200, { "token_type": "Bearer", "expires_in": 86399, "ext_expires_in": 86399, "access_token": "access_token" }, [ - 'Cache-Control', - 'no-store, no-cache', - 'Pragma', - 'no-cache', - 'Content-Type', - 'application/json; charset=utf-8', - 'Expires', - '-1', - 'Strict-Transport-Security', - 'max-age=31536000; includeSubDomains', - 'X-Content-Type-Options', - 'nosniff', - 'P3P', - 'CP="DSP CUR OTPi IND OTRi ONL FIN"', - 'x-ms-request-id', - 'ccb20cb1-6f40-4498-b2d4-32c27da31a00', - 'x-ms-ests-server', - '2.1.12197.4 - NCUS ProdSlices', - 'x-ms-clitelem', - '1,0,0,,', - 'Set-Cookie', - 'fpc=AsyrsnnUAR5EiTDqCc4HEEj__1r8AQAAAMoEFtkOAAAA; expires=Sat, 04-Dec-2021 16:43:54 GMT; path=/; secure; HttpOnly; SameSite=None', - 'Set-Cookie', - 'x-ms-gateway-slice=estsfd; path=/; secure; samesite=none; httponly', - 'Set-Cookie', - 'stsservicecookie=estsfd; path=/; secure; samesite=none; httponly', - 'Date', - 'Thu, 04 Nov 2021 16:43:54 GMT', - 'Content-Length', - '1318' - ]); - -nock('https://endpoint', { "encodedQueryParams": true }) - .get('/datasources') - .query(true) - .reply(200, { "value": [{ "properties": { "createdAt": "2021-04-01T19:18:25.6411232Z", "lastModifiedAt": "2021-04-01T19:18:25.6411233Z", "parentCollection": null }, "kind": "Collection", "id": "datasources/Collection-vaR", "name": "Collection-vaR" }, { "properties": { "endpoint": "https://joherediteststorage.blob.core.windows.net/", "resourceGroup": "joheredi-test", "subscriptionId": "faa080af-c1d8-40ad-9cce-e1a450ca5b57", "location": "westus", "resourceName": "joherediteststorage", "createdAt": "2021-04-01T19:19:37.3396977Z", "lastModifiedAt": "2021-04-01T19:19:37.3396984Z", "parentCollection": { "type": "DataSourceReference", "referenceName": "Collection-vaR" } }, "kind": "AzureStorage", "id": "datasources/AzureBlob-BzV", "name": "AzureBlob-BzV" }], "count": 2 }, [ - 'Date', - 'Sat, 17 Apr 2021 03:02:02 GMT', - 'Content-Type', - 'application/json; charset=utf-8', - 'Server', - 'Kestrel', - 'Content-Length', - '709', - 'Strict-Transport-Security', - 'max-age=31536000; includeSubDomains', - 'x-ms-correlation-request-id', - '9e4bac9f-885b-43a0-9aeb-5fdd385646f9' - ]); diff --git a/sdk/purview/purview-scanning-rest/recordings/node/list_data_sources/recording_should_list_all_available_data_sources.json b/sdk/purview/purview-scanning-rest/recordings/node/list_data_sources/recording_should_list_all_available_data_sources.json new file mode 100644 index 000000000000..6df6f0f4782b --- /dev/null +++ b/sdk/purview/purview-scanning-rest/recordings/node/list_data_sources/recording_should_list_all_available_data_sources.json @@ -0,0 +1,57 @@ +{ + "Entries": [ + { + "RequestUri": "https://endpoint/datasources?api-version=2018-12-01-preview", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Accept-Encoding": "gzip,deflate", + "Authorization": "Sanitized", + "Connection": "keep-alive", + "User-Agent": "core-rest-pipeline/1.5.1 Node/v12.22.9 OS/(x64-Linux-5.4.0-1067-azure)", + "x-ms-client-request-id": "99cb1615-e11e-45c6-bed3-4feeca2fd0be" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "api-supported-versions": "2018-12-01-preview, 2021-10-01-preview", + "Content-Length": "636", + "Content-Type": "application/json; charset=utf-8", + "Date": "Sat, 12 Feb 2022 01:20:24 GMT", + "Request-Context": "appId=cid-v1:caaf2286-a721-4ba8-a2bd-9a1b7993b4fd", + "Server": "Kestrel", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "x-ms-correlation-request-id": "011ce69f-27b7-4673-bfde-b9a067583bd2" + }, + "ResponseBody": { + "value": [ + { + "properties": { + "endpoint": "https://joheredistorage2.blob.core.windows.net/", + "resourceGroup": "joheredi-test", + "subscriptionId": "faa080af-c1d8-40ad-9cce-e1a450ca5b57", + "location": "westus", + "resourceName": "joheredistorage2", + "resourceId": null, + "dataUseGovernance": "Disabled", + "createdAt": "2021-09-29T18:51:31.9201233Z", + "lastModifiedAt": "2021-09-29T18:51:31.9201233Z", + "parentCollection": null, + "collection": { + "lastModifiedAt": "2021-09-29T18:51:31.9201233Z", + "referenceName": "la7eio", + "type": "CollectionReference" + }, + "dataSourceCollectionMovingState": 0 + }, + "kind": "AzureStorage", + "id": "datasources/AzureBlob-Fq7", + "name": "AzureBlob-Fq7" + } + ], + "count": 1 + } + } + ], + "Variables": {} +} diff --git a/sdk/purview/purview-scanning-rest/test/public/dataSources.spec.ts b/sdk/purview/purview-scanning-rest/test/public/dataSources.spec.ts index 8555da4732c7..c0c0c5fd2b01 100644 --- a/sdk/purview/purview-scanning-rest/test/public/dataSources.spec.ts +++ b/sdk/purview/purview-scanning-rest/test/public/dataSources.spec.ts @@ -4,7 +4,7 @@ import { PurviewScanningRestClient, paginate, DataSource } from "../../src"; import { Recorder } from "@azure-tools/test-recorder"; import { assert } from "chai"; -import { createClient, createRecorder } from "./utils/recordedClient"; +import { createClient } from "./utils/recordedClient"; import { Context } from "mocha"; import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; @@ -12,9 +12,9 @@ describe("List data sources", () => { let recorder: Recorder; let client: PurviewScanningRestClient; - beforeEach(function (this: Context) { - recorder = createRecorder(this); - client = createClient(); + beforeEach(async function (this: Context) { + recorder = new Recorder(this.currentTest); + client = await createClient(recorder); }); afterEach(async function () { @@ -33,7 +33,7 @@ describe("List data sources", () => { items.push(item); } - assert.strictEqual(items.length, 2); + assert.isNotEmpty(items); if (result.status !== "200") { assert.fail(`GET "/datasources" failed with ${result.status}`); diff --git a/sdk/purview/purview-scanning-rest/test/public/utils/env.browser.ts b/sdk/purview/purview-scanning-rest/test/public/utils/env.browser.ts deleted file mode 100644 index fd2aca680c7b..000000000000 --- a/sdk/purview/purview-scanning-rest/test/public/utils/env.browser.ts +++ /dev/null @@ -1,2 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. diff --git a/sdk/purview/purview-scanning-rest/test/public/utils/env.ts b/sdk/purview/purview-scanning-rest/test/public/utils/env.ts deleted file mode 100644 index 0e06855b73ae..000000000000 --- a/sdk/purview/purview-scanning-rest/test/public/utils/env.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import * as dotenv from "dotenv"; - -dotenv.config(); diff --git a/sdk/purview/purview-scanning-rest/test/public/utils/recordedClient.ts b/sdk/purview/purview-scanning-rest/test/public/utils/recordedClient.ts index f97135f017f3..94d98c016910 100644 --- a/sdk/purview/purview-scanning-rest/test/public/utils/recordedClient.ts +++ b/sdk/purview/purview-scanning-rest/test/public/utils/recordedClient.ts @@ -3,21 +3,11 @@ /// -import { Context } from "mocha"; - -import { - env, - Recorder, - record, - RecorderEnvironmentSetup, - isLiveMode, -} from "@azure-tools/test-recorder"; import PurviewScanning, { PurviewScanningRestClient } from "../../../src"; -import { ClientSecretCredential } from "@azure/identity"; -import { isNode, createXhrHttpClient } from "@azure/test-utils"; +import { Recorder, RecorderStartOptions, env } from "@azure-tools/test-recorder"; -import "./env"; import { ClientOptions } from "@azure-rest/core-client"; +import { createTestCredential } from "@azure-tools/test-credential"; const replaceableVariables: { [k: string]: string } = { ENDPOINT: "https://endpoint", @@ -26,39 +16,19 @@ const replaceableVariables: { [k: string]: string } = { AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888", }; -export const environmentSetup: RecorderEnvironmentSetup = { - replaceableVariables, - customizationsOnRecordings: [ - (recording: string): string => - recording.replace(/"access_token"\s?:\s?"[^"]*"/g, `"access_token":"access_token"`), - // If we put ENDPOINT in replaceableVariables above, it will not capture - // the endpoint string used with nock, which will be expanded to - // https://:443/ and therefore will not match, so we have to do - // this instead. - (recording: string): string => { - const replaced = recording.replace("endpoint:443", "endpoint"); - return replaced; - }, - ], - queryParametersToSkip: [], +const recorderOptions: RecorderStartOptions = { + envSetupForPlayback: replaceableVariables, }; -export function createClient(options?: ClientOptions): PurviewScanningRestClient { - const httpClient = isNode || isLiveMode() ? undefined : createXhrHttpClient(); - const credential = new ClientSecretCredential( - env.AZURE_TENANT_ID, - env.AZURE_CLIENT_ID, - env.AZURE_CLIENT_SECRET, - { httpClient } +export async function createClient( + recorder: Recorder, + options?: ClientOptions +): Promise { + const credential = createTestCredential(); + await recorder.start(recorderOptions); + return PurviewScanning( + env.ENDPOINT ?? "", + credential, + recorder.configureClientOptions({ ...options }) ); - return PurviewScanning(env.ENDPOINT, credential, { httpClient, ...options }); -} - -/** - * creates the recorder and reads the environment variables from the `.env` file. - * Should be called first in the test suite to make sure environment variables are - * read before they are being used. - */ -export function createRecorder(context: Context): Recorder { - return record(context, environmentSetup); }