Skip to content

Commit baca2f7

Browse files
committed
added error-rt gcs test
Signed-off-by: milinddethe15 <[email protected]>
1 parent d7e663b commit baca2f7

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

providers/gcs/fakecred.json

-9
This file was deleted.

providers/gcs/gcs.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ type Config struct {
5252
// ChunkSizeBytes controls the maximum number of bytes of the object that the
5353
// Writer will attempt to send to the server in a single request
5454
// Used as storage.Writer.ChunkSize of https://pkg.go.dev/google.golang.org/cloud/storage#Writer
55-
ChunkSizeBytes int `yaml:"chunk_size_bytes"`
55+
ChunkSizeBytes int `yaml:"chunk_size_bytes"`
56+
noAuth bool `yaml:"no_auth"`
5657
}
5758

5859
// Bucket implements the store.Bucket and shipper.Bucket interfaces against GCS.
@@ -102,7 +103,9 @@ func NewBucketWithConfig(ctx context.Context, logger log.Logger, gc Config, comp
102103
}
103104
opts = append(opts, option.WithCredentials(credentials))
104105
}
105-
106+
if gc.noAuth {
107+
opts = append(opts, option.WithoutAuthentication())
108+
}
106109
opts = append(opts,
107110
option.WithUserAgent(fmt.Sprintf("thanos-%s/%s (%s)", component, version.Version, runtime.Version())),
108111
)

providers/gcs/gcs_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,16 @@ func TestNewBucketWithErrorRoundTripper(t *testing.T) {
167167
Bucket: "test-bucket",
168168
ServiceAccount: "",
169169
UseGRPC: false,
170+
noAuth: true,
170171
}
171-
svr, err := gcsemu.NewServer("127.0.0.1:43649", gcsemu.Options{})
172+
svr, err := gcsemu.NewServer("127.0.0.1:0", gcsemu.Options{})
172173
testutil.Ok(t, err)
173174
defer svr.Close()
174-
err = os.Setenv("GCS_EMULATOR_HOST", svr.Addr)
175+
err = os.Setenv("STORAGE_EMULATOR_HOST", svr.Addr)
175176
testutil.Ok(t, err)
176-
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "fakecred.json")
177+
177178
bkt, err := NewBucketWithConfig(context.Background(), log.NewNopLogger(), cfg, "test-bucket", rt)
178179
testutil.Ok(t, err)
179-
testutil.Assert(t, bkt.name == "test-bucket")
180180
_, err = bkt.Get(context.Background(), "test-bucket")
181181
testutil.NotOk(t, err)
182182
testutil.Assert(t, errors.Is(err, rt.Err), "Expected RoundTripper error, got: %v", err)

0 commit comments

Comments
 (0)