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

fix

parent 46b4b1da
Branches
Tags
No related merge requests found
...@@ -17,7 +17,29 @@ type ActionURL struct { ...@@ -17,7 +17,29 @@ type ActionURL struct {
// New возвращает структуру ActionURL // New возвращает структуру ActionURL
func New(action string) (*ActionURL, error) { func New(action string) (*ActionURL, error) {
return parse(action) actionURL := &ActionURL{}
if action == "" {
return actionURL, nil
}
err := actionURL.SetURL(action)
if err != nil {
return nil, err
}
if actionURL.URL.Scheme == "grpc" {
path := actionURL.Path
if strings.HasPrefix(actionURL.Path, "/") {
path = actionURL.Path[1:]
}
splitPath := strings.Split(path, "/")
if len(splitPath) < 2 {
return nil, errors.Errorf("incorrect action URL, no action id: '%s'", action)
}
actionURL.extension = splitPath[0]
actionURL.id = splitPath[1]
}
return actionURL, nil
} }
// ID возвращает сохраненный в ActionURL id действия // ID возвращает сохраненный в ActionURL id действия
...@@ -55,28 +77,3 @@ func (p *ActionURL) Make() string { ...@@ -55,28 +77,3 @@ func (p *ActionURL) Make() string {
} }
return p.URL.String() return p.URL.String()
} }
// parse функция для заполнения структуры ActionURL из переданного действия
func parse(action string) (*ActionURL, error) {
if action == "" {
return &ActionURL{}, nil
}
actionURL := &ActionURL{}
err := actionURL.SetURL(action)
if err != nil {
return nil, err
}
if actionURL.URL.Scheme == "grpc" {
path := actionURL.Path
if strings.HasPrefix(actionURL.Path, "/") {
path = actionURL.Path[1:]
}
splitPath := strings.Split(path, "/")
if len(splitPath) < 2 {
return nil, errors.Errorf("incorrect action URL, no action id: '%s'", action)
}
actionURL.extension = splitPath[0]
actionURL.id = splitPath[1]
}
return actionURL, nil
}
...@@ -61,6 +61,12 @@ func TestActionURL_New(t *testing.T) { ...@@ -61,6 +61,12 @@ func TestActionURL_New(t *testing.T) {
want: nil, want: nil,
wantErr: assert.Error, wantErr: assert.Error,
}, },
{
name: "With no action id",
action: "grpc:///perxisweb",
want: nil,
wantErr: assert.Error,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment