Skip to content

Commit b0f6dff

Browse files
committed
test(source/cloud-storage): log teardown iterator errors and cover pageSize bounds
Cleanup loop in the integration test was treating any iterator error as iterator.Done; now distinguishes the two and logs non-Done errors so flaky teardowns are debuggable. Also adds an internal unit test for pageSize covering 0, negative, in-range, and over-cap inputs.
1 parent 91a459c commit b0f6dff

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cloudstorage
16+
17+
import "testing"
18+
19+
func TestPageSize(t *testing.T) {
20+
tcs := []struct {
21+
in int
22+
want int
23+
}{
24+
{in: 0, want: 1000},
25+
{in: -1, want: 1000},
26+
{in: 1, want: 1},
27+
{in: 500, want: 500},
28+
{in: 1000, want: 1000},
29+
{in: 1001, want: 1000},
30+
{in: 1_000_000, want: 1000},
31+
}
32+
for _, tc := range tcs {
33+
if got := pageSize(tc.in); got != tc.want {
34+
t.Errorf("pageSize(%d) = %d, want %d", tc.in, got, tc.want)
35+
}
36+
}
37+
}

tests/cloudstorage/cloud_storage_integration_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/google/uuid"
3333
"github.com/googleapis/mcp-toolbox/internal/testutils"
3434
"github.com/googleapis/mcp-toolbox/tests"
35+
"google.golang.org/api/iterator"
3536
"google.golang.org/api/option"
3637
)
3738

@@ -164,8 +165,11 @@ func setupCloudStorageTestData(t *testing.T, ctx context.Context, client *storag
164165
it := bkt.Objects(cleanupCtx, nil)
165166
for {
166167
attrs, err := it.Next()
168+
if err == iterator.Done {
169+
break
170+
}
167171
if err != nil {
168-
// iterator.Done or another error: stop iterating and attempt bucket delete.
172+
t.Logf("cleanup: iterator error, aborting object delete loop: %v", err)
169173
break
170174
}
171175
if delErr := bkt.Object(attrs.Name).Delete(cleanupCtx); delErr != nil {

0 commit comments

Comments
 (0)