[#302] pkg/audit: Document default values set in NewResult
Document field values of instance constructed via `NewResult`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
821e2951b6
commit
9fae0e4f2d
2 changed files with 55 additions and 0 deletions
|
@ -19,6 +19,17 @@ func NewResultFromV2(aV2 *audit.DataAuditResult) *Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates and initializes blank Result.
|
// New creates and initializes blank Result.
|
||||||
|
//
|
||||||
|
// Defaults:
|
||||||
|
// - version: pkg.SDKVersion();
|
||||||
|
// - complete: false;
|
||||||
|
// - cid: nil;
|
||||||
|
// - pubKey: nil;
|
||||||
|
// - passSG, failSG: nil;
|
||||||
|
// - failNodes, passNodes: nil;
|
||||||
|
// - hit, miss, fail: 0;
|
||||||
|
// - requests, retries: 0;
|
||||||
|
// - auditEpoch: 0.
|
||||||
func NewResult() *Result {
|
func NewResult() *Result {
|
||||||
r := NewResultFromV2(new(audit.DataAuditResult))
|
r := NewResultFromV2(new(audit.DataAuditResult))
|
||||||
r.SetVersion(pkg.SDKVersion())
|
r.SetVersion(pkg.SDKVersion())
|
||||||
|
|
|
@ -99,6 +99,50 @@ func TestResult_ToV2(t *testing.T) {
|
||||||
|
|
||||||
require.Nil(t, x.ToV2())
|
require.Nil(t, x.ToV2())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("default values", func(t *testing.T) {
|
||||||
|
result := audit.NewResult()
|
||||||
|
|
||||||
|
// check initial values
|
||||||
|
require.Equal(t, pkg.SDKVersion(), result.Version())
|
||||||
|
|
||||||
|
require.False(t, result.Complete())
|
||||||
|
|
||||||
|
require.Nil(t, result.ContainerID())
|
||||||
|
require.Nil(t, result.PublicKey())
|
||||||
|
require.Nil(t, result.PassSG())
|
||||||
|
require.Nil(t, result.FailSG())
|
||||||
|
require.Nil(t, result.PassNodes())
|
||||||
|
require.Nil(t, result.FailNodes())
|
||||||
|
|
||||||
|
require.Zero(t, result.Hit())
|
||||||
|
require.Zero(t, result.Miss())
|
||||||
|
require.Zero(t, result.Fail())
|
||||||
|
require.Zero(t, result.Requests())
|
||||||
|
require.Zero(t, result.Retries())
|
||||||
|
require.Zero(t, result.AuditEpoch())
|
||||||
|
|
||||||
|
// convert to v2 message
|
||||||
|
resultV2 := result.ToV2()
|
||||||
|
|
||||||
|
require.Equal(t, pkg.SDKVersion().ToV2(), resultV2.GetVersion())
|
||||||
|
|
||||||
|
require.False(t, resultV2.GetComplete())
|
||||||
|
|
||||||
|
require.Nil(t, resultV2.GetContainerID())
|
||||||
|
require.Nil(t, resultV2.GetPublicKey())
|
||||||
|
require.Nil(t, resultV2.GetPassSG())
|
||||||
|
require.Nil(t, resultV2.GetFailSG())
|
||||||
|
require.Nil(t, resultV2.GetPassNodes())
|
||||||
|
require.Nil(t, resultV2.GetFailNodes())
|
||||||
|
|
||||||
|
require.Zero(t, resultV2.GetHit())
|
||||||
|
require.Zero(t, resultV2.GetMiss())
|
||||||
|
require.Zero(t, resultV2.GetFail())
|
||||||
|
require.Zero(t, resultV2.GetRequests())
|
||||||
|
require.Zero(t, resultV2.GetRetries())
|
||||||
|
require.Zero(t, resultV2.GetAuditEpoch())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewResultFromV2(t *testing.T) {
|
func TestNewResultFromV2(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue