mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-20 07:37:38 +01:00
update doublestar pattern and the failed launcher UT cases
Signed-off-by: Steven Zou <szou@vmware.com>
This commit is contained in:
parent
0994e5efc9
commit
24190291b6
@ -216,15 +216,15 @@ func (l *launchTestSuite) TestLaunch() {
|
||||
ScopeSelectors: map[string][]*rule.Selector{
|
||||
"project": {
|
||||
{
|
||||
Kind: "regularExpression",
|
||||
Decoration: "matches",
|
||||
Kind: "doublestar",
|
||||
Decoration: "nsMatches",
|
||||
Pattern: "**",
|
||||
},
|
||||
},
|
||||
"repository": {
|
||||
{
|
||||
Kind: "regularExpression",
|
||||
Decoration: "matches",
|
||||
Kind: "doublestar",
|
||||
Decoration: "repoMatches",
|
||||
Pattern: "**",
|
||||
},
|
||||
},
|
||||
|
@ -102,7 +102,7 @@ func (suite *ProcessorTestSuite) TearDownSuite() {}
|
||||
func (suite *ProcessorTestSuite) TestProcess() {
|
||||
results, err := suite.p.Process(suite.all)
|
||||
require.NoError(suite.T(), err)
|
||||
assert.Equal(suite.T(), 2, len(results))
|
||||
assert.Equal(suite.T(), 1, len(results))
|
||||
assert.Condition(suite.T(), func() bool {
|
||||
for _, r := range results {
|
||||
if r.Error != nil {
|
||||
|
@ -31,6 +31,10 @@ const (
|
||||
RepoMatches = "repoMatches"
|
||||
// RepoExcludes represents repository excludes [pattern]
|
||||
RepoExcludes = "repoExcludes"
|
||||
// NSMatches represents namespace matches [pattern]
|
||||
NSMatches = "nsMatches"
|
||||
// NSExcludes represents namespace excludes [pattern]
|
||||
NSExcludes = "nsExcludes"
|
||||
)
|
||||
|
||||
// selector for regular expression
|
||||
@ -59,6 +63,11 @@ func (s *selector) Select(artifacts []*res.Candidate) (selected []*res.Candidate
|
||||
case RepoExcludes:
|
||||
value = art.Repository
|
||||
excludes = true
|
||||
case NSMatches:
|
||||
value = art.Namespace
|
||||
case NSExcludes:
|
||||
value = art.Namespace
|
||||
excludes = true
|
||||
}
|
||||
|
||||
if len(value) > 0 {
|
||||
@ -95,5 +104,12 @@ func match(pattern, str string) (bool, error) {
|
||||
|
||||
func init() {
|
||||
// Register doublestar selector
|
||||
selectors.Register(Kind, []string{Matches, Excludes}, New)
|
||||
selectors.Register(Kind, []string{
|
||||
Matches,
|
||||
Excludes,
|
||||
RepoMatches,
|
||||
RepoExcludes,
|
||||
NSMatches,
|
||||
NSExcludes,
|
||||
}, New)
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
||||
Labels: []string{"label1", "label2", "label3"},
|
||||
},
|
||||
{
|
||||
NamespaceID: 1,
|
||||
Namespace: "library",
|
||||
NamespaceID: 2,
|
||||
Namespace: "retention",
|
||||
Repository: "redis",
|
||||
Tag: "4.0",
|
||||
Kind: res.Image,
|
||||
@ -62,8 +62,8 @@ func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
||||
Labels: []string{"label1", "label4", "label5"},
|
||||
},
|
||||
{
|
||||
NamespaceID: 1,
|
||||
Namespace: "library",
|
||||
NamespaceID: 2,
|
||||
Namespace: "retention",
|
||||
Repository: "redis",
|
||||
Tag: "4.1",
|
||||
Kind: res.Image,
|
||||
@ -180,6 +180,60 @@ func (suite *RegExpSelectorTestSuite) TestRepoExcludes() {
|
||||
})
|
||||
}
|
||||
|
||||
// TestNSMatches tests the namespace `matches` case
|
||||
func (suite *RegExpSelectorTestSuite) TestNSMatches() {
|
||||
repoMatches := &selector{
|
||||
decoration: NSMatches,
|
||||
pattern: "{library}",
|
||||
}
|
||||
|
||||
selected, err := repoMatches.Select(suite.artifacts)
|
||||
require.NoError(suite.T(), err)
|
||||
assert.Equal(suite.T(), 1, len(selected))
|
||||
assert.Condition(suite.T(), func() bool {
|
||||
return expect([]string{"harbor:latest"}, selected)
|
||||
})
|
||||
|
||||
repoMatches2 := &selector{
|
||||
decoration: RepoMatches,
|
||||
pattern: "re*",
|
||||
}
|
||||
|
||||
selected, err = repoMatches2.Select(suite.artifacts)
|
||||
require.NoError(suite.T(), err)
|
||||
assert.Equal(suite.T(), 2, len(selected))
|
||||
assert.Condition(suite.T(), func() bool {
|
||||
return expect([]string{"redis:4.0", "redis:4.1"}, selected)
|
||||
})
|
||||
}
|
||||
|
||||
// TestNSExcludes tests the namespace `excludes` case
|
||||
func (suite *RegExpSelectorTestSuite) TestNSExcludes() {
|
||||
repoExcludes := &selector{
|
||||
decoration: NSExcludes,
|
||||
pattern: "{library}",
|
||||
}
|
||||
|
||||
selected, err := repoExcludes.Select(suite.artifacts)
|
||||
require.NoError(suite.T(), err)
|
||||
assert.Equal(suite.T(), 2, len(selected))
|
||||
assert.Condition(suite.T(), func() bool {
|
||||
return expect([]string{"redis:4.0", "redis:4.1"}, selected)
|
||||
})
|
||||
|
||||
repoExcludes2 := &selector{
|
||||
decoration: NSExcludes,
|
||||
pattern: "re*",
|
||||
}
|
||||
|
||||
selected, err = repoExcludes2.Select(suite.artifacts)
|
||||
require.NoError(suite.T(), err)
|
||||
assert.Equal(suite.T(), 1, len(selected))
|
||||
assert.Condition(suite.T(), func() bool {
|
||||
return expect([]string{"harbor:latest"}, selected)
|
||||
})
|
||||
}
|
||||
|
||||
// Check whether the returned result matched the expected ones (only check repo:tag)
|
||||
func expect(expected []string, candidates []*res.Candidate) bool {
|
||||
hash := make(map[string]bool)
|
||||
|
Loading…
Reference in New Issue
Block a user