diff --git a/API/controllers/entity_test.go b/API/controllers/entity_test.go index 97144972b..8c68ec1dd 100644 --- a/API/controllers/entity_test.go +++ b/API/controllers/entity_test.go @@ -434,9 +434,9 @@ func TestLinkUnlinkRoomss(t *testing.T) { integration.CreateTestPhysicalEntity(t, utils.ROOM, roomName, parentId, true) unlinkEndpoint := test_utils.GetEndpoint("entityUnlink", "rooms", parentId+"."+roomName) - linkEndpoint := test_utils.GetEndpoint("entityLink", "stray-objects", "StrayRoom") + linkEndpoint := test_utils.GetEndpoint("entityLink", "stray_objects", "StrayRoom") roomEndpoint := test_utils.GetEndpoint("entityInstance", "rooms", parentId+"."+roomName) - strayObjectEndpoint := test_utils.GetEndpoint("entityInstance", "stray-objects", strayName) + strayObjectEndpoint := test_utils.GetEndpoint("entityInstance", "stray_objects", strayName) tests := []struct { name string isUnlink bool diff --git a/CLI/ast.go b/CLI/ast.go index 705fcf004..fb8731365 100644 --- a/CLI/ast.go +++ b/CLI/ast.go @@ -710,27 +710,28 @@ func updateVirtualLink(path string, attr string, value string) (map[string]any, return nil, fmt.Errorf("only virtual objects can have vlinks") } - vlinks, e := obj["attributes"].(map[string]any)["vlinks"].([]any) + vlinks, hasVlinks := obj["attributes"].(map[string]any)["vlinks"].([]any) if attr == "vlinks+" { - if !e { + if !hasVlinks { vlinks = []any{value} } else { vlinks = append(vlinks, value) } } else if attr == "vlinks-" { - if !e { + if !hasVlinks { return nil, fmt.Errorf("no vlinks defined for this object") - } - found := false - for i, vlink := range vlinks { - if vlink == value { - vlinks = append(vlinks[:i], vlinks[i+1:]...) - found = true - break + } else { + found := false + for i, vlink := range vlinks { + if vlink == value { + vlinks = append(vlinks[:i], vlinks[i+1:]...) + found = true + break + } + } + if !found { + return nil, fmt.Errorf("vlink to remove not found") } - } - if !found { - return nil, fmt.Errorf("vlink to remove not found") } } else { return nil, fmt.Errorf("invalid vlink update command")