Skip to content

Commit 0bbe065

Browse files
authored
storage: Implement Fetcher (#19)
1 parent 1434e16 commit 0bbe065

File tree

6 files changed

+111
-6
lines changed

6 files changed

+111
-6
lines changed

generated.go

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.14
55
require (
66
bou.ke/monkey v1.0.2
77
github.com/aos-dev/go-integration-test/v2 v2.0.0-20201030072349-1418884fad78
8-
github.com/aos-dev/go-storage/v2 v2.0.0
8+
github.com/aos-dev/go-storage/v2 v2.0.1-0.20201203030158-b94397533b85
99
github.com/golang/mock v1.4.4
1010
github.com/google/uuid v1.1.2
1111
github.com/pengsrc/go-shared v0.2.1-0.20190131101655-1999055a4a14

go.sum

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki
99
github.com/aos-dev/go-integration-test/v2 v2.0.0-20201030072349-1418884fad78 h1:s/rzb/Zsilm/DOUjlgHNwBo9fByRsTGNCEh/T/uhI0c=
1010
github.com/aos-dev/go-integration-test/v2 v2.0.0-20201030072349-1418884fad78/go.mod h1:NfmZvOzPY/WaTXz7t7+/LaBecD/rvZWZKaQWR5oTQBg=
1111
github.com/aos-dev/go-storage/v2 v2.0.0-20201030030412-57f6d503c7c7/go.mod h1:eHpnrdrHP8mMoT1XdPcd7WRYtJKAYIcHmd2MhMO6l9E=
12-
github.com/aos-dev/go-storage/v2 v2.0.0 h1:7o2f1hz8vWSTAV1dH1l/qo8e75wzeP1ZiRPr3TP5DD0=
13-
github.com/aos-dev/go-storage/v2 v2.0.0/go.mod h1:a9oqOqLBsKkgep91ZF1bicbpAodOWtbPs3sAtaScbk8=
12+
github.com/aos-dev/go-storage/v2 v2.0.1-0.20201203030158-b94397533b85 h1:TmhNmt5NbanmhRXO47mg/QAqE7JHfiEx4n2ar0TCMKA=
13+
github.com/aos-dev/go-storage/v2 v2.0.1-0.20201203030158-b94397533b85/go.mod h1:BkdSR42JZFFjKJ+vq1UhjFODd0FPng9nMVR24IxKONI=
14+
github.com/aos-dev/specs/go v0.0.0-20201202111357-b50ee4ea7df4 h1:QHZ2ZCNLMlse6MoGyY/M+jVVJhoAq7Y0wjHQ5tH38OQ=
15+
github.com/aos-dev/specs/go v0.0.0-20201202111357-b50ee4ea7df4/go.mod h1:bsR49kgar1eScqMrZh4GvmZbeY2o4UtcDbC0jFtuJ0s=
1416
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
1517
github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0=
1618
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
@@ -30,9 +32,10 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
3032
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
3133
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
3234
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
35+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
3336
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
34-
github.com/hashicorp/hcl/v2 v2.7.0 h1:IU8qz5UzZ1po3M1D9/Kq6S5zbDGVfI9bnzmC1ogKKmI=
35-
github.com/hashicorp/hcl/v2 v2.7.0/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
37+
github.com/hashicorp/hcl/v2 v2.7.1 h1:eZWfKEO93WyE4OnZSD5LVy70YHDV/mmQ49gpKDLpDVM=
38+
github.com/hashicorp/hcl/v2 v2.7.1/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
3639
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
3740
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
3841
github.com/kevinburke/go-bindata v3.22.0+incompatible h1:/JmqEhIWQ7GRScV0WjX/0tqBrC5D21ALg0H0U/KZ/ts=

service.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace "service" {
2121
}
2222
}
2323
namespace "storage" {
24-
implement = ["copier", "dir_lister", "index_segmenter", "mover", "prefix_lister", "prefix_segments_lister", "reacher", "segmenter", "statistician"]
24+
implement = ["copier", "dir_lister", "fetcher", "index_segmenter", "mover", "prefix_lister", "prefix_segments_lister", "reacher", "segmenter", "statistician"]
2525

2626
new {
2727
required = ["name"]

storage.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,10 @@ func (s *Storage) statistical(ctx context.Context, opt *pairStorageStatistical)
398398
}
399399
return statistic, nil
400400
}
401+
402+
func (s *Storage) fetch(ctx context.Context, path string, url string, opt *pairStorageFetch) (err error) {
403+
_, err = s.bucket.PutObjectWithContext(ctx, path, &service.PutObjectInput{
404+
XQSFetchSource: service.String(url),
405+
})
406+
return err
407+
}

storager_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,3 +727,44 @@ func TestStorage_formatError(t *testing.T) {
727727
assert.Equal(t, tt.targetEq, errors.Is(err, tt.targetErr), tt.name)
728728
}
729729
}
730+
731+
func TestStorage_Fetch(t *testing.T) {
732+
ctrl := gomock.NewController(t)
733+
defer ctrl.Finish()
734+
735+
mockBucket := NewMockBucket(ctrl)
736+
737+
{
738+
client := Storage{
739+
bucket: mockBucket,
740+
}
741+
742+
name := uuid.New().String()
743+
url := uuid.New().String()
744+
745+
mockBucket.EXPECT().PutObjectWithContext(gomock.Eq(context.Background()), gomock.Any(), gomock.Any()).
746+
DoAndReturn(func(ctx context.Context, objectKey string, input *service.PutObjectInput) (*service.PutObjectOutput, error) {
747+
assert.Equal(t, name, objectKey)
748+
assert.Equal(t, *input.XQSFetchSource, url)
749+
return &service.PutObjectOutput{}, nil
750+
})
751+
err := client.Fetch(name, url)
752+
assert.NoError(t, err)
753+
}
754+
755+
{
756+
client := Storage{
757+
bucket: mockBucket,
758+
}
759+
760+
name := uuid.New().String()
761+
url := uuid.New().String()
762+
763+
mockBucket.EXPECT().PutObjectWithContext(gomock.Eq(context.Background()), gomock.Any(), gomock.Any()).
764+
DoAndReturn(func(ctx context.Context, objectKey string, input *service.PutObjectInput) (*service.PutObjectOutput, error) {
765+
return nil, &qerror.QingStorError{}
766+
})
767+
err := client.Fetch(name, url)
768+
assert.Error(t, err)
769+
}
770+
}

0 commit comments

Comments
 (0)