Skip to content
Snippets Groups Projects
Commit c2e95d13 authored by ko_oler's avatar ko_oler
Browse files

добавлен SystemID

parent fdf88caf
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,10 @@ func TestID_MarshalUnmarshalBSON(t *testing.T) {
name: "FieldID",
id: &ID{Descriptor: &FieldID{FieldName: "1", ItemID: ItemID{ItemID: "1", CollectionID: CollectionID{CollectionID: "1", EnvironmentID: EnvironmentID{EnvironmentID: "1", SpaceID: SpaceID{SpaceID: "1"}}}}}},
},
{
name: "SystemID",
id: &ID{Descriptor: &SystemID{}},
},
}
type test struct {
Text string
......
......@@ -75,6 +75,10 @@ func Parse(s string) (*ID, error) {
return &ID{Descriptor: id}, nil
}
if id, _ := parseSystemID(parts); id != nil {
return &ID{Descriptor: id}, nil
}
return nil, ErrInvalidID
}
......@@ -125,6 +129,8 @@ func FromMap(m map[string]any) (*ID, error) {
v.Descriptor = new(RevisionID)
case Field:
v.Descriptor = new(FieldID)
case System:
v.Descriptor = new(SystemID)
default:
return nil, errors.New("unknown type")
}
......
......@@ -128,6 +128,11 @@ func Test_ParseID(t *testing.T) {
FieldName: "<field_name>",
}},
},
{
name: "SystemID",
id: "/system",
result: &ID{Descriptor: &SystemID{}},
},
{
name: "With error #1: no backslash in the beginning of id",
id: "spaces/<space_id>",
......@@ -278,8 +283,12 @@ func Test_Map(t *testing.T) {
ItemID: "<item_id>",
},
FieldName: "<field_name>",
},
}},
},
{
name: "SystemID",
id: &ID{Descriptor: &SystemID{}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
......
......@@ -61,6 +61,10 @@ func TestID_MarshalUnmarshalJSON(t *testing.T) {
name: "FieldID",
id: &ID{Descriptor: &FieldID{FieldName: "1", ItemID: ItemID{ItemID: "1", CollectionID: CollectionID{CollectionID: "1", EnvironmentID: EnvironmentID{EnvironmentID: "1", SpaceID: SpaceID{SpaceID: "1"}}}}}},
},
{
name: "SystemID",
id: &ID{Descriptor: &SystemID{}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
......
package id
const (
System = "system"
)
type SystemID struct{}
func (t *SystemID) Type() string { return Space }
func (t *SystemID) String() string {
return "/" + System
}
func (t *SystemID) ToMap() map[string]any {
return map[string]any{"type": System}
}
func (t *SystemID) FromMap(m map[string]any) error {
return nil
}
func (t *SystemID) Validate() error {
return nil
}
func parseSystemID(parts []string) (*SystemID, error) {
var id SystemID
if len(parts) != 1 || parts[0] != System {
return nil, ErrInvalidID
}
return &id, nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment