(t *testing.T)
| 1724 | } |
| 1725 | |
| 1726 | func TestUsageLimitFeatures(t *testing.T) { |
| 1727 | t.Parallel() |
| 1728 | |
| 1729 | // Ensures that usage limit features are ranked by issued at, not by |
| 1730 | // values. |
| 1731 | t.Run("IssuedAtRanking", func(t *testing.T) { |
| 1732 | t.Parallel() |
| 1733 | |
| 1734 | // Generate 2 real licenses both with managed agent limit |
| 1735 | // features. lic2 should trump lic1 even though it has a lower |
| 1736 | // limit, because it was issued later. |
| 1737 | lic1 := database.License{ |
| 1738 | ID: 1, |
| 1739 | UploadedAt: time.Now(), |
| 1740 | Exp: time.Now().Add(time.Hour), |
| 1741 | UUID: uuid.New(), |
| 1742 | JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ |
| 1743 | IssuedAt: time.Now().Add(-time.Minute * 2), |
| 1744 | NotBefore: dbtime.Now().Add(-time.Minute * 2), |
| 1745 | ExpiresAt: time.Now().Add(time.Hour * 2), |
| 1746 | Features: license.Features{ |
| 1747 | codersdk.FeatureManagedAgentLimit: 100, |
| 1748 | }, |
| 1749 | }), |
| 1750 | } |
| 1751 | lic2Iat := time.Now().Add(-time.Minute * 1) |
| 1752 | lic2Nbf := lic2Iat.Add(-time.Minute) |
| 1753 | lic2Exp := lic2Iat.Add(time.Hour) |
| 1754 | lic2 := database.License{ |
| 1755 | ID: 2, |
| 1756 | UploadedAt: time.Now(), |
| 1757 | Exp: lic2Exp, |
| 1758 | UUID: uuid.New(), |
| 1759 | JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ |
| 1760 | IssuedAt: lic2Iat, |
| 1761 | NotBefore: lic2Nbf, |
| 1762 | ExpiresAt: lic2Exp, |
| 1763 | Features: license.Features{ |
| 1764 | codersdk.FeatureManagedAgentLimit: 50, |
| 1765 | }, |
| 1766 | }), |
| 1767 | } |
| 1768 | |
| 1769 | const actualAgents = 10 |
| 1770 | arguments := license.FeatureArguments{ |
| 1771 | ActiveUserCount: 10, |
| 1772 | ReplicaCount: 0, |
| 1773 | ExternalAuthCount: 0, |
| 1774 | ManagedAgentCountFn: func(ctx context.Context, from time.Time, to time.Time) (int64, error) { |
| 1775 | return actualAgents, nil |
| 1776 | }, |
| 1777 | } |
| 1778 | |
| 1779 | // Load the licenses in both orders to ensure the correct |
| 1780 | // behavior is observed no matter the order. |
| 1781 | for _, order := range [][]database.License{ |
| 1782 | {lic1, lic2}, |
| 1783 | {lic2, lic1}, |
nothing calls this directly
no test coverage detected