From a86583cfaff61d2cc54687fe957c32a1611f5bf2 Mon Sep 17 00:00:00 2001 From: Hilmar Falkenberg Date: Wed, 29 May 2024 15:26:59 +0200 Subject: [PATCH] various fixes/improvements for tests and paths to prepare migration --- .../commands/misccmds/hash/sign/cmd_test.go | 3 ++- .../common/inputs/types/maven/input_test.go | 5 ++-- .../lib/tour/04-working-with-config/README.md | 2 +- .../docsrc/04-working-with-config/README.md | 2 +- pkg/blobaccess/maven/access_test.go | 11 +++++--- .../ocm/accessmethods/maven/method_test.go | 25 +++++++++--------- .../ocm/accessmethods/ociartifact/README.md | 2 +- .../accessmethods/relativeociref/README.md | 4 +-- pkg/contexts/ocm/repositories/ctf/README.md | 2 +- .../ocm/repositories/ocireg/README.md | 2 +- pkg/contexts/ocm/signing/signing_test.go | 4 +-- .../ocm/signing/signingtest/testdata.go | 13 +++++++++ ...425f502dd6518e40eaa3ac7d24023d4c73d55dc12e | 0 .../component-descriptor.yaml | 0 .../testdata/compat/rsa.priv | 0 .../{ => signingtest}/testdata/compat/rsa.pub | 0 pkg/maven/maventest/const.go | 8 ++++++ pkg/maven/maventest/testdata.go | 4 +++ .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 595 -> 424 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 2 +- .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 595 -> 424 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 2 +- 22 files changed, 62 insertions(+), 29 deletions(-) create mode 100644 pkg/contexts/ocm/signing/signingtest/testdata.go rename pkg/contexts/ocm/signing/{ => signingtest}/testdata/compat/component-archive/blobs/sha256.c893900c1106f13d55648a425f502dd6518e40eaa3ac7d24023d4c73d55dc12e (100%) rename pkg/contexts/ocm/signing/{ => signingtest}/testdata/compat/component-archive/component-descriptor.yaml (100%) rename pkg/contexts/ocm/signing/{ => signingtest}/testdata/compat/rsa.priv (100%) rename pkg/contexts/ocm/signing/{ => signingtest}/testdata/compat/rsa.pub (100%) create mode 100644 pkg/maven/maventest/const.go diff --git a/cmds/ocm/commands/misccmds/hash/sign/cmd_test.go b/cmds/ocm/commands/misccmds/hash/sign/cmd_test.go index 0c542f75ab..faf7dd8bfc 100644 --- a/cmds/ocm/commands/misccmds/hash/sign/cmd_test.go +++ b/cmds/ocm/commands/misccmds/hash/sign/cmd_test.go @@ -6,6 +6,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/open-component-model/ocm/cmds/ocm/testhelper" + "github.com/open-component-model/ocm/pkg/contexts/ocm/signing/signingtest" . "github.com/open-component-model/ocm/pkg/testutils" ) @@ -15,7 +16,7 @@ var _ = Describe("Test Environment", func() { var env *TestEnv BeforeEach(func() { - env = NewTestEnv(TestData("../../../../../../pkg/contexts/ocm/signing/testdata")) + env = NewTestEnv(signingtest.TestData()) }) AfterEach(func() { diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go index 7731e45ac5..ea833e53e8 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go @@ -2,6 +2,7 @@ package maven_test import ( "crypto" + "github.com/open-component-model/ocm/pkg/maven/maventest" . "github.com/mandelsoft/goutils/testutils" @@ -44,7 +45,7 @@ var _ = Describe("Test Environment", func() { access := Must(env.Context.OCMContext().AccessSpecForSpec(cd.Resources[0].Access)).(*localblob.AccessSpec) Expect(access.MediaType).To(Equal(mime.MIME_TGZ)) fi := Must(env.FileSystem().Stat(env.Join(ARCH, "blobs", access.LocalReference))) - Expect(fi.Size()).To(Equal(int64(1570))) + Expect(fi.Size()).To(Equal(int64(maventest.ARTIFACT_SIZE))) li := Must(tarutils.ListArchiveContent(env.Join(ARCH, "blobs", access.LocalReference), env.FileSystem())) Expect(li).To(ConsistOf( "sdk-modules-bom-5.7.0-random-content.json", @@ -53,7 +54,7 @@ var _ = Describe("Test Environment", func() { "sdk-modules-bom-5.7.0.jar", "sdk-modules-bom-5.7.0.pom")) Expect(cd.Resources[0].Digest.HashAlgorithm).To(Equal(crypto.SHA256.String())) - Expect(cd.Resources[0].Digest.Value).To(Equal("16cfb5ced0ea7688dba14aeb0d3aa76ad46e4661bfcc556ffd7287de3b2f7152")) + Expect(cd.Resources[0].Digest.Value).To(Equal(maventest.ARTIFACT_DIGEST)) }) It("add maven from file system described by cli options", func() { diff --git a/examples/lib/tour/04-working-with-config/README.md b/examples/lib/tour/04-working-with-config/README.md index 2b156dc19a..0ec8a67c0c 100644 --- a/examples/lib/tour/04-working-with-config/README.md +++ b/examples/lib/tour/04-working-with-config/README.md @@ -115,7 +115,7 @@ settings for the given object and calls the appropriate methods on this object (after a type cast). Here is the code snippet from the apply method of the credential -config object ([.../pkg/contexts/credentials/config/type.go](../../../../../pkg/contexts/credentials/config/type.go)): +config object ([.../pkg/contexts/credentials/config/type.go](../../../../pkg/contexts/credentials/config/type.go)): ```go diff --git a/examples/lib/tour/docsrc/04-working-with-config/README.md b/examples/lib/tour/docsrc/04-working-with-config/README.md index 74572d52bb..bd0cf2a5bd 100644 --- a/examples/lib/tour/docsrc/04-working-with-config/README.md +++ b/examples/lib/tour/docsrc/04-working-with-config/README.md @@ -90,7 +90,7 @@ settings for the given object and calls the appropriate methods on this object (after a type cast). Here is the code snippet from the apply method of the credential -config object ([.../pkg/contexts/credentials/config/type.go](../../../../../pkg/contexts/credentials/config/type.go)): +config object ([.../pkg/contexts/credentials/config/type.go](../../../../pkg/contexts/credentials/config/type.go)): ```go {{include}{../../../../../pkg/contexts/credentials/config/type.go}{apply}} diff --git a/pkg/blobaccess/maven/access_test.go b/pkg/blobaccess/maven/access_test.go index e2e10c96df..de275eae53 100644 --- a/pkg/blobaccess/maven/access_test.go +++ b/pkg/blobaccess/maven/access_test.go @@ -1,9 +1,10 @@ package maven_test import ( - "github.com/open-component-model/ocm/pkg/maven/maventest" "time" + "github.com/open-component-model/ocm/pkg/maven/maventest" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/open-component-model/ocm/pkg/env/builder" @@ -45,8 +46,12 @@ var _ = Describe("blobaccess for maven", func() { b := Must(me.BlobAccessForMaven(repo, coords.GroupId, coords.ArtifactId, coords.Version, me.WithCachingFileSystem(env.FileSystem()))) defer Close(b, "blobaccess") files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) - Expect(files).To(ConsistOf("sdk-modules-bom-5.7.0.pom", "sdk-modules-bom-5.7.0.jar", "sdk-modules-bom-5.7.0-random-content.txt", - "sdk-modules-bom-5.7.0-random-content.json", "sdk-modules-bom-5.7.0-sources.jar")) + Expect(files).To(ConsistOf( + "sdk-modules-bom-5.7.0.pom", + "sdk-modules-bom-5.7.0.jar", + "sdk-modules-bom-5.7.0-random-content.txt", + "sdk-modules-bom-5.7.0-random-content.json", + "sdk-modules-bom-5.7.0-sources.jar")) }) It("blobaccess for files with the same classifier", func() { diff --git a/pkg/contexts/ocm/accessmethods/maven/method_test.go b/pkg/contexts/ocm/accessmethods/maven/method_test.go index 20310c92d0..bfd7a43103 100644 --- a/pkg/contexts/ocm/accessmethods/maven/method_test.go +++ b/pkg/contexts/ocm/accessmethods/maven/method_test.go @@ -2,9 +2,10 @@ package maven_test import ( "crypto" - "github.com/open-component-model/ocm/pkg/maven/maventest" "time" + "github.com/open-component-model/ocm/pkg/maven/maventest" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/open-component-model/ocm/pkg/env/builder" @@ -48,16 +49,16 @@ var _ = Describe("local accessmethods.maven.AccessSpec tests", func() { Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) r := Must(m.Reader()) defer Close(r) - dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) - for { - var buf [8096]byte - _, err := dr.Read(buf[:]) - if err != nil { - break - } - } - Expect(dr.Size()).To(Equal(int64(1570))) - Expect(dr.Digest().String()).To(Equal("SHA-1:359d02795bcc737e81c7f2f0ac32f49351d41867")) + dr := iotools.NewDigestReaderWithHash(crypto.SHA256, r) + li := Must(tarutils.ListArchiveContentFromReader(dr)) + Expect(li).To(ConsistOf( + "sdk-modules-bom-5.7.0-random-content.json", + "sdk-modules-bom-5.7.0-random-content.txt", + "sdk-modules-bom-5.7.0-sources.jar", + "sdk-modules-bom-5.7.0.jar", + "sdk-modules-bom-5.7.0.pom")) + Expect(dr.Size()).To(Equal(int64(maventest.ARTIFACT_SIZE))) + Expect(dr.Digest().String()).To(Equal("SHA-256:" + maventest.ARTIFACT_DIGEST)) }) It("accesses local artifact with empty classifier and with extension", func() { @@ -78,7 +79,7 @@ var _ = Describe("local accessmethods.maven.AccessSpec tests", func() { } Expect(dr.Size()).To(Equal(int64(7153))) - Expect(dr.Digest().String()).To(Equal("SHA-1:34ccdeb9c008f8aaef90873fc636b09d3ae5c709")) + Expect(dr.Digest().String()).To(Equal(maventest.POM_SHA1)) }) It("accesses local artifact with extension", func() { diff --git a/pkg/contexts/ocm/accessmethods/ociartifact/README.md b/pkg/contexts/ocm/accessmethods/ociartifact/README.md index fa818f6525..5b3b14b547 100644 --- a/pkg/contexts/ocm/accessmethods/ociartifact/README.md +++ b/pkg/contexts/ocm/accessmethods/ociartifact/README.md @@ -15,7 +15,7 @@ Provided blobs use the following media type: Depending on the repository appropriate docker legacy types might be used. -The artifact content is provided in the [Artifact Set Format](../../../oci/repositories/ctf/README.md#artifact-set-archive-format). +The artifact content is provided in the [Artifact Set Format](../../../../../pkg/contexts/oci/repositories/ctf/formatspec.md#artifact-set-archive-format). The tag is provided as annotation. ### Description diff --git a/pkg/contexts/ocm/accessmethods/relativeociref/README.md b/pkg/contexts/ocm/accessmethods/relativeociref/README.md index c174d43a8e..a08466d4f5 100644 --- a/pkg/contexts/ocm/accessmethods/relativeociref/README.md +++ b/pkg/contexts/ocm/accessmethods/relativeociref/README.md @@ -15,7 +15,7 @@ Provided blobs use the following media type: Depending on the repository appropriate docker legacy types might be used. -The artifact content is provided in the [Artifact Set Format](../../../oci/repositories/ctf/formatspec.md#artifact-set-archive-format). +The artifact content is provided in the [Artifact Set Format](../../../../../pkg/contexts/oci/repositories/ctf/formatspec.md#artifact-set-archive-format). The tag is provided as annotation. ### Description @@ -23,7 +23,7 @@ The tag is provided as annotation. This method implements the access of an OCI artifact stored in an OCI registry, which is used to host the OCM repository the component version is retrieved from. -It works similar to the [`ociArtifact`](../ociartifact/README.md) access method, +It works similar to the [`ociArtifact`](../../../../../pkg/contexts/ocm/accessmethods/ociartifact/README.md) access method, but the used reference does not contain the OCI registry host, which is taken from the OCI registry used to host the component version containing the access specification. diff --git a/pkg/contexts/ocm/repositories/ctf/README.md b/pkg/contexts/ocm/repositories/ctf/README.md index 0907d9ae08..22bd5f73ed 100644 --- a/pkg/contexts/ocm/repositories/ctf/README.md +++ b/pkg/contexts/ocm/repositories/ctf/README.md @@ -34,4 +34,4 @@ The type specific specification fields are: ### Go Bindings -The Go binding can be found [here](../../../oci/repositories/ctf/type.go). +The Go binding can be found [here](../../../../../pkg/contexts/oci/repositories/ctf/type.go). diff --git a/pkg/contexts/ocm/repositories/ocireg/README.md b/pkg/contexts/ocm/repositories/ocireg/README.md index f832cbfe2a..e7df056359 100644 --- a/pkg/contexts/ocm/repositories/ocireg/README.md +++ b/pkg/contexts/ocm/repositories/ocireg/README.md @@ -40,4 +40,4 @@ The type specific specification fields are: ### Go Bindings -The Go binding can be found [here](../../../oci/repositories/ocireg/type.go). +The Go binding can be found [here](../../../../../pkg/contexts/oci/repositories/ocireg/type.go). diff --git a/pkg/contexts/ocm/signing/signing_test.go b/pkg/contexts/ocm/signing/signing_test.go index 4ec44fc1a7..1abe817506 100644 --- a/pkg/contexts/ocm/signing/signing_test.go +++ b/pkg/contexts/ocm/signing/signing_test.go @@ -10,6 +10,7 @@ import ( . "github.com/onsi/gomega" . "github.com/open-component-model/ocm/pkg/contexts/oci/testhelper" . "github.com/open-component-model/ocm/pkg/contexts/ocm/signing" + "github.com/open-component-model/ocm/pkg/contexts/ocm/signing/signingtest" . "github.com/open-component-model/ocm/pkg/contexts/ocm/testhelper" . "github.com/open-component-model/ocm/pkg/env/builder" . "github.com/open-component-model/ocm/pkg/testutils" @@ -29,7 +30,6 @@ import ( "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/composition" "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/ctf" "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" - tenv "github.com/open-component-model/ocm/pkg/env" "github.com/open-component-model/ocm/pkg/mime" "github.com/open-component-model/ocm/pkg/signing" "github.com/open-component-model/ocm/pkg/signing/handlers/rsa" @@ -59,7 +59,7 @@ var _ = Describe("access method", func() { var env *Builder BeforeEach(func() { - env = NewBuilder(tenv.ModifiableTestData()) + env = NewBuilder(signingtest.ModifiableTestData()) env.RSAKeyPair(SIGNATURE, SIGNATURE2) }) diff --git a/pkg/contexts/ocm/signing/signingtest/testdata.go b/pkg/contexts/ocm/signing/signingtest/testdata.go new file mode 100644 index 0000000000..ea51fa190b --- /dev/null +++ b/pkg/contexts/ocm/signing/signingtest/testdata.go @@ -0,0 +1,13 @@ +package signingtest + +import ( + "github.com/open-component-model/ocm/pkg/env" +) + +func TestData(dest ...string) env.Option { + return env.ProjectTestDataForCaller(dest...) +} + +func ModifiableTestData(dest ...string) env.Option { + return env.ModifiableProjectTestDataForCaller(dest...) +} diff --git a/pkg/contexts/ocm/signing/testdata/compat/component-archive/blobs/sha256.c893900c1106f13d55648a425f502dd6518e40eaa3ac7d24023d4c73d55dc12e b/pkg/contexts/ocm/signing/signingtest/testdata/compat/component-archive/blobs/sha256.c893900c1106f13d55648a425f502dd6518e40eaa3ac7d24023d4c73d55dc12e similarity index 100% rename from pkg/contexts/ocm/signing/testdata/compat/component-archive/blobs/sha256.c893900c1106f13d55648a425f502dd6518e40eaa3ac7d24023d4c73d55dc12e rename to pkg/contexts/ocm/signing/signingtest/testdata/compat/component-archive/blobs/sha256.c893900c1106f13d55648a425f502dd6518e40eaa3ac7d24023d4c73d55dc12e diff --git a/pkg/contexts/ocm/signing/testdata/compat/component-archive/component-descriptor.yaml b/pkg/contexts/ocm/signing/signingtest/testdata/compat/component-archive/component-descriptor.yaml similarity index 100% rename from pkg/contexts/ocm/signing/testdata/compat/component-archive/component-descriptor.yaml rename to pkg/contexts/ocm/signing/signingtest/testdata/compat/component-archive/component-descriptor.yaml diff --git a/pkg/contexts/ocm/signing/testdata/compat/rsa.priv b/pkg/contexts/ocm/signing/signingtest/testdata/compat/rsa.priv similarity index 100% rename from pkg/contexts/ocm/signing/testdata/compat/rsa.priv rename to pkg/contexts/ocm/signing/signingtest/testdata/compat/rsa.priv diff --git a/pkg/contexts/ocm/signing/testdata/compat/rsa.pub b/pkg/contexts/ocm/signing/signingtest/testdata/compat/rsa.pub similarity index 100% rename from pkg/contexts/ocm/signing/testdata/compat/rsa.pub rename to pkg/contexts/ocm/signing/signingtest/testdata/compat/rsa.pub diff --git a/pkg/maven/maventest/const.go b/pkg/maven/maventest/const.go new file mode 100644 index 0000000000..1e80a4db00 --- /dev/null +++ b/pkg/maven/maventest/const.go @@ -0,0 +1,8 @@ +package maventest + +const ( + ARTIFACT_SIZE = 1504 + ARTIFACT_DIGEST = "dc5b38b58fd18cb0336c2e0deebeb5d2277c34312ae7024074812f34acfebc65" //nolint: gosec // yes +) + +const POM_SHA1 = "SHA-1:34ccdeb9c008f8aaef90873fc636b09d3ae5c709" diff --git a/pkg/maven/maventest/testdata.go b/pkg/maven/maventest/testdata.go index 64f0c103e8..efd26ff62a 100644 --- a/pkg/maven/maventest/testdata.go +++ b/pkg/maven/maventest/testdata.go @@ -7,3 +7,7 @@ import ( func TestData(dest ...string) env.Option { return env.ProjectTestDataForCaller(dest...) } + +func ModifiableTestData(dest ...string) env.Option { + return env.ModifiableProjectTestDataForCaller(dest...) +} diff --git a/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar index 8564f0addae8de5525417df8294d13c0c2a3a7c0..1d5cd83128edaf5e6980edcf4344fc8e1701b0a1 100644 GIT binary patch literal 424 zcmWIWW@Zs#;Nak3V2L>t!GHuf8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1g=~? literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lot!GHuf8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1g=~? literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo