Skip to content

Commit

Permalink
Add TLD identifier to premium terms filename and header (#2644)
Browse files Browse the repository at this point in the history
https://b.corp.google.com/issues/390053672

This makes it easier to identify what file you're looking at, at a
glance
  • Loading branch information
gbrodman authored Jan 24, 2025
1 parent 5e97a8b commit 653e092
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class ExportPremiumTermsAction implements Runnable {

private static final FluentLogger logger = FluentLogger.forEnclosingClass();
static final MediaType EXPORT_MIME_TYPE = MediaType.PLAIN_TEXT_UTF_8;
static final String PREMIUM_TERMS_FILENAME = "CONFIDENTIAL_premium_terms.txt";
static final String TLD_IDENTIFIER_FORMAT = "# TLD: %s";
static final String PREMIUM_TERMS_FILENAME_FORMAT = "CONFIDENTIAL_premium_terms_%s.txt";

@Inject DriveConnection driveConnection;

Expand Down Expand Up @@ -127,7 +128,7 @@ private String exportPremiumTerms(Tld tld) {
try {
String fileId =
driveConnection.createOrUpdateFile(
PREMIUM_TERMS_FILENAME,
String.format(PREMIUM_TERMS_FILENAME_FORMAT, tldStr),
EXPORT_MIME_TYPE,
tld.getDriveFolderId(),
getFormattedPremiumTerms(tld).getBytes(UTF_8));
Expand All @@ -150,11 +151,9 @@ private String getFormattedPremiumTerms(Tld tld) {
.map(PremiumEntry::toString)
.collect(ImmutableSortedSet.toImmutableSortedSet(String::compareTo));

return Joiner.on("\n")
.appendTo(
new StringBuilder(),
Iterables.concat(ImmutableList.of(exportDisclaimer.trim()), premiumTerms))
.append("\n")
.toString();
String tldIdentifier = String.format(TLD_IDENTIFIER_FORMAT, tldStr);
Iterable<String> commentsAndTerms =
Iterables.concat(ImmutableList.of(exportDisclaimer.trim(), tldIdentifier), premiumTerms);
return Joiner.on("\n").join(commentsAndTerms) + "\n";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.export.ExportPremiumTermsAction.EXPORT_MIME_TYPE;
import static google.registry.export.ExportPremiumTermsAction.PREMIUM_TERMS_FILENAME;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.deleteTld;
import static google.registry.testing.DatabaseHelper.persistResource;
Expand Down Expand Up @@ -52,11 +51,10 @@
/** Unit tests for {@link ExportPremiumTermsAction}. */
public class ExportPremiumTermsActionTest {

private static final String DISCLAIMER_WITH_NEWLINE = "# Premium Terms Export Disclaimer\n";
private static final ImmutableList<String> PREMIUM_NAMES =
ImmutableList.of("2048,USD 549", "0,USD 549");
private static final String EXPECTED_FILE_CONTENT =
DISCLAIMER_WITH_NEWLINE + "0, 549.00\n" + "2048, 549.00\n";
"# Premium Terms Export Disclaimer\n# TLD: tld\n0, 549.00\n" + "2048, 549.00\n";

@RegisterExtension
final JpaIntegrationTestExtension jpa =
Expand All @@ -69,7 +67,7 @@ private void runAction(String tld) {
ExportPremiumTermsAction action = new ExportPremiumTermsAction();
action.response = response;
action.driveConnection = driveConnection;
action.exportDisclaimer = DISCLAIMER_WITH_NEWLINE;
action.exportDisclaimer = "# Premium Terms Export Disclaimer\n";
action.tldStr = tld;
action.run();
}
Expand All @@ -94,7 +92,7 @@ void test_exportPremiumTerms_success() throws IOException {

verify(driveConnection)
.createOrUpdateFile(
PREMIUM_TERMS_FILENAME,
"CONFIDENTIAL_premium_terms_tld.txt",
EXPORT_MIME_TYPE,
"folder_id",
EXPECTED_FILE_CONTENT.getBytes(UTF_8));
Expand Down Expand Up @@ -157,7 +155,7 @@ void testExportPremiumTerms_failure_driveIdThrowsException() throws IOException

verify(driveConnection)
.createOrUpdateFile(
PREMIUM_TERMS_FILENAME,
"CONFIDENTIAL_premium_terms_tld.txt",
EXPORT_MIME_TYPE,
"bad_folder_id",
EXPECTED_FILE_CONTENT.getBytes(UTF_8));
Expand Down

0 comments on commit 653e092

Please sign in to comment.