-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for NAS-specific errors; add more tests
Signed-off-by: Rumen Vasilev <git@rumenvasilev.com>
- Loading branch information
1 parent
7ce73a0
commit 6241dfb
Showing
7 changed files
with
201 additions
and
89 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 |
---|---|---|
@@ -1,14 +1,4 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ= | ||
github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= | ||
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,32 @@ | ||
package nas | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type SystemError struct { | ||
Message string | ||
Data *json.RawMessage | ||
Code int // http response code | ||
} | ||
|
||
type FileSystemControllerError struct { | ||
Message string | ||
Path string | ||
Code int // internal NAS response code | ||
} | ||
|
||
func (e *SystemError) Error() string { | ||
return e.Message | ||
} | ||
|
||
func (e *SystemError) Unwrap() error { | ||
var fse *FileSystemControllerError | ||
_ = json.Unmarshal(*e.Data, &fse) | ||
return fse | ||
} | ||
|
||
func (e *FileSystemControllerError) Error() string { | ||
return fmt.Sprintf("Code: %d, Path: %s, Msg: %s", e.Code, e.Path, e.Message) | ||
} |
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,37 @@ | ||
package nas | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/matryer/is" | ||
) | ||
|
||
var sampleError = `{ | ||
"error": { | ||
"message": "[file_system_controller] The folder with the name \"blabla\" already exists and therefore cannot be created.", | ||
"data": { | ||
"message": "The folder with the name \"blabla\" already exists and therefore cannot be created.", | ||
"path": "/Dokumente", | ||
"code": 5 | ||
}, | ||
"code": 400 | ||
} | ||
}` | ||
|
||
var sampleErrorStruct = SystemError{ | ||
Message: "[file_system_controller] The folder with the name \"blabla\" already exists and therefore cannot be created.", | ||
Data: nil, | ||
Code: 400, | ||
} | ||
|
||
func TestSystemError(t *testing.T) { | ||
var e struct { | ||
Err *SystemError `json:"error"` | ||
} | ||
err := json.Unmarshal([]byte(sampleError), &e) | ||
is := is.New(t) | ||
is.NoErr(err) | ||
is.True(e.Err != nil) | ||
is.Equal(e.Err.Error(), (&sampleErrorStruct).Error()) | ||
} |
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.