Skip to content

Commit

Permalink
[Disk Manager] fix facade/image_service_*test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Montsev committed Jan 23, 2024
1 parent f0bfcb0 commit 9914f72
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,7 @@ func TestDiskServiceShouldFailCreateDiskFromNonExistingImage(t *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "not found")
status, ok := grpc_status.FromError(err)
require.True(t, ok)
statusDetails := status.Details()
require.Equal(t, 1, len(statusDetails))
errorDetails, ok := statusDetails[0].(*disk_manager.ErrorDetails)
require.True(t, ok)
require.Equal(t, int64(codes.BadSource), errorDetails.Code)
require.False(t, errorDetails.Internal)
testcommon.CheckErrorDetails(t, err, codes.BadSource, "", false /* internal */)

testcommon.CheckConsistency(t, ctx)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/types"
sdk_client "github.com/ydb-platform/nbs/cloud/disk_manager/pkg/client"
"github.com/ydb-platform/nbs/cloud/disk_manager/pkg/client/codes"
grpc_status "google.golang.org/grpc/status"
)

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -651,18 +650,13 @@ func testShouldFailCreateImageFromImageFileURL(
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.Error(t, err)

status, ok := grpc_status.FromError(err)
require.True(t, ok)

statusDetails := status.Details()
require.Equal(t, 1, len(statusDetails))

errorDetails, ok := statusDetails[0].(*disk_manager.ErrorDetails)
require.True(t, ok)

require.Equal(t, int64(codes.BadSource), errorDetails.Code)
require.False(t, errorDetails.Internal)
require.Equal(t, errorDetailsMessage, errorDetails.Message)
testcommon.CheckErrorDetails(
t,
err,
codes.BadSource,
errorDetailsMessage,
true, // internal
)

testcommon.CheckConsistency(t, ctx)
}
Expand Down
31 changes: 31 additions & 0 deletions cloud/disk_manager/internal/pkg/facade/testcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/empty"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -674,3 +675,33 @@ func GetEncryptionKeyHash(encryptionDesc *types.EncryptionDesc) ([]byte, error)
return nil, errors.NewNonRetriableErrorf("unknown key %s", key)
}
}

////////////////////////////////////////////////////////////////////////////////

func CheckErrorDetails(
t *testing.T,
err error,
code int,
message string,
internal bool,
) {

status, ok := grpc_status.FromError(err)
require.True(t, ok)

statusDetails := status.Details()
require.Equal(t, 1, len(statusDetails))

protoMessage, err := proto.Marshal(statusDetails[0].(proto.Message))
require.NoError(t, err)

var errorDetails disk_manager.ErrorDetails
err = proto.Unmarshal(protoMessage, &errorDetails)
require.NoError(t, err)

require.Equal(t, int64(code), errorDetails.Code)
require.False(t, errorDetails.Internal)
if len(message) != 0 {
require.Equal(t, message, errorDetails.Message)
}
}

0 comments on commit 9914f72

Please sign in to comment.