mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-07-23 05:47:24 +01:00
Make playwright test environment more dynamic (#2532)
* Update Az CLI to use new secrets. * Add test step for Az login * Remove test step. Fix up account names in test code. * Fix the account prefix env. variable. * Fix it in the CI config as well. * Try to fix the CI config for some tests * Clean up access tokens for NoSQL. * Disable most tests while sorting out account setup. Add debug tracing. * Comment out most tests. * Set RG Name var in CI config. * Fix up tenant id. * Enable other API tests * e-enable more tests. * Re-enable remaining tests. * Remove all of the test.skip() calls. * Remove debug traces. * Remove function to retrieve SQL RBAC token, this is handled by the CI config now. * Fix rbac token detection for table and resource token tests. * Minor cleanup and fixing the cleanup config. * Preview site and storage changes. Cleanup script changes. * Clean up before PR. * Fix resource group name in test results email.
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
export function getNoSqlRbacToken(): string | undefined {
|
||||
let nosqlRbacToken: string | undefined;
|
||||
const shardIndex = process.env.PLAYWRIGHT_SHARD_INDEX ?? "";
|
||||
switch (parseInt(shardIndex)) {
|
||||
case 1:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_1_TOKEN;
|
||||
break;
|
||||
case 2:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_2_TOKEN;
|
||||
break;
|
||||
case 3:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_3_TOKEN;
|
||||
break;
|
||||
case 4:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_4_TOKEN;
|
||||
break;
|
||||
case 5:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_5_TOKEN;
|
||||
break;
|
||||
case 6:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_6_TOKEN;
|
||||
break;
|
||||
case 7:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_7_TOKEN;
|
||||
break;
|
||||
case 8:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_8_TOKEN;
|
||||
break;
|
||||
case 9:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_9_TOKEN;
|
||||
break;
|
||||
case 10:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_10_TOKEN;
|
||||
break;
|
||||
case 11:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_11_TOKEN;
|
||||
break;
|
||||
case 12:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_12_TOKEN;
|
||||
break;
|
||||
case 13:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_13_TOKEN;
|
||||
break;
|
||||
case 14:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_14_TOKEN;
|
||||
break;
|
||||
case 15:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_15_TOKEN;
|
||||
break;
|
||||
case 16:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_16_TOKEN;
|
||||
break;
|
||||
case 17:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_17_TOKEN;
|
||||
break;
|
||||
case 18:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_18_TOKEN;
|
||||
break;
|
||||
case 19:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_19_TOKEN;
|
||||
break;
|
||||
case 20:
|
||||
nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_20_TOKEN;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!nosqlRbacToken) {
|
||||
console.warn(`No NoSQL RBAC token found for shard index ${shardIndex}`);
|
||||
}
|
||||
return nosqlRbacToken;
|
||||
}
|
||||
+21
-12
@@ -1,7 +1,6 @@
|
||||
import { DefaultAzureCredential } from "@azure/identity";
|
||||
import { Frame, Locator, Page, expect } from "@playwright/test";
|
||||
import crypto from "crypto";
|
||||
import { getNoSqlRbacToken } from "./NoSqlTestSetup";
|
||||
import { TestContainerContext } from "./testData";
|
||||
|
||||
const RETRY_COUNT = 3;
|
||||
@@ -45,29 +44,34 @@ export enum TestAccount {
|
||||
}
|
||||
|
||||
export function getDefaultAccountName(accountType: TestAccount): string {
|
||||
const accountNamePrefix = process.env.DE_ACCOUNT_PREFIX;
|
||||
if (!accountNamePrefix) {
|
||||
throw new Error("DE_ACCOUNT_PREFIX is not set");
|
||||
}
|
||||
|
||||
switch (accountType) {
|
||||
case TestAccount.Tables:
|
||||
return "github-e2etests-tables";
|
||||
return `${accountNamePrefix}-de-test-table-1`;
|
||||
case TestAccount.Cassandra:
|
||||
return "github-e2etests-cassandra";
|
||||
return `${accountNamePrefix}-de-test-cassandra-1`;
|
||||
case TestAccount.Gremlin:
|
||||
return "github-e2etests-gremlin";
|
||||
return `${accountNamePrefix}-de-test-gremlin-1`;
|
||||
case TestAccount.Mongo:
|
||||
return "github-e2etests-mongo";
|
||||
return `${accountNamePrefix}-de-test-mongo-1`;
|
||||
case TestAccount.MongoReadonly:
|
||||
return "github-e2etests-mongo-readonly";
|
||||
return `${accountNamePrefix}-de-test-mongo-readonly`;
|
||||
case TestAccount.Mongo32:
|
||||
return "github-e2etests-mongo32";
|
||||
return `${accountNamePrefix}-de-test-mongo32-1`;
|
||||
case TestAccount.SQLReadOnly:
|
||||
return "github-e2etests-sql-readonly";
|
||||
return `${accountNamePrefix}-de-test-sql-readonly`;
|
||||
case TestAccount.SQLContainerCopyOnly:
|
||||
return "github-e2etests-sql-containercopyonly";
|
||||
return `${accountNamePrefix}-de-test-sql-containercopy`;
|
||||
case TestAccount.SQL: {
|
||||
const shardIndex = process.env.PLAYWRIGHT_SHARD_INDEX ?? "";
|
||||
if (!shardIndex) {
|
||||
throw new Error("PLAYWRIGHT_SHARD_INDEX is not set");
|
||||
}
|
||||
return "github-e2etests-sql-" + shardIndex;
|
||||
return `${accountNamePrefix}-de-test-sql-${shardIndex}`;
|
||||
}
|
||||
default:
|
||||
throw new Error(`No default account name defined for account type ${accountType}`);
|
||||
@@ -75,7 +79,7 @@ export function getDefaultAccountName(accountType: TestAccount): string {
|
||||
}
|
||||
|
||||
export const resourceGroupName = process.env.DE_TEST_RESOURCE_GROUP ?? "de-e2e-tests";
|
||||
export const subscriptionId = process.env.DE_TEST_SUBSCRIPTION_ID ?? "69e02f2d-f059-4409-9eac-97e8a276ae2c";
|
||||
export const subscriptionId = process.env.DE_TEST_SUBSCRIPTION_ID ?? process.env.AZURE_SUBSCRIPTION_ID ?? "";
|
||||
export const TEST_AUTOSCALE_THROUGHPUT_RU = 1000;
|
||||
export const TEST_MANUAL_THROUGHPUT_RU = 800;
|
||||
export const TEST_AUTOSCALE_MAX_THROUGHPUT_RU_2K = 2000;
|
||||
@@ -117,11 +121,16 @@ export async function getTestExplorerUrl(accountType: TestAccount, options?: Tes
|
||||
params.set("subscriptionId", subscriptionId);
|
||||
params.set("token", token);
|
||||
|
||||
const tenantId = process.env.AZURE_TENANT_ID;
|
||||
if (tenantId) {
|
||||
params.set("tenantId", tenantId);
|
||||
}
|
||||
|
||||
// There seem to be occasional CORS issues with calling the copilot APIs (/api/tokens/sampledataconnection/v2, for example)
|
||||
// For now, since we don't test copilot, we can disable the copilot APIs by setting the feature flag to false.
|
||||
params.set("feature.enableCopilot", "false");
|
||||
|
||||
const nosqlRbacToken = getNoSqlRbacToken();
|
||||
const nosqlRbacToken = process.env.NOSQL_TESTACCOUNT_TOKEN;
|
||||
|
||||
const nosqlReadOnlyRbacToken = process.env.NOSQL_READONLY_TESTACCOUNT_TOKEN;
|
||||
const nosqlContainerCopyRbacToken = process.env.NOSQL_CONTAINERCOPY_TESTACCOUNT_TOKEN;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { setupCORSBypass } from "../CORSBypass";
|
||||
import { DataExplorer, QueryTab, TestAccount, CommandBarButton, Editor } from "../fx";
|
||||
import { CommandBarButton, DataExplorer, Editor, QueryTab, TestAccount } from "../fx";
|
||||
import { serializeMongoToJson } from "../testData";
|
||||
|
||||
const databaseId = "test-e2etests-mongo-pagination";
|
||||
|
||||
@@ -11,10 +11,9 @@ import {
|
||||
resourceGroupName,
|
||||
subscriptionId,
|
||||
} from "../fx";
|
||||
import { getNoSqlRbacToken } from "../NoSqlTestSetup";
|
||||
|
||||
test("SQL account using Resource token", async ({ page }) => {
|
||||
const nosqlAccountRbacToken = getNoSqlRbacToken() ?? "";
|
||||
const nosqlAccountRbacToken = process.env.NOSQL_TESTACCOUNT_TOKEN ?? "";
|
||||
test.skip(nosqlAccountRbacToken.length > 0, "Resource tokens not supported when using data plane RBAC.");
|
||||
|
||||
const credentials = getAzureCLICredentials();
|
||||
|
||||
+1
-2
@@ -18,7 +18,6 @@ import {
|
||||
subscriptionId,
|
||||
TestAccount,
|
||||
} from "./fx";
|
||||
import { getNoSqlRbacToken } from "./NoSqlTestSetup";
|
||||
|
||||
// In Node.js >= 19, globalThis.crypto is already available as a read-only getter.
|
||||
// Only assign the polyfill for older versions.
|
||||
@@ -135,7 +134,7 @@ async function createCosmosClientForSQLAccount(
|
||||
|
||||
const rbacToken =
|
||||
accountType === TestAccount.SQL
|
||||
? getNoSqlRbacToken()
|
||||
? process.env.NOSQL_TESTACCOUNT_TOKEN
|
||||
: accountType === TestAccount.SQLContainerCopyOnly
|
||||
? process.env.NOSQL_CONTAINERCOPY_TESTACCOUNT_TOKEN
|
||||
: "";
|
||||
|
||||
@@ -3,7 +3,6 @@ import "../../less/hostedexplorer.less";
|
||||
import { DataExplorerInputsFrame } from "../../src/Contracts/ViewModels";
|
||||
import { updateUserContext } from "../../src/UserContext";
|
||||
import { get, listKeys } from "../../src/Utils/arm/generatedClients/cosmos/databaseAccounts";
|
||||
import { getNoSqlRbacToken } from "../NoSqlTestSetup";
|
||||
|
||||
const urlSearchParams = new URLSearchParams(window.location.search);
|
||||
const resourceGroup = urlSearchParams.get("resourceGroup") || process.env.RESOURCE_GROUP || "";
|
||||
@@ -16,7 +15,7 @@ const enablecontainercopy = urlSearchParams.get("enablecontainercopy");
|
||||
|
||||
const nosqlRbacToken =
|
||||
urlSearchParams.get("nosqlRbacToken") ||
|
||||
(enablecontainercopy ? process.env.NOSQL_CONTAINERCOPY_TESTACCOUNT_TOKEN : getNoSqlRbacToken()) ||
|
||||
(enablecontainercopy ? process.env.NOSQL_CONTAINERCOPY_TESTACCOUNT_TOKEN : process.env.NOSQL_TESTACCOUNT_TOKEN) ||
|
||||
"";
|
||||
|
||||
const nosqlReadOnlyRbacToken =
|
||||
@@ -30,6 +29,7 @@ const mongoRbacToken = urlSearchParams.get("mongoRbacToken") || process.env.MONG
|
||||
const mongo32RbacToken = urlSearchParams.get("mongo32RbacToken") || process.env.MONGO32_TESTACCOUNT_TOKEN || "";
|
||||
const mongoReadOnlyRbacToken =
|
||||
urlSearchParams.get("mongoReadOnlyRbacToken") || process.env.MONGO_READONLY_TESTACCOUNT_TOKEN || "";
|
||||
const tenantId = urlSearchParams.get("tenantId") || process.env.AZURE_TENANT_ID || "";
|
||||
|
||||
const initTestExplorer = async (): Promise<void> => {
|
||||
updateUserContext({
|
||||
@@ -51,7 +51,7 @@ const initTestExplorer = async (): Promise<void> => {
|
||||
case "gremlin":
|
||||
rbacToken = gremlinRbacToken;
|
||||
break;
|
||||
case "tables":
|
||||
case "table":
|
||||
rbacToken = tableRbacToken;
|
||||
break;
|
||||
case "cassandra":
|
||||
@@ -90,6 +90,7 @@ const initTestExplorer = async (): Promise<void> => {
|
||||
resourceGroup,
|
||||
authorizationToken: `Bearer ${authToken}`,
|
||||
aadToken: rbacToken,
|
||||
tenantId,
|
||||
features: {},
|
||||
containerCopyEnabled: enablecontainercopy === "true",
|
||||
hasWriteAccess: true,
|
||||
|
||||
Reference in New Issue
Block a user