storagenode: Add more test assertions (#2772)

This commit is contained in:
Ivan Fraixedes 2019-08-13 21:08:05 +02:00 committed by Maximillian von Briesen
parent 9eba5ac631
commit 26fb992474
2 changed files with 22 additions and 7 deletions

View File

@ -149,13 +149,17 @@ func TestDB_Trivial(t *testing.T) {
} }
{ // Ensure ListUnsent works at all { // Ensure ListUnsent works at all
_, err := db.Orders().ListUnsent(ctx, 1) infos, err := db.Orders().ListUnsent(ctx, 1)
require.NoError(t, err) require.NoError(t, err)
require.Len(t, infos, 1)
} }
{ // Ensure ListUnsentBySatellite works at all { // Ensure ListUnsentBySatellite works at all
_, err := db.Orders().ListUnsentBySatellite(ctx) infos, err := db.Orders().ListUnsentBySatellite(ctx)
require.NoError(t, err) require.NoError(t, err)
require.Len(t, infos, 1)
require.Contains(t, infos, satelliteID)
require.Len(t, infos[satelliteID], 1)
} }
{ // Ensure Archive works at all { // Ensure Archive works at all
@ -164,8 +168,9 @@ func TestDB_Trivial(t *testing.T) {
} }
{ // Ensure ListArchived works at all { // Ensure ListArchived works at all
_, err := db.Orders().ListArchived(ctx, 1) infos, err := db.Orders().ListArchived(ctx, 1)
require.NoError(t, err) require.NoError(t, err)
require.Len(t, infos, 1)
} }
}) })
} }

View File

@ -140,7 +140,6 @@ func TestUpload(t *testing.T) {
}, },
} { } {
data := testrand.Bytes(tt.contentLength) data := testrand.Bytes(tt.contentLength)
expectedHash := pkcrypto.SHA256Hash(data)
serialNumber := testrand.SerialNumber() serialNumber := testrand.SerialNumber()
orderLimit, piecePrivateKey := GenerateOrderLimit( orderLimit, piecePrivateKey := GenerateOrderLimit(
@ -171,6 +170,7 @@ func TestUpload(t *testing.T) {
} else { } else {
require.NoError(t, err) require.NoError(t, err)
expectedHash := pkcrypto.SHA256Hash(data)
assert.Equal(t, expectedHash, pieceHash.Hash) assert.Equal(t, expectedHash, pieceHash.Hash)
signee := signing.SignerFromFullIdentity(planet.StorageNodes[0].Identity) signee := signing.SignerFromFullIdentity(planet.StorageNodes[0].Identity)
@ -230,6 +230,11 @@ func TestDownload(t *testing.T) {
pieceID: orderLimit.PieceId, pieceID: orderLimit.PieceId,
action: pb.PieceAction_GET, action: pb.PieceAction_GET,
}, },
{ // should err with piece ID not specified
pieceID: storj.PieceID{},
action: pb.PieceAction_GET,
errs: []string{"missing piece id"},
},
{ // should err with piece ID not specified { // should err with piece ID not specified
pieceID: storj.PieceID{2}, pieceID: storj.PieceID{2},
action: pb.PieceAction_GET, action: pb.PieceAction_GET,
@ -327,17 +332,22 @@ func TestDelete(t *testing.T) {
action pb.PieceAction action pb.PieceAction
err string err string
}{ }{
{ // should successfully download data { // should successfully delete data
pieceID: orderLimit.PieceId, pieceID: orderLimit.PieceId,
action: pb.PieceAction_DELETE, action: pb.PieceAction_DELETE,
err: "", err: "",
}, },
{ // should err with piece ID not specified { // should err with piece ID not found
pieceID: storj.PieceID{99}, pieceID: storj.PieceID{99},
action: pb.PieceAction_DELETE, action: pb.PieceAction_DELETE,
err: "", // TODO should this return error err: "", // TODO should this return error
}, },
{ // should successfully download data { // should err with piece ID not specified
pieceID: storj.PieceID{},
action: pb.PieceAction_DELETE,
err: "missing piece id",
},
{ // should err due to incorrect action
pieceID: orderLimit.PieceId, pieceID: orderLimit.PieceId,
action: pb.PieceAction_GET, action: pb.PieceAction_GET,
err: "expected delete action got GET", err: "expected delete action got GET",