diff --git a/pkg/container/container.go b/pkg/container/container.go index 264bab02..24ed218d 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -44,7 +44,14 @@ func New(opts ...NewOption) *Container { return cnr } +// ToV2 returns the v2 Container message. +// +// Nil Container converts to nil. func (c *Container) ToV2() *container.Container { + if c == nil { + return nil + } + return &c.v2 } diff --git a/pkg/container/container_test.go b/pkg/container/container_test.go index 1456b0ec..1a1bce39 100644 --- a/pkg/container/container_test.go +++ b/pkg/container/container_test.go @@ -91,3 +91,11 @@ func TestContainer_Signature(t *testing.T) { require.Equal(t, sig, cnr.Signature()) } + +func TestContainer_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *container.Container + + require.Nil(t, x.ToV2()) + }) +}