Commit bd15825
Antonio Mika
·
2026-10-10 23:26:22 -0400 EDT
parent c2b9386
test: make expiry and pgs url tests independent of local timezone and env
2 files changed,
+8,
-4
+6,
-4
| ... | ... | @@ -13,7 +13,9 @@ import ( | |
| 13 | 13 | func TestFileMetaKeepsSettings(t *testing.T) { | |
| 14 | 14 | soon := time.Now().Add(time.Hour) | |
| 15 | 15 | past := time.Now().Add(-time.Hour) | |
| 16 | - | day := 24 * time.Hour | |
| 16 | + | // Pastes expire after calendar days, which a daylight saving change | |
| 17 | + | // makes an hour longer or shorter. | |
| 18 | + | defaultExpiry := time.Until(time.Now().AddDate(0, 0, DEFAULT_EXPIRES_AT)).Round(time.Minute) | |
| 17 | 19 | tests := []struct { | |
| 18 | 20 | name string | |
| 19 | 21 | cmd []string |
| ... | ... | @@ -22,12 +24,12 @@ func TestFileMetaKeepsSettings(t *testing.T) { | |
| 22 | 24 | // expires is how long until the paste expires, or 0 for never. | |
| 23 | 25 | expires time.Duration | |
| 24 | 26 | }{ | |
| 25 | - | {name: "new", expires: 90 * day}, | |
| 27 | + | {name: "new", expires: defaultExpiry}, | |
| 26 | 28 | {name: "new with arguments", cmd: []string{"hidden=true", "expires=2h"}, hidden: true, expires: 2 * time.Hour}, | |
| 27 | 29 | {name: "existing", cur: &db.Post{Hidden: true, ExpiresAt: &soon}, hidden: true, expires: time.Hour}, | |
| 28 | 30 | {name: "existing without expiry", cur: &db.Post{Hidden: true}, hidden: true}, | |
| 29 | - | {name: "existing past its expiry", cur: &db.Post{Hidden: true, ExpiresAt: &past}, hidden: true, expires: 90 * day}, | |
| 30 | - | {name: "existing with arguments", cmd: []string{"hidden=false", "expires=true"}, cur: &db.Post{Hidden: true}, expires: 90 * day}, | |
| 31 | + | {name: "existing past its expiry", cur: &db.Post{Hidden: true, ExpiresAt: &past}, hidden: true, expires: defaultExpiry}, | |
| 32 | + | {name: "existing with arguments", cmd: []string{"hidden=false", "expires=true"}, cur: &db.Post{Hidden: true}, expires: defaultExpiry}, | |
| 31 | 33 | {name: "existing made permanent", cmd: []string{"expires=false"}, cur: &db.Post{ExpiresAt: &soon}}, | |
| 32 | 34 | } | |
| 33 | 35 | for _, tt := range tests { |
+2,
-0
| ... | ... | @@ -58,6 +58,8 @@ func newRsyncEnv(t *testing.T, st storage.StorageServe) *rsyncEnv { | |
| 58 | 58 | ||
| 59 | 59 | t.Setenv("PGS_SSH_PORT", "0") | |
| 60 | 60 | cfg := NewPgsConfig(logger, dbpool, st, discardPubsub{}) | |
| 61 | + | cfg.Domain = "pgs.sh" | |
| 62 | + | cfg.WebProtocol = "https" | |
| 61 | 63 | done := make(chan error) | |
| 62 | 64 | readyCh := make(chan *pssh.SSHServer) | |
| 63 | 65 | prometheus.DefaultRegisterer = prometheus.NewRegistry() |