From b0f0d802ce55d0a4adc5dd74ad3fef36bd4fc58b Mon Sep 17 00:00:00 2001 From: nicoleczhu Date: Thu, 29 Oct 2020 14:47:29 -0700 Subject: [PATCH 1/2] test(logging): add back DeleteLog test --- logging/logging_test.go | 47 ++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/logging/logging_test.go b/logging/logging_test.go index 0e511ba141b6..132a09a7ed06 100644 --- a/logging/logging_test.go +++ b/logging/logging_test.go @@ -473,38 +473,27 @@ func TestPing(t *testing.T) { } } -func TestLogsAndDelete(t *testing.T) { - t.Skip("https://github.com/googleapis/google-cloud-go/issues/1654") - - // This function tests both the Logs and DeleteLog methods. We only try to - // delete those logs that we can observe and that were generated by this - // test. This may not include the logs generated from the current test run, - // because the logging service is only eventually consistent. It's - // therefore possible that on some runs, this test will do nothing. +func TestDeleteLog(t *testing.T) { ctx := context.Background() - it := aclient.Logs(ctx) - nDeleted := 0 - for { - logID, err := it.Next() - if err == iterator.Done { - break - } - if err != nil { - t.Fatal(err) - } - if strings.HasPrefix(logID, testLogIDPrefix) { - if err := aclient.DeleteLog(ctx, logID); err != nil { - // Ignore NotFound. Sometimes, amazingly, DeleteLog cannot find - // a log that is returned by Logs. - if status.Code(err) != codes.NotFound { - t.Fatalf("deleting %q: %v", logID, err) - } - } else { - nDeleted++ - } + initLogs() + c, a := newClients(ctx, testProjectID) + defer c.Close() + defer a.Close() + lg := c.Logger(testLogID) + err := lg.LogSync(ctx, logging.Entry{Payload: "hello"}) + if err != nil { + t.Fatal(err) + } + + if err := aclient.DeleteLog(ctx, testLogID); err != nil { + // Ignore NotFound. Sometimes, amazingly, DeleteLog cannot find + // a log that is returned by Logs. + if status.Code(err) != codes.NotFound { + t.Fatalf("deleting %q: %v", testLogID, err) } + } else { + t.Logf("deleted log_id: %q", testLogID) } - t.Logf("deleted %d logs", nDeleted) } func TestNonProjectParent(t *testing.T) { From b7412731c2b4aabf36511f5fc77dc498969ea4b7 Mon Sep 17 00:00:00 2001 From: nicoleczhu Date: Fri, 30 Oct 2020 08:08:49 -0700 Subject: [PATCH 2/2] style(logging): collapse error handling on same line as err return --- logging/logging_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logging/logging_test.go b/logging/logging_test.go index 132a09a7ed06..2c5d6d76aa32 100644 --- a/logging/logging_test.go +++ b/logging/logging_test.go @@ -480,8 +480,8 @@ func TestDeleteLog(t *testing.T) { defer c.Close() defer a.Close() lg := c.Logger(testLogID) - err := lg.LogSync(ctx, logging.Entry{Payload: "hello"}) - if err != nil { + + if err := lg.LogSync(ctx, logging.Entry{Payload: "hello"}); err != nil { t.Fatal(err) }