From 2b764a25cd40394ce84e5ae67c7fa4448ae5926b Mon Sep 17 00:00:00 2001 From: Hilmar Falkenberg Date: Tue, 14 Jan 2025 10:33:47 +0100 Subject: [PATCH 1/2] chore(format): executed make format on EVERYTHING (incl. tests) (#1252) everytime, I'm executing `make format`, those files get changed, even when they have nothing to do with the actual feature --- api/oci/ociutils/ref_test.go | 2 ++ api/ocm/extensions/accessmethods/git/method_test.go | 2 +- .../repositories/genericocireg/config_test.go | 5 +++-- .../transfer/transferhandler/standard/compat_test.go | 9 +++++---- api/tech/git/identity/identity_test.go | 3 ++- api/tech/git/resolver_test.go | 8 ++++---- api/utils/blobaccess/git/access_test.go | 11 ++++++----- api/utils/logging/roundtripper_test.go | 4 ++-- .../ocmcmds/common/inputs/types/git/input_test.go | 3 +-- cmds/ocm/commands/ocmcmds/components/add/cmd_test.go | 3 ++- cmds/ocm/commands/ocmcmds/components/hash/cmd_test.go | 1 - cmds/ocm/commands/ocmcmds/components/sign/cmd_test.go | 3 +-- examples/lib/tour/07-resource-management/example.go | 5 +++-- 13 files changed, 32 insertions(+), 27 deletions(-) diff --git a/api/oci/ociutils/ref_test.go b/api/oci/ociutils/ref_test.go index 1e5075447a..4c5ada3d0e 100644 --- a/api/oci/ociutils/ref_test.go +++ b/api/oci/ociutils/ref_test.go @@ -4,7 +4,9 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/opencontainers/go-digest" + "ocm.software/ocm/api/oci/ociutils" "ocm.software/ocm/api/oci/testhelper" ) diff --git a/api/ocm/extensions/accessmethods/git/method_test.go b/api/ocm/extensions/accessmethods/git/method_test.go index 3a3ac663a4..f6d36194cf 100644 --- a/api/ocm/extensions/accessmethods/git/method_test.go +++ b/api/ocm/extensions/accessmethods/git/method_test.go @@ -12,12 +12,12 @@ import ( _ "embed" - "github.com/go-git/go-git/v5/plumbing" . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" "github.com/mandelsoft/filepath/pkg/filepath" "github.com/mandelsoft/vfs/pkg/cwdfs" diff --git a/api/ocm/extensions/repositories/genericocireg/config_test.go b/api/ocm/extensions/repositories/genericocireg/config_test.go index 2435497a81..ec298a25b1 100644 --- a/api/ocm/extensions/repositories/genericocireg/config_test.go +++ b/api/ocm/extensions/repositories/genericocireg/config_test.go @@ -6,17 +6,18 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "ocm.software/ocm/api/datacontext" - "ocm.software/ocm/api/ocm/extensions/repositories/genericocireg/config" "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" + + "ocm.software/ocm/api/datacontext" "ocm.software/ocm/api/oci" "ocm.software/ocm/api/oci/extensions/repositories/ctf" "ocm.software/ocm/api/ocm" "ocm.software/ocm/api/ocm/cpi/repocpi" "ocm.software/ocm/api/ocm/extensions/repositories/genericocireg" + "ocm.software/ocm/api/ocm/extensions/repositories/genericocireg/config" "ocm.software/ocm/api/utils/accessio" "ocm.software/ocm/api/utils/accessobj" ) diff --git a/api/ocm/tools/transfer/transferhandler/standard/compat_test.go b/api/ocm/tools/transfer/transferhandler/standard/compat_test.go index efb06e6d97..5e0db6b981 100644 --- a/api/ocm/tools/transfer/transferhandler/standard/compat_test.go +++ b/api/ocm/tools/transfer/transferhandler/standard/compat_test.go @@ -13,13 +13,14 @@ import ( common "ocm.software/ocm/api/utils/misc" ) -const COMPAT_ARCH = "/testdata/v0.18.0" -const COMPAT_COMP = "github.com/mandelsoft/test1" -const COMPAT_VERS = "1.0.0" +const ( + COMPAT_ARCH = "/testdata/v0.18.0" + COMPAT_COMP = "github.com/mandelsoft/test1" + COMPAT_VERS = "1.0.0" +) var _ = Describe("Transfer Test Environment", func() { Context("extraid compatibility transfer", func() { - var env *TestEnv BeforeEach(func() { diff --git a/api/tech/git/identity/identity_test.go b/api/tech/git/identity/identity_test.go index 13a95f4e2c..879f373f44 100644 --- a/api/tech/git/identity/identity_test.go +++ b/api/tech/git/identity/identity_test.go @@ -1,11 +1,12 @@ package identity_test import ( - "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "ocm.software/ocm/api/tech/git/identity" + "github.com/mandelsoft/goutils/testutils" + "ocm.software/ocm/api/credentials" "ocm.software/ocm/api/datacontext" "ocm.software/ocm/api/oci" diff --git a/api/tech/git/resolver_test.go b/api/tech/git/resolver_test.go index d128d07808..99f49d0e0d 100644 --- a/api/tech/git/resolver_test.go +++ b/api/tech/git/resolver_test.go @@ -7,16 +7,17 @@ import ( "os" "time" + . "github.com/mandelsoft/goutils/testutils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" "github.com/mandelsoft/filepath/pkg/filepath" - . "github.com/mandelsoft/goutils/testutils" "github.com/mandelsoft/vfs/pkg/cwdfs" "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/projectionfs" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" "ocm.software/ocm/api/datacontext/attrs/tmpcache" "ocm.software/ocm/api/datacontext/attrs/vfsattr" @@ -107,6 +108,5 @@ var _ = Describe("standard tests with local file repo", func() { file := Must(tempVFS.Stat("file_in_repo")) Expect(file.Size()).To(Equal(int64(len(expectedBlobContent)))) - }) }) diff --git a/api/utils/blobaccess/git/access_test.go b/api/utils/blobaccess/git/access_test.go index a35495a7aa..3f608e512c 100644 --- a/api/utils/blobaccess/git/access_test.go +++ b/api/utils/blobaccess/git/access_test.go @@ -2,21 +2,23 @@ package git_test import ( "embed" - _ "embed" "fmt" "io" "os" "time" + _ "embed" + + . "github.com/mandelsoft/goutils/testutils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" "github.com/mandelsoft/filepath/pkg/filepath" - . "github.com/mandelsoft/goutils/testutils" "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/projectionfs" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" "ocm.software/ocm/api/datacontext/attrs/tmpcache" "ocm.software/ocm/api/datacontext/attrs/vfsattr" @@ -100,7 +102,6 @@ var _ = Describe("git Blob Access", func() { files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) Expect(files).To(ConsistOf("file_in_repo")) }) - }) Context("git http repository", func() { diff --git a/api/utils/logging/roundtripper_test.go b/api/utils/logging/roundtripper_test.go index a7bdbf8a72..ec700ee651 100644 --- a/api/utils/logging/roundtripper_test.go +++ b/api/utils/logging/roundtripper_test.go @@ -5,12 +5,12 @@ import ( "net/http" "net/http/httptest" - logcfg "github.com/mandelsoft/logging/config" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/tonglil/buflogr" "github.com/mandelsoft/logging" + logcfg "github.com/mandelsoft/logging/config" + "github.com/tonglil/buflogr" local "ocm.software/ocm/api/utils/logging" ) diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/git/input_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/git/input_test.go index b664f261eb..459fbc8cf2 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/git/input_test.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/git/input_test.go @@ -7,12 +7,12 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + . "ocm.software/ocm/cmds/ocm/testhelper" "ocm.software/ocm/api/datacontext/attrs/vfsattr" "ocm.software/ocm/api/ocm" "ocm.software/ocm/api/ocm/extensions/repositories/ctf" "ocm.software/ocm/api/utils/accessio" - . "ocm.software/ocm/cmds/ocm/testhelper" ) const ( @@ -78,7 +78,6 @@ resources: }) It("add git repo described by cli options through blob access via input described in file", func() { - constructor := fmt.Sprintf(`--- name: test.de/x version: %s diff --git a/cmds/ocm/commands/ocmcmds/components/add/cmd_test.go b/cmds/ocm/commands/ocmcmds/components/add/cmd_test.go index df8269cda5..cf523b45e3 100644 --- a/cmds/ocm/commands/ocmcmds/components/add/cmd_test.go +++ b/cmds/ocm/commands/ocmcmds/components/add/cmd_test.go @@ -1,13 +1,14 @@ package add_test import ( - "github.com/mandelsoft/goutils/general" . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "ocm.software/ocm/api/oci/testhelper" . "ocm.software/ocm/cmds/ocm/testhelper" + "github.com/mandelsoft/goutils/general" + "ocm.software/ocm/api/oci" "ocm.software/ocm/api/oci/artdesc" "ocm.software/ocm/api/ocm" diff --git a/cmds/ocm/commands/ocmcmds/components/hash/cmd_test.go b/cmds/ocm/commands/ocmcmds/components/hash/cmd_test.go index 6f20c09d0c..a717b844b1 100644 --- a/cmds/ocm/commands/ocmcmds/components/hash/cmd_test.go +++ b/cmds/ocm/commands/ocmcmds/components/hash/cmd_test.go @@ -9,7 +9,6 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "ocm.software/ocm/cmds/ocm/testhelper" "ocm.software/ocm/api/ocm/compdesc" diff --git a/cmds/ocm/commands/ocmcmds/components/sign/cmd_test.go b/cmds/ocm/commands/ocmcmds/components/sign/cmd_test.go index 7991b3f843..26b7ba3f0d 100644 --- a/cmds/ocm/commands/ocmcmds/components/sign/cmd_test.go +++ b/cmds/ocm/commands/ocmcmds/components/sign/cmd_test.go @@ -7,9 +7,7 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "ocm.software/ocm/api/oci/testhelper" - "ocm.software/ocm/api/ocm/compdesc" . "ocm.software/ocm/api/ocm/testhelper" . "ocm.software/ocm/cmds/ocm/testhelper" @@ -17,6 +15,7 @@ import ( "ocm.software/ocm/api/datacontext" "ocm.software/ocm/api/oci" + "ocm.software/ocm/api/ocm/compdesc" metav1 "ocm.software/ocm/api/ocm/compdesc/meta/v1" "ocm.software/ocm/api/ocm/extensions/accessmethods/ociartifact" resourcetypes "ocm.software/ocm/api/ocm/extensions/artifacttypes" diff --git a/examples/lib/tour/07-resource-management/example.go b/examples/lib/tour/07-resource-management/example.go index cffd10c172..3bafa5898a 100644 --- a/examples/lib/tour/07-resource-management/example.go +++ b/examples/lib/tour/07-resource-management/example.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/mandelsoft/goutils/errors" + "ocm.software/ocm/api/ocm" metav1 "ocm.software/ocm/api/ocm/compdesc/meta/v1" "ocm.software/ocm/api/ocm/extensions/repositories/ocireg" @@ -80,8 +81,7 @@ func (r *resource) Close() error { // --- begin caching factory --- // CachingFactory provides resource inmplementations // using the original access as cache. -type CachingFactory struct { -} +type CachingFactory struct{} func (c CachingFactory) Create(id metav1.Identity, typ string) Resource { return &resource{ @@ -95,6 +95,7 @@ func (c CachingFactory) Create(id metav1.Identity, typ string) Resource { func (r *resource) GetIdentity() metav1.Identity { return r.Identity } + func (r *resource) GetType() string { return r.ArtifactType } From f0103a86a8c42a07a37a2ceb941c6397dee5caf2 Mon Sep 17 00:00:00 2001 From: Hilmar Falkenberg Date: Tue, 14 Jan 2025 14:13:07 +0100 Subject: [PATCH 2/2] fix: unable to close, unable to unref last: unable to cleanup component version, while unref last: closing component version (#1243) #### What this PR does / why we need it When calling ocm-cli with oci-tag-version like `0.0.1-20250108132333.build-af79499` e.g. ```bash ocm get cv ocm-oci-test.int.repositories.cloud.sap//docker.io/recmo/docker-hello-tiny:0.0.1-20250108132333.build-af79499 ``` It fails during the [finalize step](https://github.com/open-component-model/ocm/blob/releases/v0.19/api/utils/refmgmt/refcloser.go#L196), when [doing an update](https://github.com/open-component-model/ocm/blob/releases/v0.19/api/ocm/extensions/repositories/genericocireg/componentversion.go#L171), where [another round of version comparison](https://github.com/open-component-model/ocm/blob/releases/v0.19/api/ocm/extensions/repositories/genericocireg/componentversion.go#L99) happens. #### Which issue(s) this PR fixes Fixes: https://github.com/open-component-model/ocm/issues/1235 Related: https://github.com/open-component-model/ocm/pull/355 --- .../genericocireg/componentversion.go | 6 ++ .../genericocireg/componentversion_test.go | 85 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 api/ocm/extensions/repositories/genericocireg/componentversion_test.go diff --git a/api/ocm/extensions/repositories/genericocireg/componentversion.go b/api/ocm/extensions/repositories/genericocireg/componentversion.go index e0dd0f5470..950ff9018c 100644 --- a/api/ocm/extensions/repositories/genericocireg/componentversion.go +++ b/api/ocm/extensions/repositories/genericocireg/componentversion.go @@ -102,6 +102,12 @@ func (c *ComponentVersionContainer) SetReadOnly() { func (c *ComponentVersionContainer) Check() error { if c.version != c.GetDescriptor().Version { + // check if version contained '+' which has been replaced by META_SEPARATOR to create OCI compliant tag + if replaced, _ := toTag(c.GetDescriptor().Version); replaced != c.GetDescriptor().Version && replaced == c.version { + Logger(c.GetContext()).Warn(fmt.Sprintf( + "checked version %q contains %q, this is discouraged and you should prefer the original component version %q", c.version, META_SEPARATOR, c.GetDescriptor().Version)) + return nil + } return errors.ErrInvalid("component version", c.GetDescriptor().Version) } if c.comp.name != c.GetDescriptor().Name { diff --git a/api/ocm/extensions/repositories/genericocireg/componentversion_test.go b/api/ocm/extensions/repositories/genericocireg/componentversion_test.go new file mode 100644 index 0000000000..0b79d0b968 --- /dev/null +++ b/api/ocm/extensions/repositories/genericocireg/componentversion_test.go @@ -0,0 +1,85 @@ +package genericocireg + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "ocm.software/ocm/api/ocm/internal" + "ocm.software/ocm/api/utils/accessobj" +) + +func TestComponentVersionContainer_Check(t *testing.T) { + // Setup + state, err := accessobj.NewBlobStateForBlob(accessobj.ACC_READONLY, nil, NewStateHandler("mock.test.com/state_handler", "1.0.0")) + assert.NoError(t, err) + repo := &RepositoryImpl{ctx: internal.DefaultContext} + comp := &componentAccessImpl{repo: repo} + cvc := &ComponentVersionContainer{state: state, comp: comp} + + // Test cases + tests := []struct { + name string + setup func() + expectErr bool + }{ + { + name: "valid version and name", + setup: func() { + cvc.version = "1.0.0" + cvc.GetDescriptor().Version = "1.0.0" + cvc.comp.name = "test-component" + cvc.GetDescriptor().Name = "test-component" + }, + expectErr: false, + }, + { + name: "half valid version - containing META_SEPARATOR = " + META_SEPARATOR, + setup: func() { + cvc.version = "0.0.1-20250108132333.build-af79499" + cvc.GetDescriptor().Version = "0.0.1-20250108132333+af79499" + cvc.comp.name = "test-component" + cvc.GetDescriptor().Name = "test-component" + }, + expectErr: false, + }, + { + name: "valid version - containing '+'", + setup: func() { + cvc.version = "0.0.1-20250108132333+af79499" + cvc.GetDescriptor().Version = "0.0.1-20250108132333+af79499" + cvc.comp.name = "test-component" + cvc.GetDescriptor().Name = "test-component" + }, + expectErr: false, + }, + { + name: "invalid version", + setup: func() { + cvc.version = "1.0.0" + cvc.GetDescriptor().Version = "2.0.0" + }, + expectErr: true, + }, + { + name: "invalid name", + setup: func() { + cvc.comp.name = "test-component" + cvc.GetDescriptor().Name = "invalid-component" + }, + expectErr: true, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + test.setup() + err := cvc.Check() + if test.expectErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +}