Skip to content

Commit 50b4457

Browse files
authored
fix(cloudloggingadmin): increase log injesting time and add auth test (#2772)
Addresses flakiness in the list log names test, which was suspected to caused by querying logs before they were fully ingested. Adds a new success path test case for `runAuthListLogNamesTest`.
1 parent 5c92e39 commit 50b4457

1 file changed

Lines changed: 38 additions & 11 deletions

File tree

‎tests/cloudloggingadmin/cloud_logging_admin_integration_test.go‎

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ func TestLogAdminToolEndpoints(t *testing.T) {
105105

106106
// set up test logs and wait for logs to be injested.
107107
setupTestLogs(t, loggingClient, logName)
108-
t.Logf("Waiting 15 seconds for log ingestion...")
109-
time.Sleep(15 * time.Second)
108+
t.Logf("Waiting 30 seconds for log ingestion...")
109+
time.Sleep(30 * time.Second)
110110

111111
// Delete test logs once test is over
112112
defer teardownTestLogs(t, ctx, LogAdminProject, logName)
@@ -230,6 +230,42 @@ func runListLogNamesTest(t *testing.T, expectedLogName string) {
230230
})
231231
}
232232

233+
func runAuthListLogNamesTest(t *testing.T, expectedLogName string) {
234+
idToken, err := tests.GetGoogleIdToken(tests.ClientId)
235+
if err != nil {
236+
t.Fatalf("error getting Google ID token: %s", err)
237+
}
238+
requestHeader := map[string]string{"my-google-auth_token": idToken}
239+
t.Run("auth-list-log-names", func(t *testing.T) {
240+
resp, respBody := tests.RunRequest(t, http.MethodPost, "http://127.0.0.1:5000/api/tool/auth-list-log-names/invoke", bytes.NewBuffer([]byte(`{}`)), requestHeader)
241+
defer resp.Body.Close()
242+
243+
if resp.StatusCode != 200 {
244+
t.Fatalf("expected status 200, got %d", resp.StatusCode)
245+
}
246+
247+
var body map[string]interface{}
248+
if err := json.Unmarshal(respBody, &body); err != nil {
249+
t.Fatalf("error parsing response body")
250+
}
251+
252+
result, ok := body["result"].(string)
253+
if !ok {
254+
t.Fatalf("expected result to be string")
255+
}
256+
257+
if !strings.Contains(result, expectedLogName) {
258+
t.Errorf("expected log name %s not found in result: %s", expectedLogName, result)
259+
}
260+
})
261+
t.Run("auth-list-log-names-missing-header", func(t *testing.T) {
262+
resp, _ := tests.RunRequest(t, http.MethodPost, "http://127.0.0.1:5000/api/tool/auth-list-log-names/invoke", bytes.NewBuffer([]byte(`{}`)), nil)
263+
if resp.StatusCode != 401 {
264+
t.Fatalf("expected status 401 (Unauthorized), got %d", resp.StatusCode)
265+
}
266+
})
267+
}
268+
233269
func runListResourceTypesTest(t *testing.T) {
234270
t.Run("list-resource-types", func(t *testing.T) {
235271
resp, respBody := tests.RunRequest(t, http.MethodPost, "http://127.0.0.1:5000/api/tool/list-resource-types/invoke", bytes.NewBuffer([]byte(`{}`)), nil)
@@ -319,15 +355,6 @@ func invokeQueryTool(t *testing.T, requestBody string) string {
319355
return result
320356
}
321357

322-
func runAuthListLogNamesTest(t *testing.T, expectedLogName string) {
323-
t.Run("auth-list-log-names", func(t *testing.T) {
324-
resp, _ := tests.RunRequest(t, http.MethodPost, "http://127.0.0.1:5000/api/tool/auth-list-log-names/invoke", bytes.NewBuffer([]byte(`{}`)), nil)
325-
if resp.StatusCode != 401 {
326-
t.Fatalf("expected status 401 (Unauthorized), got %d", resp.StatusCode)
327-
}
328-
})
329-
}
330-
331358
func runQueryLogsErrorTest(t *testing.T) {
332359
t.Run("query-logs-error", func(t *testing.T) {
333360
requestBody := `{"filter": "INVALID_FILTER_SYNTAX :::", "limit": 10}`

0 commit comments

Comments
 (0)