Skip to content

Commit

Permalink
test: fix codegen test
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jul 22, 2021
1 parent d2228a9 commit 37212cc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void awsClient() {

// Check config files
assertThat(manifest.getFileString("runtimeConfig.ts").get(),
containsString("credentialDefaultProvider: decorateDefaultCredentialProvider"));
containsString("decorateDefaultCredentialProvider"));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("Credential is missing"));
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), not(containsString("signingName:")));

Expand Down Expand Up @@ -81,7 +81,7 @@ public void sigV4GenericClient() {

// Check config files
assertThat(manifest.getFileString("runtimeConfig.ts").get(),
containsString("credentialDefaultProvider: decorateDefaultCredentialProvider"));
containsString("decorateDefaultCredentialProvider"));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("Credential is missing"));
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), containsString("signingName:"));

Expand Down Expand Up @@ -120,7 +120,7 @@ public void notSigV4GenericClient() {

// Check config files
assertThat(manifest.getFileString("runtimeConfig.ts").get(),
not(containsString("credentialDefaultProvider: decorateDefaultCredentialProvider")));
not(containsString("decorateDefaultCredentialProvider")));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), not(containsString("Credential is missing")));
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), not(containsString("signingName:")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public void awsClient() {
assertThat(manifest.getFileString("NotSameClient.ts").get(), containsString("region?:"));

// Check config files
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), containsString("serviceId: \"Not Same\""));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("region: invalidProvider"));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("region: loadNodeConfig"));
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), containsString("serviceId: config.serviceId ?? \"Not Same\""));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("region: config.region ?? invalidProvider"));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("region: config.region ?? loadNodeConfig"));
}

@Test
Expand Down Expand Up @@ -81,8 +81,8 @@ public void sigV4GenericClient() {

// Check config files
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), not(containsString("serviceId:")));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("region: invalidProvider"));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("region: loadNodeConfig"));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("region: config.region ?? invalidProvider"));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("region: config.region ?? loadNodeConfig"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public void awsClient() {
// Check config files
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("defaultUserAgent"));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("packageInfo.version"));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("ClientSharedValues.serviceId"));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("clientSharedValues.serviceId"));

assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("defaultUserAgent"));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("packageInfo.version"));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("ClientSharedValues.serviceId"));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("clientSharedValues.serviceId"));

// Check the config resolution and middleware plugin
assertThat(manifest.getFileString("NotSameClient.ts").get(), containsString("resolveUserAgentConfig"));
Expand Down
71 changes: 51 additions & 20 deletions scripts/generate-clients/copy-to-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,39 @@ const { normalize, join } = require("path");
const { copySync, removeSync } = require("fs-extra");
const { readdirSync, lstatSync, readFileSync, existsSync, writeFileSync } = require("fs");

