@@ -22,6 +22,9 @@ import (
2222 "strconv"
2323 "strings"
2424 "testing"
25+ "time"
26+
27+ "github.com/stretchr/testify/assert"
2528)
2629
2730func newGraph (t * testing.T ) * Graph {
@@ -509,6 +512,47 @@ func TestEvents(t *testing.T) {
509512 }
510513}
511514
515+ func TestNodeCopy (t * testing.T ) {
516+ n := & Node {
517+ graphElement : graphElement {
518+ ID : Identifier ("id" ),
519+ Host : "Host" ,
520+ Origin : "Origin" ,
521+ CreatedAt : Time (time .Unix (100 , 0 )),
522+ UpdatedAt : Time (time .Unix (200 , 0 )),
523+ DeletedAt : Time (time .Unix (300 , 0 )),
524+ Revision : 1 ,
525+ Metadata : Metadata {"foo" : "bar" },
526+ },
527+ }
528+
529+ cn := n .Copy ()
530+ assert .Equal (t , n , cn )
531+
532+ // Check that modifications in the copied node do not affect the origin node
533+ ok := cn .Metadata .SetField ("new" , "value" )
534+ assert .Truef (t , ok , "copied node set metadata" )
535+ assert .NotEqualf (t , n , cn , "Metadata" )
536+
537+ cn .Host = "modified"
538+ assert .NotEqualf (t , n , cn , "Host" )
539+
540+ cn .Origin = "modified"
541+ assert .NotEqualf (t , n , cn , "Origin" )
542+
543+ cn .Revision = 99
544+ assert .NotEqualf (t , n , cn , "Revision" )
545+
546+ cn .CreatedAt = Time (time .Unix (100 , 99 ))
547+ assert .NotEqualf (t , n , cn , "CreatedAt" )
548+
549+ cn .UpdatedAt = Time (time .Unix (200 , 99 ))
550+ assert .NotEqualf (t , n , cn , "UpdatedAt" )
551+
552+ cn .DeletedAt = Time (time .Unix (300 , 99 ))
553+ assert .NotEqualf (t , n , cn , "DeletedAt" )
554+ }
555+
512556type FakeRecursiveListener1 struct {
513557 DefaultGraphListener
514558 graph * Graph
0 commit comments