-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature api cli generic objects (#321)
* feat(api): recursive get objects * feat(cli): get and ls recursive * feat(cli): show relative path when doing recursive ls * fix(cli): order objects on get * docs(cli): recursive ls and get * feat(cli): get with filters and ls -r with filters * feat(api): support ** (also directy children) * feat(cli): add support for min and max depth in recursive ls/get * feat(api): add support for min and max depth in wildcards * fix(cli): be able to ls format without sort * fix(cli): man are txt files * fix(cli): lsdev * docs(cli): more docs to ls, lsobj and get * fix(cli,api): wildcards following linux standard * fix(cli): not error when layer is empty * fix(cli): relative path when ls -r is not path * feat(api): create generic objects * fix(cli): delete grep * refactor(cli): avoid not neccesary error verification * docs(cli): fix lint and typos * refactor(cli): remove duplicated code for template, posXYZ and size * refactor(cli): serialise vector * refactor(cli): create attributes * refactor(cli): apply template * feat(cli): verify that template category is the correct one * feat(cli): create generic object * feat(api): add templates to generic * feat(cli): add generics layers * feat(cli): create generic templates * docs(cli): create generic and generic template * fix(cli): build * Update wildcard_test.go * fix(api) strict use of transactions * fix(api) tests * fix(api) minor fixes * fix(api,cli) add shapes * fix(api) tests * fix(api,cli) tests --------- Co-authored-by: Franco Liberali <[email protected]>
- Loading branch information
1 parent
a138326
commit ae6733c
Showing
47 changed files
with
2,047 additions
and
979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package models_test | ||
|
||
import ( | ||
"p3/models" | ||
"p3/test/integration" | ||
"p3/test/unit" | ||
u "p3/utils" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateRackWithoutAttributesReturnsError(t *testing.T) { | ||
_, err := models.CreateEntity( | ||
u.RACK, | ||
map[string]any{ | ||
"category": "rack", | ||
"description": []any{"rack"}, | ||
"domain": integration.TestDBName, | ||
"name": "create-object-1", | ||
"tags": []any{}, | ||
}, | ||
integration.ManagerUserRoles, | ||
) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, u.ErrBadFormat, err.Type) | ||
assert.Equal(t, "JSON body doesn't validate with the expected JSON schema", err.Message) | ||
} | ||
|
||
func TestCreateObjectWithDuplicatedNameReturnsError(t *testing.T) { | ||
site := integration.RequireCreateSite("create-object-1") | ||
|
||
_, err := integration.CreateSite(site["name"].(string)) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, u.ErrDuplicate, err.Type) | ||
assert.Equal(t, "Error while creating site: Duplicates not allowed", err.Message) | ||
} | ||
|
||
func TestCreateCorridorWithSameNameAsRackReturnsError(t *testing.T) { | ||
rack := integration.RequireCreateRack("", "create-object-2") | ||
|
||
_, err := integration.CreateCorridor(rack["parentId"].(string), "create-object-2") | ||
assert.NotNil(t, err) | ||
assert.Equal(t, u.ErrBadFormat, err.Type) | ||
assert.Equal(t, "Object name must be unique among corridors, racks and generic objects", err.Message) | ||
} | ||
|
||
func TestCreateRackWithSameNameAsCorridorReturnsError(t *testing.T) { | ||
corridor := integration.RequireCreateCorridor("", "create-object-3") | ||
|
||
_, err := integration.CreateRack(corridor["parentId"].(string), "create-object-3") | ||
assert.NotNil(t, err) | ||
assert.Equal(t, u.ErrBadFormat, err.Type) | ||
assert.Equal(t, "Object name must be unique among corridors, racks and generic objects", err.Message) | ||
} | ||
|
||
func TestCreateGenericWithSameNameAsRackReturnsError(t *testing.T) { | ||
rack := integration.RequireCreateRack("", "create-object-4") | ||
|
||
_, err := integration.CreateGeneric(rack["parentId"].(string), "create-object-4") | ||
assert.NotNil(t, err) | ||
assert.Equal(t, u.ErrBadFormat, err.Type) | ||
assert.Equal(t, "Object name must be unique among corridors, racks and generic objects", err.Message) | ||
} | ||
|
||
func TestCreateGenericWithSameNameAsCorridorReturnsError(t *testing.T) { | ||
corridor := integration.RequireCreateCorridor("", "create-object-5") | ||
|
||
_, err := integration.CreateGeneric(corridor["parentId"].(string), "create-object-5") | ||
assert.NotNil(t, err) | ||
assert.Equal(t, u.ErrBadFormat, err.Type) | ||
assert.Equal(t, "Object name must be unique among corridors, racks and generic objects", err.Message) | ||
} | ||
|
||
func TestCreateGroupWithObjectThatNotExistsReturnsError(t *testing.T) { | ||
room := integration.RequireCreateRoom("", "create-object-6-room") | ||
|
||
_, err := integration.CreateGroup(room["id"].(string), "create-object-6", []string{"not-exists"}) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, u.ErrBadFormat, err.Type) | ||
assert.Equal(t, "Some object(s) could not be found. Please check and try again", err.Message) | ||
} | ||
|
||
func TestCreateGroupWithCorridorsRacksAndGenericWorks(t *testing.T) { | ||
room := integration.RequireCreateRoom("", "create-object-7-room") | ||
rack := integration.RequireCreateRack(room["id"].(string), "create-object-7-rack") | ||
corridor := integration.RequireCreateCorridor(room["id"].(string), "create-object-7-corridor") | ||
generic := integration.RequireCreateGeneric(room["id"].(string), "create-object-7-generic") | ||
|
||
group, err := integration.CreateGroup( | ||
room["id"].(string), | ||
"create-object-7", | ||
[]string{rack["name"].(string), corridor["name"].(string), generic["name"].(string)}, | ||
) | ||
assert.Nil(t, err) | ||
unit.HasAttribute(t, group, "content", "create-object-7-rack,create-object-7-corridor,create-object-7-generic") | ||
} | ||
|
||
func TestCreateGenericWithParentNotRoomReturnsError(t *testing.T) { | ||
rack := integration.RequireCreateRack("", "create-object-8-rack") | ||
|
||
_, err := integration.CreateGeneric(rack["id"].(string), "create-object-8-generic") | ||
assert.NotNil(t, err) | ||
assert.ErrorContains(t, err, "ParentID should correspond to Existing Room ID") | ||
} | ||
|
||
func TestCreateGenericWithParentRoomWorks(t *testing.T) { | ||
room := integration.RequireCreateRoom("", "create-object-9-room") | ||
|
||
_, err := integration.CreateGeneric(room["id"].(string), "create-object-9-generic") | ||
assert.Nil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.