Migrate remaining configuration documents to ConfigKit
This commit is contained in:
56
internal/config/document_configkit_test.go
Normal file
56
internal/config/document_configkit_test.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSingleSourceDocumentsRejectConfigKitDirectives(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
campaignPath := filepath.Join(dir, "campaign.yml")
|
||||
if err := os.WriteFile(campaignPath, []byte("configkit:\n imports: []\ncampaign_id: sample\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
load func() error
|
||||
}{
|
||||
{name: "campaign", load: func() error { _, err := LoadCampaign(campaignPath); return err }},
|
||||
{name: "session", load: func() error {
|
||||
_, err := LoadSessionBytesWithOptions("session.yml", []byte("configkit:\n imports: []\nsession_id: sample\n"), SessionLoadOptions{})
|
||||
return err
|
||||
}},
|
||||
{name: "party", load: func() error {
|
||||
_, err := ParseParty([]byte("configkit:\n imports: []\nschema_version: narratio.party.v1\ncharacters: {}\n"))
|
||||
return err
|
||||
}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if err := test.load(); err == nil || !strings.Contains(err.Error(), "import.disabled") {
|
||||
t.Fatalf("load error = %v, want disabled-import diagnostic", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInspectedDocumentsEnforceConfigKitSizeLimit(t *testing.T) {
|
||||
tooLarge := bytes.Repeat([]byte{' '}, int(maxConfigDocumentBytes)+1)
|
||||
if _, err := LoadSessionBytesWithOptions("session.yml", tooLarge, SessionLoadOptions{}); err == nil || !strings.Contains(err.Error(), "exceeds") {
|
||||
t.Fatalf("oversized session error = %v", err)
|
||||
}
|
||||
if _, err := ParseParty(tooLarge); err == nil || !strings.Contains(err.Error(), "exceeds") {
|
||||
t.Fatalf("oversized party error = %v", err)
|
||||
}
|
||||
|
||||
path := filepath.Join(t.TempDir(), "session.yml")
|
||||
if err := os.WriteFile(path, tooLarge, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := LoadSession(path); err == nil || !strings.Contains(err.Error(), "limit") {
|
||||
t.Fatalf("oversized local session error = %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user