mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-20 15:04:17 +00:00
Add set-based label selector test and docs coverage for restore
Restore label selector filtering had only equality-based coverage; set-based selectors were exercised nowhere in the repo, relying entirely on apimachinery behavior. Add notin, in, and doesnotexist (!key) cases to TestRestoreResourceFiltering and set-based parse cases for the --selector CLI flag. Also document restore usage of --selector in resource-filtering.md: the notin phased-restore scenario (noting notin also matches resources without the label key), restoring only unlabeled resources via '!<key>', and the caveat that restore item action dependencies bypass label selectors. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
836689f6cc
commit
b7ffd55085
@@ -24,6 +24,28 @@ func TestSetOfLabelSelector(t *testing.T) {
|
||||
assert.True(t, str == "k1=v1,k2=v2" || str == "k2=v2,k2=v2")
|
||||
}
|
||||
|
||||
func TestSetOfSetBasedLabelSelector(t *testing.T) {
|
||||
selector := &LabelSelector{}
|
||||
require.NoError(t, selector.Set("pr-label notin (1)"))
|
||||
require.NotNil(t, selector.LabelSelector)
|
||||
require.Len(t, selector.LabelSelector.MatchExpressions, 1)
|
||||
req := selector.LabelSelector.MatchExpressions[0]
|
||||
assert.Equal(t, "pr-label", req.Key)
|
||||
assert.Equal(t, metav1.LabelSelectorOpNotIn, req.Operator)
|
||||
assert.Equal(t, []string{"1"}, req.Values)
|
||||
}
|
||||
|
||||
func TestSetOfDoesNotExistLabelSelector(t *testing.T) {
|
||||
selector := &LabelSelector{}
|
||||
require.NoError(t, selector.Set("!pr-label"))
|
||||
require.NotNil(t, selector.LabelSelector)
|
||||
require.Len(t, selector.LabelSelector.MatchExpressions, 1)
|
||||
req := selector.LabelSelector.MatchExpressions[0]
|
||||
assert.Equal(t, "pr-label", req.Key)
|
||||
assert.Equal(t, metav1.LabelSelectorOpDoesNotExist, req.Operator)
|
||||
assert.Empty(t, req.Values)
|
||||
}
|
||||
|
||||
func TestTypeOfLabelSelector(t *testing.T) {
|
||||
selector := &LabelSelector{}
|
||||
assert.Equal(t, "labelSelector", selector.Type())
|
||||
|
||||
Reference in New Issue
Block a user