Skip to content

Commit

Permalink
fix(api) tests
Browse files Browse the repository at this point in the history
  • Loading branch information
helderbetiol committed Jun 13, 2024
1 parent 9192305 commit 5bf942a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions API/controllers/entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions CLI/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5bf942a

Please sign in to comment.