storj/satellite/vouchers/vouchers_test.go
Egon Elbre 5d0816430f
rename all the things (#2531)
* rename pkg/linksharing to linksharing
* rename pkg/httpserver to linksharing/httpserver
* rename pkg/eestream to uplink/eestream
* rename pkg/stream to uplink/stream
* rename pkg/metainfo/kvmetainfo to uplink/metainfo/kvmetainfo
* rename pkg/auth/signing to pkg/signing
* rename pkg/storage to uplink/storage
* rename pkg/accounting to satellite/accounting
* rename pkg/audit to satellite/audit
* rename pkg/certdb to satellite/certdb
* rename pkg/discovery to satellite/discovery
* rename pkg/overlay to satellite/overlay
* rename pkg/datarepair to satellite/repair
2019-07-28 08:55:36 +03:00

77 lines
1.9 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package vouchers_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testplanet"
"storj.io/storj/pkg/pb"
"storj.io/storj/satellite"
"storj.io/storj/satellite/overlay"
"storj.io/storj/storagenode"
)
func TestVouchers(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 2, UplinkCount: 0,
Reconfigure: testplanet.Reconfigure{
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Overlay.Node.AuditCount = 1
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
tests := []struct {
node *storagenode.Peer
reputable bool
}{
{
node: planet.StorageNodes[0],
reputable: true,
},
{
node: planet.StorageNodes[1],
reputable: false,
},
}
satellite := planet.Satellites[0].Local().Node
for _, tt := range tests {
if tt.reputable {
_, err := planet.Satellites[0].DB.OverlayCache().UpdateStats(ctx, &overlay.UpdateRequest{
NodeID: tt.node.ID(),
IsUp: true,
AuditSuccess: true,
})
require.NoError(t, err)
}
conn, err := tt.node.Transport.DialNode(ctx, &satellite)
require.NoError(t, err)
defer ctx.Check(conn.Close)
client := pb.NewVouchersClient(conn)
resp, err := client.Request(ctx, &pb.VoucherRequest{})
voucher := resp.GetVoucher()
if tt.reputable {
assert.NoError(t, err)
assert.NotNil(t, voucher)
assert.Equal(t, pb.VoucherResponse_ACCEPTED, resp.GetStatus())
assert.Equal(t, tt.node.ID(), voucher.StorageNodeId)
} else {
require.NoError(t, err)
assert.Equal(t, pb.VoucherResponse_REJECTED, resp.GetStatus())
assert.Nil(t, voucher)
}
}
})
}