initial public relay build repo
ci / build (push) Successful in 2m3s
ci / image (push) Successful in 1m4s

This commit is contained in:
2026-07-24 13:11:06 -04:00
commit 294616642f
24 changed files with 2957 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
package main
import (
"os"
"path/filepath"
"testing"
"fiatjaf.com/nostr"
)
func TestDevKeyPersistsAcrossCalls(t *testing.T) {
t.Setenv("RELAY_SECRET_KEY", "")
t.Setenv("RELAY_ENV", "")
dir := t.TempDir()
first := loadOrGenerateKey(dir)
// The key file should now exist and a second call must return the same key.
if _, err := os.Stat(filepath.Join(dir, "relay.key")); err != nil {
t.Fatalf("dev key not persisted: %v", err)
}
second := loadOrGenerateKey(dir)
if first != second {
t.Fatal("dev identity should be stable across restarts")
}
}
func TestExplicitKeyIsUsed(t *testing.T) {
sk := nostr.Generate()
t.Setenv("RELAY_SECRET_KEY", sk.Hex())
t.Setenv("RELAY_ENV", "production") // explicit key wins even in production
got := loadOrGenerateKey(t.TempDir())
if got != sk {
t.Fatal("explicit RELAY_SECRET_KEY should be used verbatim")
}
}
// Note: the production-without-key path calls log.Fatal (os.Exit), which can't
// be exercised in-process without a subprocess harness; its behavior is simple
// and covered by manual verification + the isProduction() guard below.
func TestIsProduction(t *testing.T) {
t.Setenv("RELAY_ENV", "production")
if !isProduction() {
t.Fatal("RELAY_ENV=production should be detected")
}
t.Setenv("RELAY_ENV", "")
if isProduction() {
t.Fatal("unset RELAY_ENV should not be production")
}
}