Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes/improvements for tests and paths to prepare migration #788

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmds/ocm/commands/misccmds/hash/sign/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package maven_test

import (
"crypto"

"github.com/open-component-model/ocm/pkg/maven/maventest"

. "github.com/mandelsoft/goutils/testutils"
Expand Down Expand Up @@ -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",
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/tour/04-working-with-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
11 changes: 8 additions & 3 deletions pkg/blobaccess/maven/access_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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() {
Expand Down
25 changes: 13 additions & 12 deletions pkg/contexts/ocm/accessmethods/maven/method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/contexts/ocm/accessmethods/ociartifact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/contexts/ocm/accessmethods/relativeociref/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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

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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/contexts/ocm/repositories/ctf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion pkg/contexts/ocm/repositories/ocireg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
4 changes: 2 additions & 2 deletions pkg/contexts/ocm/signing/signing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
})

Expand Down
13 changes: 13 additions & 0 deletions pkg/contexts/ocm/signing/signingtest/testdata.go
Original file line number Diff line number Diff line change
@@ -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...)
}
8 changes: 8 additions & 0 deletions pkg/maven/maventest/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package maventest

const (
ARTIFACT_SIZE = 1504
ARTIFACT_DIGEST = "dc5b38b58fd18cb0336c2e0deebeb5d2277c34312ae7024074812f34acfebc65" //nolint: gosec // yes
)

const POM_SHA1 = "SHA-1:34ccdeb9c008f8aaef90873fc636b09d3ae5c709"
4 changes: 4 additions & 0 deletions pkg/maven/maventest/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
53d97f5667e8890507e1a45b08bc0ceddefc6eed
7952c62446009a98176eeac7b815cddda5a13fa4
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
53d97f5667e8890507e1a45b08bc0ceddefc6eed
7952c62446009a98176eeac7b815cddda5a13fa4
Loading