Remove unused second part of the expiry counter
This commit is contained in:
@@ -169,10 +169,16 @@ func describeExpiry(t *time.Time, now time.Time) string {
|
||||
if t == nil {
|
||||
return "never"
|
||||
}
|
||||
at := t.UTC().Format("2006-01-02 15:04 MST")
|
||||
d := t.Sub(now).Round(time.Minute)
|
||||
if d < 0 {
|
||||
switch {
|
||||
case d < 0:
|
||||
return "expired"
|
||||
case d == 0:
|
||||
// Rounded away to nothing, and a zero duration is how this program
|
||||
// spells "unlimited": saying "in never" of a file about to go would
|
||||
// be exactly backwards.
|
||||
return at + " (in under a minute)"
|
||||
}
|
||||
return fmt.Sprintf("%s (in %s)", t.UTC().Format("2006-01-02 15:04 MST"),
|
||||
config.FormatDuration(d))
|
||||
return fmt.Sprintf("%s (in %s)", at, config.FormatDuration(d))
|
||||
}
|
||||
|
||||
@@ -1686,6 +1686,32 @@ func TestCustomNameFieldIsAlwaysUsable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The share page's expiry line is rounded to the minute, so it must not offer
|
||||
// a seconds tail it is not counting - nor, when the remainder rounds away to
|
||||
// nothing, claim the file is kept forever.
|
||||
func TestDescribeExpiryReadsAsWritten(t *testing.T) {
|
||||
at := func(d time.Duration) *time.Time {
|
||||
when := clock.Add(d)
|
||||
return &when
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
in *time.Time
|
||||
want string
|
||||
}{
|
||||
{"no deadline", nil, "never"},
|
||||
{"already gone", at(-time.Hour), "expired"},
|
||||
{"about to go", at(20 * time.Second), "(in under a minute)"},
|
||||
{"a minute off", at(time.Minute), "(in 1m)"},
|
||||
{"an hour and a half", at(90 * time.Minute), "(in 1h30m)"},
|
||||
{"three days", at(72 * time.Hour), "(in 3d)"},
|
||||
} {
|
||||
if got := describeExpiry(c.in, clock); !strings.Contains(got, c.want) {
|
||||
t.Errorf("%s: describeExpiry = %q, want it to contain %q", c.name, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A chosen passphrase has to work everywhere a generated token does: at the
|
||||
// login form, on an upload, and as a session.
|
||||
func TestChosenPassphraseWorksEndToEnd(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user