mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 17:01:04 -06:00
c8df3e5995
Fixes #11052 It appears that historically nodes did not expect DotOpts to ever be nil. To avoid nil panics in general I'm in agreement with this behavior so this modifies dag to always pass in a non-nil DotOpts. Tests included.
40 lines
685 B
Go
40 lines
685 B
Go
package dag
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestGraphDot_opts(t *testing.T) {
|
|
var v testDotVertex
|
|
var g Graph
|
|
g.Add(&v)
|
|
|
|
opts := &DotOpts{MaxDepth: 42}
|
|
actual := g.Dot(opts)
|
|
if len(actual) == 0 {
|
|
t.Fatal("should not be empty")
|
|
}
|
|
|
|
if !v.DotNodeCalled {
|
|
t.Fatal("should call DotNode")
|
|
}
|
|
if !reflect.DeepEqual(v.DotNodeOpts, opts) {
|
|
t.Fatalf("bad; %#v", v.DotNodeOpts)
|
|
}
|
|
}
|
|
|
|
type testDotVertex struct {
|
|
DotNodeCalled bool
|
|
DotNodeTitle string
|
|
DotNodeOpts *DotOpts
|
|
DotNodeReturn *DotNode
|
|
}
|
|
|
|
func (v *testDotVertex) DotNode(title string, opts *DotOpts) *DotNode {
|
|
v.DotNodeCalled = true
|
|
v.DotNodeTitle = title
|
|
v.DotNodeOpts = opts
|
|
return v.DotNodeReturn
|
|
}
|