Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions clients/bucket/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ func (c Client) Create(ctx context.Context, params *BucketsCreateParams) error {
reqBody.Description = &params.Description
}
// Only append a retention rule if the user wants to explicitly set
// a parameter on the rule.
// a parameter on the rule,
// or the shard group duration is set, to be able to set a retention of infinity
//
// This is for backwards-compatibility with older versions of the API,
// which didn't support setting shard-group durations and used an empty
// array of rules to represent infinite retention.
if rp > 0 || sgd > 0 {
rule := api.NewRetentionRuleWithDefaults()
if rp > 0 {
rule.SetEverySeconds(int64(rp.Round(time.Second) / time.Second))
}

rule.SetEverySeconds(int64(rp.Round(time.Second) / time.Second))

if sgd > 0 {
rule.SetShardGroupDurationSeconds(int64(sgd.Round(time.Second) / time.Second))
}
Expand Down
30 changes: 30 additions & 0 deletions clients/bucket/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,36 @@ func TestBucketsCreate(t *testing.T) {
}, nil)
},
},
{
name: "shard-group duration and infinite retention",
params: bucket.BucketsCreateParams{
OrgParams: clients.OrgParams{OrgID: "123"},
Name: "my-bucket",
Retention: "0",
ShardGroupDuration: "10s",
},
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
bucketsApi.EXPECT().PostBuckets(gomock.Any()).Return(api.ApiPostBucketsRequest{ApiService: bucketsApi})
bucketsApi.EXPECT().
PostBucketsExecute(tmock.MatchedBy(func(in api.ApiPostBucketsRequest) bool {
body := in.GetPostBucketRequest()
retentionRules := *body.RetentionRules
return assert.NotNil(t, body) &&
assert.Equal(t, "123", body.OrgID) &&
assert.Equal(t, "my-bucket", body.Name) &&
assert.Nil(t, body.Description) &&
assert.Len(t, *body.RetentionRules, 1) &&
assert.Equal(t, int64(0), retentionRules[0].EverySeconds) &&
assert.Equal(t, int64(10), *(retentionRules[0].ShardGroupDurationSeconds))
})).
Return(api.Bucket{
Id: api.PtrString("456"),
OrgID: api.PtrString("123"),
Name: "my-bucket",
RetentionRules: []api.RetentionRule{{EverySeconds: 0, ShardGroupDurationSeconds: api.PtrInt64(10)}},
}, nil)
},
},
{
name: "create bucket with explicit schema",
params: bucket.BucketsCreateParams{
Expand Down