storj/satellite/payments/coupons_test.go
crawter 0b898c48a4 satellite/payments: coupons expiration logic fix
Change-Id: Ic8cc4e117957a75a3eb057075204a5b592e62ff4
2020-01-30 00:22:38 +02:00

38 lines
712 B
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package payments
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestCouponIsExpired(t *testing.T) {
duration := 2
now := time.Now().UTC()
testCases := [...]struct {
created time.Time
expected bool
}{
{now.AddDate(0, -duration-1, 0), true},
{now.AddDate(0, -duration-2, 0), true},
{now.AddDate(0, -duration-3, 0), true},
{now.AddDate(0, -1, 0), false},
{now.AddDate(0, 0, 0), false},
{now.AddDate(0, 1, 0), false},
}
for _, tc := range testCases {
coupon := Coupon{
Duration: duration,
Created: tc.created,
}
require.Equal(t, coupon.IsExpired(), tc.expected)
}
}