use proper error assertion (OCIS-363)
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
merrors "github.com/micro/go-micro/v2/errors"
|
||||||
|
|
||||||
mgrpc "github.com/micro/go-micro/v2/client/grpc"
|
mgrpc "github.com/micro/go-micro/v2/client/grpc"
|
||||||
ocislog "github.com/owncloud/ocis-pkg/v2/log"
|
ocislog "github.com/owncloud/ocis-pkg/v2/log"
|
||||||
"github.com/owncloud/ocis-pkg/v2/service/grpc"
|
"github.com/owncloud/ocis-pkg/v2/service/grpc"
|
||||||
@@ -71,13 +73,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomError struct {
|
|
||||||
ID string
|
|
||||||
Code int
|
|
||||||
Detail string
|
|
||||||
Status string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
testing that saving a settings bundle and retrieving it again works correctly
|
testing that saving a settings bundle and retrieving it again works correctly
|
||||||
using various setting bundle properties
|
using various setting bundle properties
|
||||||
@@ -92,7 +87,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
displayName string
|
displayName string
|
||||||
extensionName string
|
extensionName string
|
||||||
UUID string
|
UUID string
|
||||||
expectedError CustomError
|
expectedError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"ASCII",
|
"ASCII",
|
||||||
@@ -100,7 +95,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"simple-bundle-key",
|
"simple-bundle-key",
|
||||||
"simple-extension-name",
|
"simple-extension-name",
|
||||||
"123e4567-e89b-12d3-a456-426652340000",
|
"123e4567-e89b-12d3-a456-426652340000",
|
||||||
CustomError{},
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"UTF validation on bundle name",
|
"UTF validation on bundle name",
|
||||||
@@ -108,12 +103,10 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"सिम्प्ले-display-name",
|
"सिम्प्ले-display-name",
|
||||||
"सिम्प्ले-extension-name",
|
"सिम्प्ले-extension-name",
|
||||||
"सिम्प्ले",
|
"सिम्प्ले",
|
||||||
CustomError{
|
merrors.New("", "extension: must be in a valid format; name: must be in a valid format.", 0),
|
||||||
ID: "go.micro.client",
|
//CustomError{
|
||||||
Code: 500,
|
// Detail: "extension: must be in a valid format; name: must be in a valid format.",
|
||||||
Detail: "extension: must be in a valid format; name: must be in a valid format.",
|
//},
|
||||||
Status: "Internal Server Error",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"UTF validation on display name",
|
"UTF validation on display name",
|
||||||
@@ -121,12 +114,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"सिम्प्ले-display-name",
|
"सिम्प्ले-display-name",
|
||||||
"simple-extension-name",
|
"simple-extension-name",
|
||||||
"123e4567-e89b-12d3-a456-426652340000",
|
"123e4567-e89b-12d3-a456-426652340000",
|
||||||
CustomError{
|
merrors.New("", "name: must be in a valid format.", 0),
|
||||||
ID: "go.micro.client",
|
|
||||||
Code: 500,
|
|
||||||
Detail: "name: must be in a valid format.",
|
|
||||||
Status: "Internal Server Error",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"extension name with ../ in the name",
|
"extension name with ../ in the name",
|
||||||
@@ -134,12 +122,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"simple-display-name",
|
"simple-display-name",
|
||||||
"../folder-a-level-higher-up",
|
"../folder-a-level-higher-up",
|
||||||
"123e4567-e89b-12d3-a456-426652340000",
|
"123e4567-e89b-12d3-a456-426652340000",
|
||||||
CustomError{
|
merrors.New("", "extension: must be in a valid format.", 0),
|
||||||
ID: "go.micro.client",
|
|
||||||
Code: 500,
|
|
||||||
Detail: "extension: must be in a valid format.",
|
|
||||||
Status: "Internal Server Error",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"extension name with \\ in the name",
|
"extension name with \\ in the name",
|
||||||
@@ -147,12 +130,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"simple-display-name",
|
"simple-display-name",
|
||||||
"\\",
|
"\\",
|
||||||
"123e4567-e89b-12d3-a456-426652340000",
|
"123e4567-e89b-12d3-a456-426652340000",
|
||||||
CustomError{
|
merrors.New("", "extension: must be in a valid format.", 0),
|
||||||
ID: "go.micro.client",
|
|
||||||
Code: 500,
|
|
||||||
Detail: "extension: must be in a valid format.",
|
|
||||||
Status: "Internal Server Error",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"spaces are disallowed in bundle names",
|
"spaces are disallowed in bundle names",
|
||||||
@@ -160,9 +138,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"simple display name",
|
"simple display name",
|
||||||
"simple extension name",
|
"simple extension name",
|
||||||
"123e4567-e89b-12d3-a456-426652340000",
|
"123e4567-e89b-12d3-a456-426652340000",
|
||||||
CustomError{
|
merrors.New("", "extension: must be in a valid format; name: must be in a valid format.", 0),
|
||||||
Detail: "extension: must be in a valid format; name: must be in a valid format.",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"spaces are allowed in display names",
|
"spaces are allowed in display names",
|
||||||
@@ -170,7 +146,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"simple display name",
|
"simple display name",
|
||||||
"simple-extension-name",
|
"simple-extension-name",
|
||||||
"123e4567-e89b-12d3-a456-426652340000",
|
"123e4567-e89b-12d3-a456-426652340000",
|
||||||
CustomError{},
|
nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"extension missing",
|
"extension missing",
|
||||||
@@ -178,12 +154,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"simple-display-name",
|
"simple-display-name",
|
||||||
"",
|
"",
|
||||||
"123e4567-e89b-12d3-a456-426652340000",
|
"123e4567-e89b-12d3-a456-426652340000",
|
||||||
CustomError{
|
merrors.New("", "extension: cannot be blank.", 0),
|
||||||
ID: "go.micro.client",
|
|
||||||
Code: 500,
|
|
||||||
Detail: "extension: cannot be blank.",
|
|
||||||
Status: "Internal Server Error",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"display name missing",
|
"display name missing",
|
||||||
@@ -191,12 +162,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"",
|
"",
|
||||||
"simple-extension-name",
|
"simple-extension-name",
|
||||||
"123e4567-e89b-12d3-a456-426652340000",
|
"123e4567-e89b-12d3-a456-426652340000",
|
||||||
CustomError{
|
merrors.New("", "display_name: cannot be blank.", 0),
|
||||||
ID: "go.micro.client",
|
|
||||||
Code: 500,
|
|
||||||
Detail: "display_name: cannot be blank.",
|
|
||||||
Status: "Internal Server Error",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"UUID missing (omitted on bundles)",
|
"UUID missing (omitted on bundles)",
|
||||||
@@ -204,7 +170,7 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
"simple-display-name",
|
"simple-display-name",
|
||||||
"simple-extension-name",
|
"simple-extension-name",
|
||||||
"",
|
"",
|
||||||
CustomError{},
|
nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, scenario := range scenarios {
|
for _, scenario := range scenarios {
|
||||||
@@ -225,14 +191,9 @@ func TestSettingsBundleProperties(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cresponse, err := cl.SaveBundle(context.Background(), &createRequest)
|
cresponse, err := cl.SaveBundle(context.Background(), &createRequest)
|
||||||
if err != nil || (CustomError{} != scenario.expectedError) {
|
if err != nil || scenario.expectedError != nil {
|
||||||
assert.Error(t, err)
|
t.Log(err)
|
||||||
var errorData CustomError
|
assert.Equal(t, scenario.expectedError, err)
|
||||||
err = json.Unmarshal([]byte(err.Error()), &errorData)
|
|
||||||
if err != nil {
|
|
||||||
t.Log(err)
|
|
||||||
}
|
|
||||||
assert.Equal(t, scenario.expectedError.Detail, errorData.Detail)
|
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, scenario.extensionName, cresponse.Bundle.Extension)
|
assert.Equal(t, scenario.extensionName, cresponse.Bundle.Extension)
|
||||||
assert.Equal(t, scenario.displayName, cresponse.Bundle.DisplayName)
|
assert.Equal(t, scenario.displayName, cresponse.Bundle.DisplayName)
|
||||||
@@ -258,9 +219,7 @@ func TestSettingsBundleWithoutSettings(t *testing.T) {
|
|||||||
response, err := cl.SaveBundle(context.Background(), &createRequest)
|
response, err := cl.SaveBundle(context.Background(), &createRequest)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Nil(t, response)
|
assert.Nil(t, response)
|
||||||
var errorData CustomError
|
assert.Equal(t, merrors.New("", "extension: cannot be blank; name: cannot be blank; settings: cannot be blank.", 0), err)
|
||||||
_ = json.Unmarshal([]byte(err.Error()), &errorData)
|
|
||||||
assert.Equal(t, "extension: cannot be blank; name: cannot be blank; settings: cannot be blank.", errorData.Detail)
|
|
||||||
os.RemoveAll(dataStore)
|
os.RemoveAll(dataStore)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user