Files
galaxy-game/authsession/internal/testkit/code_generator.go
T
2026-04-08 16:23:07 +02:00

36 lines
867 B
Go

package testkit
import (
"errors"
"strings"
"galaxy/authsession/internal/ports"
)
// FixedCodeGenerator is a deterministic CodeGenerator double that always
// returns the same code or error.
type FixedCodeGenerator struct {
// Code stores the fixed code returned by Generate when Err is nil.
Code string
// Err is returned directly from Generate when set.
Err error
}
// Generate returns the configured fixed code.
func (g FixedCodeGenerator) Generate() (string, error) {
if g.Err != nil {
return "", g.Err
}
switch {
case strings.TrimSpace(g.Code) == "":
return "", errors.New("fixed code generator code must not be empty")
case strings.TrimSpace(g.Code) != g.Code:
return "", errors.New("fixed code generator code must not contain surrounding whitespace")
default:
return g.Code, nil
}
}
var _ ports.CodeGenerator = FixedCodeGenerator{}