Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
6e4c58c3
Commit
6e4c58c3
authored
1 year ago
by
ko_oler
Browse files
Options
Downloads
Patches
Plain Diff
правки по ПР
parent
188bef62
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
id/id_test.go
+43
-7
43 additions, 7 deletions
id/id_test.go
id/json_test.go
+2
-2
2 additions, 2 deletions
id/json_test.go
id/schema.go
+6
-7
6 additions, 7 deletions
id/schema.go
with
51 additions
and
16 deletions
id/id_test.go
+
43
−
7
View file @
6e4c58c3
...
...
@@ -11,6 +11,7 @@ func Test_ParseID(t *testing.T) {
name
string
id
string
result
*
ID
wantError
bool
}{
{
name
:
Service
,
...
...
@@ -75,7 +76,7 @@ func Test_ParseID(t *testing.T) {
SpaceID
:
SpaceID
{
SpaceID
:
"<space_id>"
},
EnvironmentID
:
"<env_id>"
,
},
Schema
ID
:
"<collection_id>"
,
Collection
ID
:
"<collection_id>"
,
}},
},
{
...
...
@@ -126,10 +127,45 @@ func Test_ParseID(t *testing.T) {
FieldName
:
"<field_name>"
,
}},
},
{
name
:
"With error #1: no backslash in the beginning of id"
,
id
:
"spaces/<space_id>"
,
result
:
nil
,
wantError
:
true
,
},
{
name
:
"With error #2: backslash in the end of id"
,
id
:
"/spaces/<space_id>/"
,
result
:
nil
,
wantError
:
true
,
},
{
name
:
"With error #3: typo in 'spaces'"
,
id
:
"/space/<space_id>"
,
result
:
nil
,
wantError
:
true
,
},
{
name
:
"With error #4: no space_id in id"
,
id
:
"/spaces"
,
result
:
nil
,
wantError
:
true
,
},
{
name
:
"With error #5: multiple backslashes in the end of id"
,
id
:
"/spaces/<space_id>///"
,
result
:
nil
,
wantError
:
true
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
id
,
_
:=
Parse
(
tt
.
id
)
id
,
err
:=
Parse
(
tt
.
id
)
if
tt
.
wantError
{
require
.
Error
(
t
,
err
)
return
}
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
tt
.
result
,
id
)
require
.
Equal
(
t
,
tt
.
id
,
id
.
String
(),
"проверяем корректность работы метода String, полученное ID должно совпадать с исходным"
)
})
...
...
@@ -209,13 +245,13 @@ func Test_Map(t *testing.T) {
{
name
:
Schema
,
id
:
ID
{
Descriptor
:
&
SchemaID
{}},
from
:
map
[
string
]
any
{
"space_id"
:
"<space_id>"
,
"env_id"
:
"<env_id>"
,
"
schema
_id"
:
"<collection_id>"
},
from
:
map
[
string
]
any
{
"space_id"
:
"<space_id>"
,
"env_id"
:
"<env_id>"
,
"
collection
_id"
:
"<collection_id>"
},
to
:
ID
{
Descriptor
:
&
SchemaID
{
EnvironmentID
:
EnvironmentID
{
SpaceID
:
SpaceID
{
SpaceID
:
"<space_id>"
},
EnvironmentID
:
"<env_id>"
,
},
Schema
ID
:
"<collection_id>"
,
Collection
ID
:
"<collection_id>"
,
}},
},
{
...
...
This diff is collapsed.
Click to expand it.
id/json_test.go
+
2
−
2
View file @
6e4c58c3
...
...
@@ -56,7 +56,7 @@ func TestID_MarshalJSON(t *testing.T) {
},
{
name
:
Schema
,
ID
:
ID
{
Descriptor
:
&
SchemaID
{
Schema
ID
:
"1"
,
EnvironmentID
:
EnvironmentID
{
EnvironmentID
:
"1"
,
SpaceID
:
SpaceID
{
SpaceID
:
"1"
}}}},
ID
:
ID
{
Descriptor
:
&
SchemaID
{
Collection
ID
:
"1"
,
EnvironmentID
:
EnvironmentID
{
EnvironmentID
:
"1"
,
SpaceID
:
SpaceID
{
SpaceID
:
"1"
}}}},
want
:
`"/spaces/1/envs/1/schema/1"`
,
},
{
...
...
@@ -132,7 +132,7 @@ func TestID_UnmarshalJSON(t *testing.T) {
},
{
id
:
Schema
,
want
:
ID
{
Descriptor
:
&
SchemaID
{
Schema
ID
:
"1"
,
EnvironmentID
:
EnvironmentID
{
EnvironmentID
:
"1"
,
SpaceID
:
SpaceID
{
SpaceID
:
"1"
}}}},
want
:
ID
{
Descriptor
:
&
SchemaID
{
Collection
ID
:
"1"
,
EnvironmentID
:
EnvironmentID
{
EnvironmentID
:
"1"
,
SpaceID
:
SpaceID
{
SpaceID
:
"1"
}}}},
b
:
[]
byte
(
`"/spaces/1/envs/1/schema/1"`
),
},
{
...
...
This diff is collapsed.
Click to expand it.
id/schema.go
+
6
−
7
View file @
6e4c58c3
...
...
@@ -6,20 +6,19 @@ const (
)
type
SchemaID
struct
{
SpaceID
EnvironmentID
Schema
ID
string
`json:"
schema
_id"`
Collection
ID
string
`json:"
collection
_id"`
}
func
(
t
*
SchemaID
)
Type
()
string
{
return
Schema
}
func
(
t
*
SchemaID
)
String
()
string
{
return
Join
(
t
.
EnvironmentID
.
String
(),
SchemaPrefix
,
t
.
Schema
ID
)
return
Join
(
t
.
EnvironmentID
.
String
(),
SchemaPrefix
,
t
.
Collection
ID
)
}
func
(
t
*
SchemaID
)
ToMap
()
map
[
string
]
any
{
m
:=
t
.
EnvironmentID
.
ToMap
()
m
[
"
schema_id"
]
=
t
.
Schema
ID
m
[
"
collection_id"
]
=
t
.
Collection
ID
return
m
}
...
...
@@ -27,12 +26,12 @@ func (t *SchemaID) FromMap(m map[string]any) error {
if
err
:=
t
.
EnvironmentID
.
FromMap
(
m
);
err
!=
nil
{
return
err
}
t
.
SchemaID
=
m
[
"schema
_id"
]
.
(
string
)
t
.
CollectionID
=
m
[
"collection
_id"
]
.
(
string
)
return
nil
}
func
(
t
*
SchemaID
)
Validate
()
error
{
if
t
.
Schema
ID
==
""
{
if
t
.
Collection
ID
==
""
{
return
ErrInvalidID
}
...
...
@@ -51,6 +50,6 @@ func parseSchemaID(parts []string) (*SchemaID, error) {
var
id
SchemaID
id
.
EnvironmentID
=
*
envID
id
.
Schema
ID
=
parts
[
5
]
id
.
Collection
ID
=
parts
[
5
]
return
&
id
,
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment