Skip to content

Commit

Permalink
chore(tests): refactoring tests
Browse files Browse the repository at this point in the history
Test ListLogs.printLogNames vs audit logs to save time.
Restore retrieval of log entries in the wait loop to ensure printing to STDOUT
  • Loading branch information
minherz committed Jul 30, 2021
1 parent 7b49562 commit 3b70732
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -39,6 +39,7 @@
public class LoggingIT {

private static final String TEST_LOG = "test-log";
private static final String GOOGLEAPIS_AUDIT_LOGNAME = "cloudaudit.googleapis.com%2Factivity";
private static final String STRING_PAYLOAD = "Hello, world!";
private static final String STRING_PAYLOAD2 = "Hello world again";

Expand Down Expand Up @@ -85,9 +86,9 @@ public void testWriteAndListLogs() throws Exception {
logging.flush();
bout.reset();

ListLogs.main(TEST_LOG);
// Check for mocked STDOUT having data
while (bout.toString().isEmpty()) {
ListLogs.printLogEntries(TEST_LOG);
Thread.sleep(5000);
}
assertThat(bout.toString().contains(STRING_PAYLOAD2)).isTrue();
Expand All @@ -108,9 +109,9 @@ public void testWriteLogHttpRequest() throws Exception {
assertThat(got).contains(String.format("Logged: %s", STRING_PAYLOAD));
bout.reset();

ListLogs.printLogEntries(TEST_LOG);
// Check for mocked STDOUT having data
while (bout.toString().isEmpty()) {
ListLogs.printLogEntries(TEST_LOG);
Thread.sleep(5000);
}

Expand All @@ -121,12 +122,12 @@ public void testWriteLogHttpRequest() throws Exception {

@Test(timeout = 60000)
public void testListLogNames() throws Exception {
QuickstartSample.main(TEST_LOG);
ListLogs.printLogNames();
// Check for mocked STDOUT having data
while (bout.toString().isEmpty()) {
Thread.sleep(5000);
}
assertThat(bout.toString().contains(TEST_LOG)).isTrue();

assertThat(bout.toString().contains(GOOGLEAPIS_AUDIT_LOGNAME)).isTrue();
}
}

0 comments on commit 3b70732

Please sign in to comment.