2020-08-25 12:11:06 +00:00
|
|
|
package client_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
2020-09-15 08:03:15 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
2020-08-25 12:11:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-crypto/test"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExample(t *testing.T) {
|
|
|
|
t.Skip()
|
|
|
|
target := "s01.localtest.nspcc.ru:50501"
|
|
|
|
key := test.DecodeKey(-1)
|
|
|
|
|
|
|
|
// create client from address
|
|
|
|
cli, err := client.New(key, client.WithAddress(target))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// ask for balance
|
|
|
|
resp, err := cli.GetSelfBalance(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-11-13 10:36:18 +00:00
|
|
|
fmt.Println(resp.Value(), resp.Precision())
|
2020-08-25 12:11:06 +00:00
|
|
|
|
|
|
|
// create client from grpc connection
|
|
|
|
conn, err := grpc.DialContext(context.Background(), target, grpc.WithBlock(), grpc.WithInsecure())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cli, err = client.New(key, client.WithGRPCConnection(conn))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-15 08:03:15 +00:00
|
|
|
replica := new(netmap.Replica)
|
|
|
|
replica.SetCount(2)
|
|
|
|
replica.SetSelector("*")
|
|
|
|
|
|
|
|
policy := new(netmap.PlacementPolicy)
|
|
|
|
policy.SetContainerBackupFactor(2)
|
2020-11-05 11:15:54 +00:00
|
|
|
policy.SetReplicas(replica)
|
2020-09-15 08:03:15 +00:00
|
|
|
|
2020-08-25 12:11:06 +00:00
|
|
|
// this container has random nonce and it does not set owner id
|
2020-09-15 08:03:15 +00:00
|
|
|
cnr := container.New(
|
2020-08-25 12:11:06 +00:00
|
|
|
container.WithAttribute("CreatedAt", time.Now().String()),
|
2020-09-15 08:03:15 +00:00
|
|
|
container.WithPolicy(policy),
|
2020-08-25 12:11:06 +00:00
|
|
|
container.WithReadOnlyBasicACL(),
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// here container will have owner id from client key, and it will be signed
|
|
|
|
containerID, err := cli.PutContainer(context.Background(), cnr, client.WithTTL(10))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Println(containerID)
|
|
|
|
|
|
|
|
list, err := cli.ListSelfContainers(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for i := range list {
|
|
|
|
fmt.Println("found container:", list[i])
|
|
|
|
}
|
|
|
|
}
|