generated from open-component-model/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add support for OCI repository pattern for add component version #628
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
Draft
Skarlso
wants to merge
10
commits into
open-component-model:main
Choose a base branch
from
Skarlso:support-oci-repositories
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
90cfbdb
feat: add support for OCI repository pattern for add component version
Skarlso c90ee87
use the actual type after repository scheme
Skarlso 5888070
add test coverage for GetRepositorySpec
Skarlso eef8173
the beginnings of a refactor to not duplicate logic over reference pa…
Skarlso b865ec5
shifted the tests into compdesc
Skarlso 65856ca
add integration test for add component version
Skarlso 1be2778
add scheme to the repository spec for credentials to work
Skarlso 476c932
tests are now passing I believe
Skarlso ecb5e75
using proper TestMain for a setup sequence
Skarlso a7c9ab2
removed unused credential start registry helper
Skarlso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
cli/integration/add_component_version_integration_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"ocm.software/open-component-model/cli/cmd" | ||
) | ||
|
||
func Test_Integration_AddComponentVersion_OCIRepository(t *testing.T) { | ||
Skarlso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
suite := SetupTestSuite(t) | ||
|
||
t.Run("add component-version with plain OCI registry reference", func(t *testing.T) { | ||
r := require.New(t) | ||
|
||
componentName := "ocm.software/test-component" | ||
componentVersion := "v1.0.0" | ||
|
||
// Create constructor file using suite helper | ||
constructorPath := suite.CreateComponentConstructor(t, componentName, componentVersion) | ||
|
||
// Test the add component-version command with plain OCI registry reference | ||
addCMD := cmd.New() | ||
addCMD.SetArgs([]string{ | ||
"add", | ||
"component-version", | ||
"--repository", suite.GetRepositoryURL(), | ||
"--constructor", constructorPath, | ||
"--config", suite.ConfigPath, | ||
}) | ||
|
||
r.NoError(addCMD.ExecuteContext(t.Context()), "add component-version should succeed with OCI registry") | ||
|
||
// Verify the component version was added by attempting to retrieve it | ||
desc, err := suite.Repository.GetComponentVersion(t.Context(), componentName, componentVersion) | ||
r.NoError(err, "should be able to retrieve the added component version") | ||
r.Equal(componentName, desc.Component.Name) | ||
r.Equal(componentVersion, desc.Component.Version) | ||
r.Equal("ocm.software", desc.Component.Provider.Name) | ||
r.Len(desc.Component.Resources, 1) | ||
r.Equal("test-resource", desc.Component.Resources[0].Name) | ||
r.Equal(componentVersion, desc.Component.Resources[0].Version) | ||
}) | ||
|
||
t.Run("add component-version with explicit OCI type prefix", func(t *testing.T) { | ||
r := require.New(t) | ||
|
||
componentName := "ocm.software/explicit-oci-component" | ||
componentVersion := "v2.0.0" | ||
|
||
// Create constructor file using suite helper | ||
constructorPath := suite.CreateComponentConstructor(t, componentName, componentVersion) | ||
|
||
// Test with explicit oci:: prefix | ||
addCMD := cmd.New() | ||
addCMD.SetArgs([]string{ | ||
"add", | ||
"component-version", | ||
"--repository", suite.GetRepositoryURLWithPrefix("oci"), | ||
"--constructor", constructorPath, | ||
"--config", suite.ConfigPath, | ||
}) | ||
|
||
r.NoError(addCMD.ExecuteContext(t.Context()), "add component-version should succeed with explicit OCI type") | ||
|
||
// Verify the component version was added | ||
desc, err := suite.Repository.GetComponentVersion(t.Context(), componentName, componentVersion) | ||
r.NoError(err, "should be able to retrieve the component version added with explicit OCI type") | ||
r.Equal(componentName, desc.Component.Name) | ||
r.Equal(componentVersion, desc.Component.Version) | ||
}) | ||
|
||
t.Run("add component-version with HTTP URL format", func(t *testing.T) { | ||
r := require.New(t) | ||
|
||
componentName := "ocm.software/http-component" | ||
componentVersion := "v3.0.0" | ||
|
||
// Create constructor file using suite helper | ||
constructorPath := suite.CreateComponentConstructor(t, componentName, componentVersion) | ||
|
||
// Test with HTTP URL format | ||
addCMD := cmd.New() | ||
addCMD.SetArgs([]string{ | ||
"add", | ||
"component-version", | ||
"--repository", suite.GetRepositoryURL(), | ||
"--constructor", constructorPath, | ||
"--config", suite.ConfigPath, | ||
}) | ||
|
||
r.NoError(addCMD.ExecuteContext(t.Context()), "add component-version should succeed with HTTP URL format") | ||
|
||
// Verify the component version was added | ||
desc, err := suite.Repository.GetComponentVersion(t.Context(), componentName, componentVersion) | ||
r.NoError(err, "should be able to retrieve the component version added with HTTP URL") | ||
r.Equal(componentName, desc.Component.Name) | ||
r.Equal(componentVersion, desc.Component.Version) | ||
}) | ||
} | ||
|
||
func Test_Integration_AddComponentVersion_CTFRepository(t *testing.T) { | ||
t.Run("add component-version with CTF archive path", func(t *testing.T) { | ||
r := require.New(t) | ||
|
||
componentName := "ocm.software/ctf-component" | ||
componentVersion := "v1.0.0" | ||
|
||
// Create temporary test suite for this test (no shared registry needed for CTF) | ||
suite := &TestSuite{} | ||
constructorPath := suite.CreateComponentConstructor(t, componentName, componentVersion) | ||
|
||
// Test with CTF archive path | ||
ctfArchivePath := filepath.Join(t.TempDir(), "test-archive") | ||
addCMD := cmd.New() | ||
addCMD.SetArgs([]string{ | ||
"add", | ||
"component-version", | ||
"--repository", ctfArchivePath, | ||
"--constructor", constructorPath, | ||
}) | ||
|
||
r.NoError(addCMD.ExecuteContext(t.Context()), "add component-version should succeed with CTF archive") | ||
|
||
// Verify the archive was created | ||
_, err := os.Stat(ctfArchivePath) | ||
r.NoError(err, "CTF archive should be created") | ||
}) | ||
|
||
t.Run("add component-version with explicit CTF type prefix", func(t *testing.T) { | ||
r := require.New(t) | ||
|
||
componentName := "ocm.software/explicit-ctf-component" | ||
componentVersion := "v2.0.0" | ||
|
||
// Create temporary test suite for this test (no shared registry needed for CTF) | ||
suite := &TestSuite{} | ||
constructorPath := suite.CreateComponentConstructor(t, componentName, componentVersion) | ||
|
||
// Test with explicit ctf:: prefix | ||
ctfArchivePath := filepath.Join(t.TempDir(), "explicit-archive") | ||
addCMD := cmd.New() | ||
addCMD.SetArgs([]string{ | ||
"add", | ||
"component-version", | ||
"--repository", fmt.Sprintf("ctf::%s", ctfArchivePath), | ||
"--constructor", constructorPath, | ||
}) | ||
|
||
r.NoError(addCMD.ExecuteContext(t.Context()), "add component-version should succeed with explicit CTF type") | ||
|
||
// Verify the archive was created | ||
_, err := os.Stat(ctfArchivePath) | ||
r.NoError(err, "CTF archive should be created with explicit type") | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not actually a
repository specification
, is it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a repository url I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can be sort a specification because it's no longer "just a path". What could we call this?