Enchantrix/pkg/crypt/crypt_internal_test.go
google-labs-jules[bot] e112ec363d feat: Add Good, Bad, and Ugly tests
This commit refactors the test suites for the `crypt` and `enchantrix` packages to follow the "Good, Bad, Ugly" testing methodology.

- `_Good` tests cover the ideal "happy path" scenarios.
- `_Bad` tests cover expected failure scenarios with well-formed but invalid inputs.
- `_Ugly` tests cover malicious or malformed inputs designed to cause crashes or panics.

This change improves test coverage and ensures that the codebase is more robust and resilient to unexpected inputs.
2025-11-13 21:27:38 +00:00

33 lines
781 B
Go

package crypt
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestEnsureRSA_Good tests that the RSA service is initialized correctly.
func TestEnsureRSA_Good(t *testing.T) {
s := &Service{}
s.ensureRSA()
assert.NotNil(t, s.rsa)
}
// TestEnsureRSA_Bad tests that calling ensureRSA multiple times does not change the RSA service.
func TestEnsureRSA_Bad(t *testing.T) {
s := &Service{}
s.ensureRSA()
rsa1 := s.rsa
s.ensureRSA()
rsa2 := s.rsa
assert.Same(t, rsa1, rsa2)
}
// TestEnsureRSA_Ugly tests that ensureRSA works correctly on a service with a pre-initialized RSA service.
func TestEnsureRSA_Ugly(t *testing.T) {
s := NewService() // NewService initializes the RSA service
rsa1 := s.rsa
s.ensureRSA()
rsa2 := s.rsa
assert.Same(t, rsa1, rsa2)
}