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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
157c90b1
Commit
157c90b1
authored
1 year ago
by
Semyon Krestyaninov
Browse files
Options
Downloads
Patches
Plain Diff
fix
parent
3accb6dd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
id/object_id_test.go
+12
-1
12 additions, 1 deletion
id/object_id_test.go
id/registry.go
+6
-1
6 additions, 1 deletion
id/registry.go
with
18 additions
and
2 deletions
id/object_id_test.go
+
12
−
1
View file @
157c90b1
...
@@ -3,6 +3,7 @@ package id
...
@@ -3,6 +3,7 @@ package id
import
(
import
(
"testing"
"testing"
"git.perx.ru/perxis/perxis-go/pkg/items"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
...
@@ -10,7 +11,7 @@ import (
...
@@ -10,7 +11,7 @@ import (
func
Test_ParseID
(
t
*
testing
.
T
)
{
func
Test_ParseID
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
id
string
id
any
result
*
ObjectId
result
*
ObjectId
wantError
bool
wantError
bool
}{
}{
...
@@ -104,6 +105,16 @@ func Test_ParseID(t *testing.T) {
...
@@ -104,6 +105,16 @@ func Test_ParseID(t *testing.T) {
result
:
nil
,
result
:
nil
,
wantError
:
true
,
wantError
:
true
,
},
},
{
name
:
"With error #6: nil value"
,
id
:
nil
,
wantError
:
true
,
},
{
name
:
"With error #7: nil object value"
,
id
:
(
*
items
.
Item
)(
nil
),
wantError
:
true
,
},
}
}
for
_
,
tt
:=
range
tests
{
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
id/registry.go
+
6
−
1
View file @
157c90b1
...
@@ -61,7 +61,12 @@ func (r *Registry) FromMap(m map[string]interface{}) (*ObjectId, error) {
...
@@ -61,7 +61,12 @@ func (r *Registry) FromMap(m map[string]interface{}) (*ObjectId, error) {
}
}
func
(
r
*
Registry
)
FromObject
(
v
interface
{})
(
*
ObjectId
,
error
)
{
func
(
r
*
Registry
)
FromObject
(
v
interface
{})
(
*
ObjectId
,
error
)
{
t
:=
reflect
.
TypeOf
(
v
)
value
:=
reflect
.
ValueOf
(
v
)
if
v
==
nil
||
(
value
.
Kind
()
==
reflect
.
Ptr
&&
value
.
IsNil
())
{
return
nil
,
fmt
.
Errorf
(
"object value is nil"
)
}
t
:=
value
.
Type
()
if
handler
,
ok
:=
r
.
handlers
[
t
];
ok
{
if
handler
,
ok
:=
r
.
handlers
[
t
];
ok
{
i
:=
handler
(
v
)
i
:=
handler
(
v
)
if
i
==
nil
{
if
i
==
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