Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(logging): add back DeleteLog test #3114

Merged
merged 3 commits into from
Oct 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 18 additions & 29 deletions logging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: combine with if check below if err := lg.LogSync(ctx, logging.Entry{Payload: "hello"}); err != nil { ...}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted for future , thanks!

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) {
Expand Down