From 374c37983d1e06adcaa32934a5709779a9e50c1c Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 27 May 2021 14:36:45 +0300 Subject: [PATCH] [#288] pkg/eacl: Document default values set in NewRecord Document field values of instance constructed via `NewRecord`. Assert the values in corresponding unit test. Signed-off-by: Leonard Lyubich --- pkg/acl/eacl/record.go | 6 ++++++ pkg/acl/eacl/record_test.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/acl/eacl/record.go b/pkg/acl/eacl/record.go index 2e0d255c..e8430d14 100644 --- a/pkg/acl/eacl/record.go +++ b/pkg/acl/eacl/record.go @@ -156,6 +156,12 @@ func (r *Record) ToV2() *v2acl.Record { } // NewRecord creates and returns blank Record instance. +// +// Defaults: +// - action: ActionUnknown; +// - operation: OperationUnknown; +// - targets: nil, +// - filters: nil. func NewRecord() *Record { return new(Record) } diff --git a/pkg/acl/eacl/record_test.go b/pkg/acl/eacl/record_test.go index 25608bed..7ed59dd0 100644 --- a/pkg/acl/eacl/record_test.go +++ b/pkg/acl/eacl/record_test.go @@ -126,4 +126,22 @@ func TestRecord_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) + + t.Run("default values", func(t *testing.T) { + record := NewRecord() + + // check initial values + require.Equal(t, OperationUnknown, record.Operation()) + require.Equal(t, ActionUnknown, record.Action()) + require.Nil(t, record.Targets()) + require.Nil(t, record.Filters()) + + // convert to v2 message + recordV2 := record.ToV2() + + require.Equal(t, v2acl.OperationUnknown, recordV2.GetOperation()) + require.Equal(t, v2acl.ActionUnknown, recordV2.GetAction()) + require.Nil(t, recordV2.GetTargets()) + require.Nil(t, recordV2.GetFilters()) + }) }