Skip to content

Commit

Permalink
container: add version getter
Browse files Browse the repository at this point in the history
This field is a part of the container structure and this field can be
useful if for whatever reason we change the container structure. It's also
useful for the REST gateway that returns this data to users.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
  • Loading branch information
roman-khimov committed Apr 23, 2024
1 parent 9e74258 commit 611ba44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,10 @@ func (x Container) AssertID(id cid.ID) bool {

return id2.Equals(id)
}

// Version returns the NeoFS API version this container was created with.
func (x Container) Version() version.Version {
var v version.Version
_ = v.ReadFromV2(*x.v2.GetVersion()) // No, this can't fail for x.
return v
}
4 changes: 3 additions & 1 deletion container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func TestContainer_Init(t *testing.T) {

val.Init()

var ver = val.Version()
require.Equal(t, version.Current(), ver)

var msg v2container.Container
val.WriteToV2(&msg)

Expand All @@ -60,7 +63,6 @@ func TestContainer_Init(t *testing.T) {
verV2 := msg.GetVersion()
require.NotNil(t, verV2)

var ver version.Version
require.NoError(t, ver.ReadFromV2(*verV2))

require.Equal(t, version.Current(), ver)
Expand Down

0 comments on commit 611ba44

Please sign in to comment.