Merge pull request #1065 from gargdeepak/fix/cluster/pinupdate
Fixes #996 pin expiry is updated if set in options
This commit is contained in:
commit
a6d8e00d20
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user