fix test files

This commit is contained in:
2026-01-27 10:45:15 +08:00
parent 8b589e5a55
commit bd0fdf89f3
10 changed files with 83 additions and 72 deletions
+8 -4
View File
@@ -42,12 +42,16 @@ func getRSAPublicKey() (*rsa.PublicKey, error) {
rsaPublicKeyOnce.Do(func() {
log.Print("Loading RSA public key from PEM certificate file")
// Read PEM file
// Read PEM file - use path relative to executable or try both common paths
pemData, err := os.ReadFile("rsa/ServerCertificate.pem")
if err != nil {
rsaPublicKeyError = fmt.Errorf("failed to read PEM file: %w", err)
log.Printf("Error reading PEM file: %v", rsaPublicKeyError)
return
// Try alternate path when running tests from subdirectory
pemData, err = os.ReadFile("../rsa/ServerCertificate.pem")
if err != nil {
rsaPublicKeyError = fmt.Errorf("failed to read PEM file: %w", err)
log.Printf("Error reading PEM file: %v", rsaPublicKeyError)
return
}
}
log.Print("PEM file successfully read")
+7
View File
@@ -19,6 +19,13 @@ import (
"github.com/golang-jwt/jwt/v5"
)
func TestMain(m *testing.M) {
os.Setenv("GO_ENV", "development")
code := m.Run()
os.Unsetenv("GO_ENV")
os.Exit(code)
}
// Test helper to generate RSA key pair and certificate
func generateTestRSACertificate(t *testing.T) (privateKey *rsa.PrivateKey, certPEM []byte) {
t.Helper()