52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package usage
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestGenerateEnabledDefaultsNilToTrue(t *testing.T) {
|
|
if !GenerateEnabled(nil) {
|
|
t.Fatalf("GenerateEnabled(nil) = false, want true")
|
|
}
|
|
}
|
|
|
|
func TestGenerateEnabledHonorsExplicitFalse(t *testing.T) {
|
|
if GenerateEnabled(GenerateFlag(false)) {
|
|
t.Fatalf("GenerateEnabled(false) = true, want false")
|
|
}
|
|
}
|
|
|
|
func TestGenerateEnabledHonorsExplicitTrue(t *testing.T) {
|
|
if !GenerateEnabled(GenerateFlag(true)) {
|
|
t.Fatalf("GenerateEnabled(true) = false, want true")
|
|
}
|
|
}
|
|
|
|
func TestGenerateFromContextDefaultsMissingToTrue(t *testing.T) {
|
|
if !GenerateFromContext(context.Background()) {
|
|
t.Fatalf("GenerateFromContext(background) = false, want true")
|
|
}
|
|
}
|
|
|
|
func TestGenerateFromContextHonorsExplicitFalse(t *testing.T) {
|
|
ctx := WithGenerate(context.Background(), false)
|
|
if GenerateFromContext(ctx) {
|
|
t.Fatalf("GenerateFromContext(false) = true, want false")
|
|
}
|
|
}
|
|
|
|
func TestRecordOmittedGenerateIsEnabled(t *testing.T) {
|
|
// Existing callers construct Record without setting Generate.
|
|
// Omission must remain distinguishable from explicit false and default to true.
|
|
record := Record{
|
|
Provider: "openai",
|
|
Model: "gpt-5.4",
|
|
}
|
|
if record.Generate != nil {
|
|
t.Fatalf("Record.Generate = %v, want nil for omitted field", record.Generate)
|
|
}
|
|
if !GenerateEnabled(record.Generate) {
|
|
t.Fatalf("GenerateEnabled(omitted) = false, want true")
|
|
}
|
|
}
|