const getOverwritablePredicate = (packageName) => (pathName) => {
const overwritablePathnames = [
// const getOverwritablePredicate = (packageName) => (pathName) => {
// const overwritablePathnames = [
// "commands",
// "models",
// "protocols",
// "pagination",
// "tests",
// "waiters",
// "LICENCE",
// "runtimeConfig.ts",
// "runtimeConfig.browser.ts",
// "runtimeConfig.shared.ts",
// "runtimeConfig.native.ts",
// "index.ts",
// "endpoints.ts",
// "README.md",
// ];
// const additionalGeneratedFiles = {
// "@aws-sdk/client-sts": ["defaultRoleAssumers.ts", "defaultStsRoleAssumers.ts", "defaultRoleAssumers.spec.ts"],
// };
// return (
// // pathName
// // .toLowerCase()
// // .startsWith(
// // packageName.toLowerCase().replace("@aws-sdk/client-", "").replace("@aws-sdk/aws-", "").replace(/-/g, "")
// // ) ||
// pathName.endsWith("Client.ts") &&
// overwritablePathnames.indexOf(pathName) >= 0 ||
// additionalGeneratedFiles[packageName.toLowerCase()]?.indexOf(pathName) >= 0
// );
// };
const getOverwritableDirectories = (subDirectories) => {
const overwritableDirectories = [
"commands",
"models",
"protocols",
Expand All @@ -19,19 +50,17 @@ const getOverwritablePredicate = (packageName) => (pathName) => {
"index.ts",
"endpoints.ts",
"README.md",
// @aws-sdk/client-sts special files
"defaultRoleAssumers.ts",
"defaultStsRoleAssumers.ts",
"defaultRoleAssumers.spec.ts",
];
const additionalGeneratedFiles = {
"@aws-sdk/client-sts": ["defaultRoleAssumers.ts", "defaultStsRoleAssumers.ts", "defaultRoleAssumers.spec.ts"],
};
return (
pathName
.toLowerCase()
.startsWith(
packageName.toLowerCase().replace("@aws-sdk/client-", "").replace("@aws-sdk/aws-", "").replace(/-/g, "")
) ||
overwritablePathnames.indexOf(pathName) >= 0 ||
additionalGeneratedFiles[packageName.toLowerCase()]?.indexOf(pathName) >= 0
);
return subDirectories.filter((subDirectory) => {
const isBareBoneClient =
subDirectory.endsWith("Client.ts") && subDirectories.includes(subDirectory.replace("Client.ts", ".ts"));
const isAggregateClient = subDirectories.includes(subDirectory.replace(".ts", "Client.ts"));
return isBareBoneClient || isAggregateClient || overwritableDirectories.indexOf(subDirectory) >= 0;
});
};

/**
Expand Down Expand Up @@ -109,7 +138,6 @@ const copyToClients = async (sourceDir, destinationDir) => {

console.log(`copying ${packageName} from ${artifactPath} to ${destinationDir}`);
const destPath = join(destinationDir, clientName);
const overwritablePredicate = getOverwritablePredicate(packageName);

// Code to move files/folders prefixed with `doc-client-` to `lib/lib-dynamodb`
if (clientName === "client-dynamodb") {
Expand All @@ -124,7 +152,9 @@ const copyToClients = async (sourceDir, destinationDir) => {
}
}

for (const packageSub of readdirSync(artifactPath)) {
const packageSubs = readdirSync(artifactPath);
const overWritableSubs = getOverwritableDirectories(packageSubs);
for (const packageSub of packageSubs) {
const packageSubPath = join(artifactPath, packageSub);
const destSubPath = join(destPath, packageSub);

Expand All @@ -141,7 +171,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
},
};
writeFileSync(destSubPath, JSON.stringify(mergedManifest, null, 2).concat(`\n`));
} else if (overwritablePredicate(packageSub) || !existsSync(destSubPath)) {
} else if (overWritableSubs.includes(packageSub) || !existsSync(destSubPath)) {
if (lstatSync(packageSubPath).isDirectory()) removeSync(destSubPath);
copySync(packageSubPath, destSubPath, {
overwrite: true,
Expand All @@ -168,9 +198,10 @@ const copyServerTests = async (sourceDir, destinationDir) => {

console.log(`copying ${packageName} from ${artifactPath} to ${destinationDir}`);
const destPath = join(destinationDir, testName);
const overwritablePredicate = getOverwritablePredicate(packageName);

for (const packageSub of readdirSync(artifactPath)) {
const packageSubs = readdirSync(artifactPath);
const overWritableSubs = getOverwritableDirectories(packageSubs);
for (const packageSub of packageSubs) {
const packageSubPath = join(artifactPath, packageSub);
const destSubPath = join(destPath, packageSub);

Expand All @@ -187,7 +218,7 @@ const copyServerTests = async (sourceDir, destinationDir) => {
},
};
writeFileSync(destSubPath, JSON.stringify(mergedManifest, null, 2).concat(`\n`));
} else if (overwritablePredicate(packageSub) || !existsSync(destSubPath)) {
} else if (overWritableSubs.includes(packageSub) || !existsSync(destSubPath)) {
if (lstatSync(packageSubPath).isDirectory()) removeSync(destSubPath);
copySync(packageSubPath, destSubPath, {
overwrite: true,
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-clients/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const {
await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
await copyServerTests(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR, PROTOCOL_TESTS_CLIENTS_DIR);

emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
// emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
emptyDirSync(TEMP_CODE_GEN_INPUT_DIR);

rmdirSync(TEMP_CODE_GEN_INPUT_DIR);
Expand Down

0 comments on commit 37212cc

Please sign in to comment.