Skip to content

Commit c9d10c0

Browse files
committed
fix: properties print empty json when object not exist
1 parent 665417c commit c9d10c0

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

gcs/client/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ func (client *GCSBlobstore) getReader(gcs *storage.Client, src string) (*storage
137137
const retryAttempts = 3
138138

139139
func (client *GCSBlobstore) Put(sourceFilePath string, dest string) error {
140-
141140
src, err := os.Open(sourceFilePath)
142141
if err != nil {
143142
return err
@@ -319,6 +318,10 @@ func (client *GCSBlobstore) Properties(dest string) error {
319318
attr, err := oh.Attrs(context.Background())
320319

321320
if err != nil {
321+
if errors.Is(err, storage.ErrObjectNotExist) {
322+
fmt.Println(`{}`)
323+
return nil
324+
}
322325
return fmt.Errorf("getting attributes: %w", err)
323326
}
324327

gcs/integration/assertions.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ func AssertLifecycleWorks(gcsCLIPath string, ctx AssertContext) {
4747
Expect(session.ExitCode()).To(BeZero())
4848
Expect(session.Err.Contents()).To(MatchRegexp("File '.*' exists in bucket '.*'"))
4949

50-
session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, storageType, "properties", ctx.GCSFileName)
51-
Expect(err).ToNot(HaveOccurred())
52-
Expect(session.ExitCode()).To(BeZero())
53-
output := string(session.Out.Contents())
54-
Expect(output).To(MatchRegexp(`"etag":\s*".+?"`))
55-
Expect(output).To(MatchRegexp(`"last_modified":\s*".+?"`))
56-
Expect(output).To(MatchRegexp(`"content_length":\s*\d+`))
57-
5850
tmpLocalFileName := "gcscli-download"
5951
defer os.Remove(tmpLocalFileName) //nolint:errcheck
6052

@@ -206,3 +198,28 @@ func AssertListMultipleWithPrefixLifecycle(gcsCLIPath string, ctx AssertContext)
206198
Expect(err).ToNot(HaveOccurred())
207199
Expect(session.ExitCode()).To(BeZero())
208200
}
201+
202+
func AssertPropertiesLifecycle(gcsCLIPath string, ctx AssertContext) {
203+
storageType := "gcs"
204+
session, err := RunGCSCLI(gcsCLIPath, ctx.ConfigPath, storageType, "put", ctx.ContentFile, ctx.GCSFileName)
205+
Expect(err).ToNot(HaveOccurred())
206+
Expect(session.ExitCode()).To(BeZero())
207+
208+
session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, storageType, "properties", ctx.GCSFileName)
209+
Expect(err).ToNot(HaveOccurred())
210+
Expect(session.ExitCode()).To(BeZero())
211+
output := string(session.Out.Contents())
212+
Expect(output).To(MatchRegexp(`"etag":\s*".+?"`))
213+
Expect(output).To(MatchRegexp(`"last_modified":\s*".+?"`))
214+
Expect(output).To(MatchRegexp(`"content_length":\s*\d+`))
215+
216+
session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, storageType, "delete", ctx.GCSFileName)
217+
Expect(err).ToNot(HaveOccurred())
218+
Expect(session.ExitCode()).To(BeZero())
219+
220+
session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, storageType, "properties", ctx.GCSFileName)
221+
Expect(err).ToNot(HaveOccurred())
222+
Expect(session.ExitCode()).To(BeZero())
223+
Expect(string(session.Out.Contents())).To(MatchRegexp("{}"))
224+
225+
}

gcs/integration/gcs_general_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ var _ = Describe("Integration", func() {
142142

143143
}, configurations)
144144

145+
DescribeTable("properties should print json", func(config *config.GCSCli) {
146+
env.AddConfig(config)
147+
AssertPropertiesLifecycle(gcsCLIPath, env)
148+
}, configurations)
149+
145150
Context("when bucket is not exist", func() {
146151
DescribeTable("ensure storage exist will create a new bucket", func(cfg *config.GCSCli) {
147152
// create new a newCfg instead of modifying shared cfg accross all tests

0 commit comments

Comments
 (0)