@@ -2,8 +2,10 @@ package lore
22
33import (
44 "context"
5+ "errors"
56 "os"
67 "path/filepath"
8+ "strings"
79 "testing"
810)
911
@@ -146,6 +148,38 @@ func TestCatalog_KindInference(t *testing.T) {
146148 }
147149}
148150
151+ func TestCatalog_InvalidKindOverride (t * testing.T ) {
152+ ctx := context .Background ()
153+ db := openTestDB (t , "catalog-bad-kind" )
154+
155+ dir := t .TempDir ()
156+ if err := os .WriteFile (filepath .Join (dir , "note.md" ), []byte ("# Note\n \n Some content here." ), 0o600 ); err != nil {
157+ t .Fatalf ("write note.md: %v" , err )
158+ }
159+
160+ _ , err := Catalog (ctx , db , & CatalogParams {
161+ Dir : dir ,
162+ ProjectID : "catalog-bad-kind" ,
163+ Kind : Kind ("not-a-real-kind" ),
164+ })
165+ if ! errors .Is (err , ErrInvalidKind ) {
166+ t .Fatalf ("Catalog error = %v; want ErrInvalidKind" , err )
167+ }
168+ if ! strings .Contains (err .Error (), "valid: idea, research, decision, observation, principle" ) {
169+ t .Fatalf ("Catalog error = %q; want valid kind list" , err .Error ())
170+ }
171+
172+ var count int
173+ if err := db .QueryRowContext (ctx ,
174+ `SELECT COUNT(*) FROM entries WHERE project_id = 'catalog-bad-kind'` ,
175+ ).Scan (& count ); err != nil {
176+ t .Fatalf ("count entries: %v" , err )
177+ }
178+ if count != 0 {
179+ t .Errorf ("entries in DB = %d; want 0" , count )
180+ }
181+ }
182+
149183func TestCatalog_SkipsNonMD (t * testing.T ) {
150184 ctx := context .Background ()
151185 db := openTestDB (t , "catalog-ext" )
0 commit comments