storj/lib/uplink/libuplink_test.go
Dylan Lott 6bf46e80ee
Adds Libuplink (#1452)
* Merge in upstream

* Some initial wireup

* Added common.go file, more misc. work

* WIP adding identity in

* Get FullIdentity combined into Uplink

* Structure libuplink a little better

* Update some types and add some comments

* WIP uplink stuff

* Get uplink types and configs figured out

* add initial setup for tests, happy path is working

* Remove dependency from miniogw

* Adds miniogw code and wires it up correctly

* WIP working on getting test suite setup

* Uplink client now returns successfully and passes some initial happy path tets

* WIP trying to get v2 draft ready

* WIP

* WIP wiring up bucket methods and adjusting to some review feedback

* Getting closer to v2 libuplink draft

* CreateBucket now works and has tests to prove it

* Bucket tests are passing now

* removing some code

* Updates error handling and linter fixes

* Removes main_test

* Uploads and downloads are now working

* Rename BucketOpts to Encryption

* updates

* added test file back to git that was being ignored for some reason

* more test conditions

* changes Checksum in ObjectMeta struct to be type []byte

* linter fix

* Updates how encryption is passed through to bucket opts

* Updates encryption handling at bucket and access level

* Fixes imports

* Updates per code review
2019-03-20 09:43:53 -06:00

132 lines
3.6 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package uplink
import (
"testing"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testplanet"
"storj.io/storj/pkg/cfgstruct"
"storj.io/storj/pkg/identity"
"storj.io/storj/pkg/storj"
"storj.io/storj/satellite"
ul "storj.io/storj/uplink"
)
func TestUplink(t *testing.T) {
// Planet Config for Uplink
testplanetConfig := testplanet.Config{
SatelliteCount: 1,
StorageNodeCount: 20,
UplinkCount: 1,
}
// Run Tests
testplanet.Run(t, testplanetConfig, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
satellite := planet.Satellites[0]
identity, err := identity.NewFullIdentity(ctx, 12, 4)
assert.NoError(t, err)
satelliteAddr := satellite.Addr() // get address
cfg := getConfig(satellite, planet)
uplink := NewUplink(identity, satelliteAddr, cfg)
permissions := Permissions{}
access := uplink.Access(ctx, permissions)
assert.NoError(t, err)
opts := CreateBucketOptions{}
bucket, err := access.CreateBucket(ctx, "testbucket", opts)
assert.NoError(t, err)
assert.NotNil(t, bucket)
bucketListOptions := storj.BucketListOptions{
Limit: 1000,
Direction: storj.ListDirection(1),
}
buckets, err := access.ListBuckets(ctx, bucketListOptions)
assert.NoError(t, err)
assert.NotNil(t, buckets)
storjBucket, err := access.GetBucketInfo(ctx, "testbucket")
assert.NoError(t, err)
assert.NotNil(t, storjBucket)
assert.Equal(t, storjBucket.Name, "testbucket")
assert.IsType(t, storj.Bucket{}, storjBucket)
encOpts := &Encryption{}
getbucket := access.GetBucket(ctx, "testbucket", encOpts)
assert.NoError(t, err)
assert.NotNil(t, getbucket)
err = access.DeleteBucket(ctx, "testbucket")
assert.NoError(t, err)
uploadtest, err := access.CreateBucket(ctx, "uploadtest", opts)
assert.NoError(t, err)
assert.NotNil(t, uploadtest)
assert.Equal(t, uploadtest.Name, "uploadtest")
uploadBucket := access.GetBucket(ctx, "uploadtest", encOpts)
assert.NotNil(t, uploadBucket)
list, err := uploadBucket.List(ctx, ListObjectsConfig{
Direction: storj.ListDirection(1),
Limit: 100,
})
assert.NoError(t, err)
assert.NotNil(t, list)
assert.Equal(t, len(list.Items), 0)
testdata := []byte{1, 1, 1, 1, 1}
uploadOpts := UploadOpts{}
err = uploadBucket.Upload(ctx, "testpath", testdata, uploadOpts)
assert.NoError(t, err)
downloadedData, err := uploadBucket.Download(ctx, "testpath")
assert.NotNil(t, downloadedData)
assert.NoError(t, err)
assert.Equal(t, testdata, downloadedData)
list2, err := uploadBucket.List(ctx, ListObjectsConfig{
Direction: storj.ListDirection(1),
Limit: 100,
})
assert.NotNil(t, list2)
assert.NoError(t, err)
assert.NotNil(t, list2.Items)
assert.Equal(t, len(list2.Items), 1)
})
}
func getConfig(satellite *satellite.Peer, planet *testplanet.Planet) ul.Config {
config := getDefaultConfig()
config.Client.OverlayAddr = satellite.Addr()
config.Client.PointerDBAddr = satellite.Addr()
config.Client.APIKey = planet.Uplinks[0].APIKey[satellite.ID()]
config.RS.MinThreshold = 1 * len(planet.StorageNodes) / 5
config.RS.RepairThreshold = 2 * len(planet.StorageNodes) / 5
config.RS.SuccessThreshold = 3 * len(planet.StorageNodes) / 5
config.RS.MaxThreshold = 4 * len(planet.StorageNodes) / 5
config.TLS.UsePeerCAWhitelist = false
config.TLS.Extensions.Revocation = false
config.TLS.Extensions.WhitelistSignedLeaf = false
return config
}
func getDefaultConfig() ul.Config {
cfg := ul.Config{}
cfgstruct.Bind(&pflag.FlagSet{}, &cfg, true)
return cfg
}