-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add more helper functions for identifiers
It is often needed to get another ID, as well as a list of random ones. With new functions, `cidtest.IDWithChecksum` becomes redundant, so it marked as deprecated. Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
- Loading branch information
1 parent
66ae541
commit 1674080
Showing
9 changed files
with
223 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cidtest_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/nspcc-dev/neofs-api-go/v2/refs" | ||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" | ||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestID(t *testing.T) { | ||
id := cidtest.ID() | ||
require.NotEqual(t, id, cidtest.ID()) | ||
|
||
var m refs.ContainerID | ||
id.WriteToV2(&m) | ||
var id2 cid.ID | ||
require.NoError(t, id2.ReadFromV2(m)) | ||
} | ||
|
||
func TestNIDs(t *testing.T) { | ||
n := rand.Int() % 10 | ||
require.Len(t, cidtest.IDs(n), n) | ||
} | ||
|
||
func TestOtherID(t *testing.T) { | ||
ids := cidtest.IDs(100) | ||
require.NotContains(t, ids, cidtest.OtherID(ids...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package oidtest_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/nspcc-dev/neofs-api-go/v2/refs" | ||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" | ||
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestID(t *testing.T) { | ||
id := oidtest.ID() | ||
require.NotEqual(t, id, oidtest.ID()) | ||
|
||
var m refs.ObjectID | ||
id.WriteToV2(&m) | ||
var id2 oid.ID | ||
require.NoError(t, id2.ReadFromV2(m)) | ||
} | ||
|
||
func TestNIDs(t *testing.T) { | ||
n := rand.Int() % 10 | ||
require.Len(t, oidtest.IDs(n), n) | ||
} | ||
|
||
func TestOtherID(t *testing.T) { | ||
ids := oidtest.IDs(100) | ||
require.NotContains(t, ids, oidtest.OtherID(ids...)) | ||
} | ||
|
||
func TestAddress(t *testing.T) { | ||
a := oidtest.Address() | ||
require.NotEqual(t, a, oidtest.Address()) | ||
|
||
var m refs.Address | ||
a.WriteToV2(&m) | ||
var id2 oid.Address | ||
require.NoError(t, id2.ReadFromV2(m)) | ||
} | ||
|
||
func TestChangeAddress(t *testing.T) { | ||
addrs := oidtest.Addresses(100) | ||
require.NotContains(t, addrs, oidtest.OtherAddress(addrs...)) | ||
} | ||
|
||
func TestNAddresses(t *testing.T) { | ||
n := rand.Int() % 10 | ||
require.Len(t, oidtest.Addresses(n), n) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package usertest_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/nspcc-dev/neofs-api-go/v2/refs" | ||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" | ||
"github.com/nspcc-dev/neofs-sdk-go/user" | ||
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestID(t *testing.T) { | ||
id := usertest.ID() | ||
require.NotEqual(t, id, usertest.ID()) | ||
|
||
var m refs.OwnerID | ||
id.WriteToV2(&m) | ||
var id2 user.ID | ||
require.NoError(t, id2.ReadFromV2(m)) | ||
} | ||
|
||
func TestNIDs(t *testing.T) { | ||
n := rand.Int() % 10 | ||
require.Len(t, cidtest.IDs(n), n) | ||
} | ||
|
||
func TestOtherID(t *testing.T) { | ||
ids := usertest.IDs(100) | ||
require.NotContains(t, ids, usertest.OtherID(ids...)) | ||
} |