Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Nov 11, 2024
1 parent 6041f62 commit 3fd5b47
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
30 changes: 29 additions & 1 deletion cmds/ocm/commands/ocmcmds/components/add/cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package add_test

import (
"github.com/mandelsoft/goutils/general"
. "github.com/mandelsoft/goutils/testutils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -35,7 +36,7 @@ const (
OUT = "/tmp/res"
)

func CheckComponent(env *TestEnv, handler func(ocm.Repository)) {
func CheckComponent(env *TestEnv, handler func(ocm.Repository), tests ...func(cv ocm.ComponentVersionAccess)) {
repo := Must(ctf.Open(env.OCMContext(), accessobj.ACC_READONLY, ARCH, 0, env))
defer Close(repo)
cv := Must(repo.LookupComponentVersion("ocm.software/demo/test", "1.0.0"))
Expand Down Expand Up @@ -73,6 +74,10 @@ func CheckComponent(env *TestEnv, handler func(ocm.Repository)) {
if handler != nil {
handler(repo)
}

for _, t := range tests {
t(cv)
}
}

var _ = Describe("Test Environment", func() {
Expand Down Expand Up @@ -104,6 +109,17 @@ var _ = Describe("Test Environment", func() {
CheckComponent(env, nil)
})

It("creates ctf and adds components without digests", func() {
Expect(env.Execute("add", "c", "--skip-digest-generation", "-fc", "--file", ARCH, "--version", "1.0.0", "testdata/component-constructor.yaml")).To(Succeed())
Expect(env.DirExists(ARCH)).To(BeTrue())
CheckComponent(env, nil, noDigest("data"), noDigest("text"))
})
It("creates ctf and adds components without digest for one resource", func() {
Expect(env.Execute("add", "c", "-fc", "--file", ARCH, "--version", "1.0.0", "testdata/component-constructor-skip.yaml")).To(Succeed())
Expect(env.DirExists(ARCH)).To(BeTrue())
CheckComponent(env, nil, noDigest("data", false), noDigest("text"))
})

Context("failures", func() {
It("rejects adding duplicate components", func() {
ExpectError(env.Execute("add", "c", "-fc", "--file", ARCH, "--version", "1.0.0", "testdata/components-dup.yaml")).To(
Expand Down Expand Up @@ -176,3 +192,15 @@ var _ = Describe("Test Environment", func() {
})
})
})

func noDigest(name string, skips ...bool) func(cv ocm.ComponentVersionAccess) {
skip := general.OptionalDefaultedBool(true, skips...)
return func(cv ocm.ComponentVersionAccess) {
r := MustWithOffset(1, Calling(cv.GetResource(metav1.Identity{"name": name})))
if skip {
ExpectWithOffset(1, r.Meta().Digest).To(BeNil())
} else {
ExpectWithOffset(1, r.Meta().Digest).NotTo(BeNil())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: ocm.software/demo/test
version: 1.0.0
provider:
name: ocm.software
labels:
- name: city
value: Karlsruhe
labels:
- name: purpose
value: test

resources:
- name: text
type: PlainText
skipDigestGeneration: true
labels:
- name: city
value: Karlsruhe
merge:
algorithm: default
config:
overwrite: inbound
input:
type: file
path: testdata
- name: data
type: PlainText
input:
type: binary
data: IXN0cmluZ2RhdGE=

references:
- name: ref
version: v1
componentName: github.com/mandelsoft/test2
9 changes: 1 addition & 8 deletions docs/reference/ocm_add_componentversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ componentversions, componentversion, cv, components, component, comps, comp, c
--lookup stringArray repository name or spec for closure lookup fallback
-O, --output string output file for dry-run
-R, --replace replace existing elements
-S, --scheme string schema version (default "v2")
-s, --settings stringArray settings file with variable settings (yaml)
--skip-digest-generation skip digest creation
--templater string templater to use (go, none, spiff, subst) (default "subst")
-t, --type string archive format (directory, tar, tgz) (default "directory")
--uploader <name>=<value> repository uploader (<name>[:<artifact type>[:<media type>[:<priority>]]]=<JSON target config>) (default [])
Expand Down Expand Up @@ -85,13 +85,6 @@ archive does not exist yet. The following formats are supported:
The default format is <code>directory</code>.


If the option <code>--scheme</code> is given, the specified component descriptor format is used/generated.

The following schema versions are supported for explicit conversions:
- <code>ocm.software/v3alpha1</code>
- <code>v2</code> (default)


All yaml/json defined resources can be templated.
Variables are specified as regular arguments following the syntax <code>&lt;name>=&lt;value></code>.
Additionally settings can be specified by a yaml file using the <code>--settings <file></code>
Expand Down

0 comments on commit 3fd5b47

Please sign in to comment.