Merge pull request #1065 from gargdeepak/fix/cluster/pinupdate

Fixes #996 pin expiry is updated if set in options
This commit is contained in:
Hector Sanjuan 2020-04-16 10:55:18 +02:00 committed by GitHub
commit a6d8e00d20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -1509,7 +1509,9 @@ func (c *Cluster) PinUpdate(ctx context.Context, from cid.Cid, to cid.Cid, opts
if opts.Name != "" {
existing.Name = opts.Name
}
if !opts.ExpireAt.IsZero() && opts.ExpireAt.After(time.Now()) {
existing.ExpireAt = opts.ExpireAt
}
return existing, c.consensus.LogPin(ctx, existing)
}

View File

@ -719,11 +719,12 @@ func TestClustersPinUpdate(t *testing.T) {
}
pinDelay()
expiry := time.Now().AddDate(1, 0, 0)
opts2 := api.PinOptions{
UserAllocations: []peer.ID{clusters[0].host.ID()}, // should not be used
PinUpdate: h,
Name: "new name",
ExpireAt: expiry,
}
_, err = clusters[0].Pin(ctx, h2, opts2) // should call PinUpdate
@ -746,6 +747,11 @@ func TestClustersPinUpdate(t *testing.T) {
if pinget.MaxDepth != -1 {
t.Error("updated pin should be recursive like pin1")
}
expiry = expiry.Round(2 * time.Second)
if pinget.ExpireAt != expiry {
t.Errorf("Expiry didn't match. Expected: %s. Got: %s",
expiry.String(), pinget.ExpireAt.String())
}
if pinget.Name != "new name" {
t.Error("name should be kept")