Skip to content

Commit 2cb8f8c

Browse files
test the assertion
1 parent 87593d5 commit 2cb8f8c

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

world/location_test.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package world
22

33
import (
44
"errors"
5-
"github.com/hashicorp/go-uuid"
65
"log"
76
"math/rand/v2"
87
"testing"
8+
9+
"github.com/hashicorp/go-uuid"
910
)
1011

1112
func CreateRandomTestLocation() (*Location, error, string, string, float64, float64) {
@@ -28,6 +29,40 @@ func CreateRandomTestLocation() (*Location, error, string, string, float64, floa
2829
func TestLocation(t *testing.T) {
2930
t.Parallel()
3031

32+
t.Run("SetNode", func(t *testing.T) {
33+
t.Parallel()
34+
t.Run("should set the node of the location", func(t *testing.T) {
35+
t.Parallel()
36+
loc, err, _, _, _, _ := CreateRandomTestLocation()
37+
if err != nil {
38+
t.Fatalf("unexpected error: %v", err)
39+
}
40+
41+
if loc.Node != nil {
42+
t.Fatalf("expected node to be nil")
43+
}
44+
node := &TreeNode{}
45+
loc.SetNode(node)
46+
47+
if loc.Node != node {
48+
t.Fatalf("expected node to be set")
49+
}
50+
})
51+
t.Run("should panic if the node is nil", func(t *testing.T) {
52+
t.Parallel()
53+
defer func() {
54+
if r := recover(); r == nil {
55+
t.Fatalf("expected panic but did not get one")
56+
}
57+
}()
58+
loc, err, _, _, _, _ := CreateRandomTestLocation()
59+
if err != nil {
60+
t.Fatalf("unexpected error: %v", err)
61+
}
62+
63+
loc.SetNode(nil)
64+
})
65+
})
3166
t.Run("NewLocation", func(t *testing.T) {
3267
t.Parallel()
3368
t.Run("should return an error if the namespace id is missing", func(t *testing.T) {

0 commit comments

Comments
 (0)