Test that renderEdges panics on a node kind it does not handle

This commit is contained in:
2026-09-28 23:56:34 +02:00
committed by Lillem4n
parent 62ae658b4d
commit 446a3f98d6
+20
View File
@@ -2,6 +2,8 @@ package fejkdata
import ( import (
"encoding/json" "encoding/json"
"fmt"
"strings"
"testing" "testing"
) )
@@ -54,3 +56,21 @@ func quote(s string) string {
} }
return string(b) return string(b)
} }
type unhandledNode struct{}
func (*unhandledNode) isNode() {}
func TestRenderEdgesPanicsOnAnUnhandledNode(t *testing.T) {
for _, n := range []node{&folder{}, &nullItem{}} {
if es := renderEdges(n); len(es) != 0 {
t.Errorf("renderEdges(%T) = %v, want no edges", n, es)
}
}
defer func() {
if r := recover(); r == nil || !strings.Contains(fmt.Sprint(r), "*fejkdata.unhandledNode") {
t.Errorf("renderEdges(unhandledNode) recovered %v, want a panic naming the node kind", r)
}
}()
renderEdges(&unhandledNode{})
}