-
Notifications
You must be signed in to change notification settings - Fork 2
Capability-based OCI image filtering #54
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
Merged
Merged
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package oci | ||
|
|
||
| import ( | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/cobaltcore-dev/cloud-profile-sync/api/v1alpha1" | ||
| ) | ||
|
|
||
| var _ = Describe("splitAnnotationRaw", func() { | ||
| It("returns empty map for empty string", func() { | ||
| Expect(splitAnnotationRaw("")).To(BeEmpty()) | ||
| }) | ||
|
|
||
| It("returns empty map for whitespace-only string", func() { | ||
| Expect(splitAnnotationRaw(" , , ")).To(BeEmpty()) | ||
| }) | ||
|
|
||
| It("preserves tokens including leading underscores", func() { | ||
| result := splitAnnotationRaw("scibase,_usi,vhost") | ||
| Expect(result).To(HaveKey("scibase")) | ||
| Expect(result).To(HaveKey("_usi")) | ||
| Expect(result).To(HaveKey("vhost")) | ||
| Expect(result).To(HaveLen(3)) | ||
| }) | ||
|
|
||
| It("trims whitespace around tokens", func() { | ||
| result := splitAnnotationRaw(" scibase , _usi ") | ||
| Expect(result).To(HaveKey("scibase")) | ||
| Expect(result).To(HaveKey("_usi")) | ||
| }) | ||
|
|
||
| It("deduplicates repeated tokens", func() { | ||
| result := splitAnnotationRaw("sci,sci,_usi") | ||
| Expect(result).To(HaveLen(2)) | ||
| Expect(result).To(HaveKey("sci")) | ||
| Expect(result).To(HaveKey("_usi")) | ||
| }) | ||
| }) | ||
|
|
||
| var _ = Describe("supportsInPlaceUpdate", func() { | ||
| It("returns false when feature_set annotation is absent", func() { | ||
| Expect(supportsInPlaceUpdate(map[string]string{"architecture": "amd64"})).To(BeFalse()) | ||
| }) | ||
|
|
||
| It("returns false when feature_set annotation is present but empty", func() { | ||
| Expect(supportsInPlaceUpdate(map[string]string{"architecture": "amd64", "feature_set": ""})).To(BeFalse()) | ||
| }) | ||
|
|
||
| It("returns false when _usi is absent from feature_set", func() { | ||
| Expect(supportsInPlaceUpdate(map[string]string{"feature_set": "scibase,vhost"})).To(BeFalse()) | ||
| }) | ||
|
|
||
| It("returns false when only the normalized form 'usi' is present (not '_usi')", func() { | ||
| Expect(supportsInPlaceUpdate(map[string]string{"feature_set": "scibase,usi"})).To(BeFalse()) | ||
| }) | ||
|
|
||
| It("returns true when _usi is present in feature_set", func() { | ||
| Expect(supportsInPlaceUpdate(map[string]string{"feature_set": "scibase,_usi,vhost"})).To(BeTrue()) | ||
| }) | ||
| }) | ||
|
|
||
| var _ = Describe("passesImageFilter", func() { | ||
| It("passes when filter is nil", func() { | ||
| Expect(passesImageFilter(map[string]struct{}{"sci": {}}, nil)).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("passes when RequiredFeatureSetValues is empty", func() { | ||
| filter := &v1alpha1.ImageFilter{} | ||
| Expect(passesImageFilter(map[string]struct{}{"sci": {}}, filter)).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("passes when all required values are present", func() { | ||
| filter := &v1alpha1.ImageFilter{RequiredFeatureSetValues: []string{"scibase", "_usi"}} | ||
| tokens := map[string]struct{}{"scibase": {}, "_usi": {}, "vhost": {}} | ||
| Expect(passesImageFilter(tokens, filter)).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("fails when a required value is absent", func() { | ||
| filter := &v1alpha1.ImageFilter{RequiredFeatureSetValues: []string{"scibase", "_usi"}} | ||
| tokens := map[string]struct{}{"scibase": {}} | ||
| Expect(passesImageFilter(tokens, filter)).To(BeFalse()) | ||
| }) | ||
|
|
||
| It("fails when normalized form is present but raw form is required", func() { | ||
| filter := &v1alpha1.ImageFilter{RequiredFeatureSetValues: []string{"_usi"}} | ||
| tokens := map[string]struct{}{"usi": {}} | ||
| Expect(passesImageFilter(tokens, filter)).To(BeFalse()) | ||
| }) | ||
|
|
||
| It("fails when token set is empty", func() { | ||
| filter := &v1alpha1.ImageFilter{RequiredFeatureSetValues: []string{"scibase"}} | ||
| Expect(passesImageFilter(map[string]struct{}{}, filter)).To(BeFalse()) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.