2020-12-21 07:52:34 +00:00
|
|
|
package audit_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-12-21 14:35:03 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
2020-12-21 07:52:34 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/audit"
|
2021-06-08 11:39:41 +00:00
|
|
|
audittest "github.com/nspcc-dev/neofs-api-go/pkg/audit/test"
|
2021-05-31 12:09:04 +00:00
|
|
|
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
2020-12-21 07:52:34 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2021-06-08 08:38:29 +00:00
|
|
|
objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test"
|
2021-06-08 11:33:56 +00:00
|
|
|
auditv2 "github.com/nspcc-dev/neofs-api-go/v2/audit"
|
2020-12-21 07:52:34 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestResult(t *testing.T) {
|
|
|
|
r := audit.NewResult()
|
2020-12-21 14:35:03 +00:00
|
|
|
require.Equal(t, pkg.SDKVersion(), r.Version())
|
2020-12-21 07:52:34 +00:00
|
|
|
|
|
|
|
epoch := uint64(13)
|
|
|
|
r.SetAuditEpoch(epoch)
|
|
|
|
require.Equal(t, epoch, r.AuditEpoch())
|
|
|
|
|
2021-05-31 12:09:04 +00:00
|
|
|
cid := cidtest.Generate()
|
2020-12-21 07:52:34 +00:00
|
|
|
r.SetContainerID(cid)
|
|
|
|
require.Equal(t, cid, r.ContainerID())
|
|
|
|
|
|
|
|
key := []byte{1, 2, 3}
|
|
|
|
r.SetPublicKey(key)
|
|
|
|
require.Equal(t, key, r.PublicKey())
|
|
|
|
|
2020-12-21 14:35:03 +00:00
|
|
|
r.SetComplete(true)
|
|
|
|
require.True(t, r.Complete())
|
|
|
|
|
2020-12-23 15:45:00 +00:00
|
|
|
requests := uint32(2)
|
|
|
|
r.SetRequests(requests)
|
|
|
|
require.Equal(t, requests, r.Requests())
|
|
|
|
|
|
|
|
retries := uint32(1)
|
|
|
|
r.SetRetries(retries)
|
|
|
|
require.Equal(t, retries, r.Retries())
|
|
|
|
|
2021-06-08 11:39:41 +00:00
|
|
|
passSG := []*object.ID{objecttest.ID(), objecttest.ID()}
|
2020-12-21 07:52:34 +00:00
|
|
|
r.SetPassSG(passSG)
|
|
|
|
require.Equal(t, passSG, r.PassSG())
|
|
|
|
|
2021-06-08 11:39:41 +00:00
|
|
|
failSG := []*object.ID{objecttest.ID(), objecttest.ID()}
|
2020-12-21 07:52:34 +00:00
|
|
|
r.SetFailSG(failSG)
|
|
|
|
require.Equal(t, failSG, r.FailSG())
|
|
|
|
|
|
|
|
hit := uint32(1)
|
|
|
|
r.SetHit(hit)
|
|
|
|
require.Equal(t, hit, r.Hit())
|
|
|
|
|
|
|
|
miss := uint32(2)
|
|
|
|
r.SetMiss(miss)
|
|
|
|
require.Equal(t, miss, r.Miss())
|
|
|
|
|
|
|
|
fail := uint32(3)
|
|
|
|
r.SetFail(fail)
|
|
|
|
require.Equal(t, fail, r.Fail())
|
|
|
|
|
|
|
|
passNodes := [][]byte{{1}, {2}}
|
|
|
|
r.SetPassNodes(passNodes)
|
|
|
|
require.Equal(t, passNodes, r.PassNodes())
|
|
|
|
|
|
|
|
failNodes := [][]byte{{3}, {4}}
|
|
|
|
r.SetFailNodes(failNodes)
|
|
|
|
require.Equal(t, failNodes, r.FailNodes())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStorageGroupEncoding(t *testing.T) {
|
2021-06-08 11:39:41 +00:00
|
|
|
r := audittest.Generate()
|
2020-12-21 07:52:34 +00:00
|
|
|
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
|
|
data, err := r.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
r2 := audit.NewResult()
|
|
|
|
require.NoError(t, r2.Unmarshal(data))
|
|
|
|
|
|
|
|
require.Equal(t, r, r2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
|
|
data, err := r.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
r2 := audit.NewResult()
|
|
|
|
require.NoError(t, r2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, r, r2)
|
|
|
|
})
|
|
|
|
}
|
2021-06-08 11:33:56 +00:00
|
|
|
|
|
|
|
func TestResult_ToV2(t *testing.T) {
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
var x *audit.Result
|
|
|
|
|
|
|
|
require.Nil(t, x.ToV2())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewResultFromV2(t *testing.T) {
|
|
|
|
t.Run("from nil", func(t *testing.T) {
|
|
|
|
var x *auditv2.DataAuditResult
|
|
|
|
|
|
|
|
require.Nil(t, audit.NewResultFromV2(x))
|
|
|
|
})
|
|
|
|
}
|