mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-20 23:57:42 +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{
|
ScopeSelectors: map[string][]*rule.Selector{
|
||||||
"project": {
|
"project": {
|
||||||
{
|
{
|
||||||
Kind: "regularExpression",
|
Kind: "doublestar",
|
||||||
Decoration: "matches",
|
Decoration: "nsMatches",
|
||||||
Pattern: "**",
|
Pattern: "**",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
{
|
{
|
||||||
Kind: "regularExpression",
|
Kind: "doublestar",
|
||||||
Decoration: "matches",
|
Decoration: "repoMatches",
|
||||||
Pattern: "**",
|
Pattern: "**",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -102,7 +102,7 @@ func (suite *ProcessorTestSuite) TearDownSuite() {}
|
|||||||
func (suite *ProcessorTestSuite) TestProcess() {
|
func (suite *ProcessorTestSuite) TestProcess() {
|
||||||
results, err := suite.p.Process(suite.all)
|
results, err := suite.p.Process(suite.all)
|
||||||
require.NoError(suite.T(), err)
|
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 {
|
assert.Condition(suite.T(), func() bool {
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if r.Error != nil {
|
if r.Error != nil {
|
||||||
|
@ -31,6 +31,10 @@ const (
|
|||||||
RepoMatches = "repoMatches"
|
RepoMatches = "repoMatches"
|
||||||
// RepoExcludes represents repository excludes [pattern]
|
// RepoExcludes represents repository excludes [pattern]
|
||||||
RepoExcludes = "repoExcludes"
|
RepoExcludes = "repoExcludes"
|
||||||
|
// NSMatches represents namespace matches [pattern]
|
||||||
|
NSMatches = "nsMatches"
|
||||||
|
// NSExcludes represents namespace excludes [pattern]
|
||||||
|
NSExcludes = "nsExcludes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// selector for regular expression
|
// selector for regular expression
|
||||||
@ -59,6 +63,11 @@ func (s *selector) Select(artifacts []*res.Candidate) (selected []*res.Candidate
|
|||||||
case RepoExcludes:
|
case RepoExcludes:
|
||||||
value = art.Repository
|
value = art.Repository
|
||||||
excludes = true
|
excludes = true
|
||||||
|
case NSMatches:
|
||||||
|
value = art.Namespace
|
||||||
|
case NSExcludes:
|
||||||
|
value = art.Namespace
|
||||||
|
excludes = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(value) > 0 {
|
if len(value) > 0 {
|
||||||
@ -95,5 +104,12 @@ func match(pattern, str string) (bool, error) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Register doublestar selector
|
// 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"},
|
Labels: []string{"label1", "label2", "label3"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 2,
|
||||||
Namespace: "library",
|
Namespace: "retention",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
Tag: "4.0",
|
Tag: "4.0",
|
||||||
Kind: res.Image,
|
Kind: res.Image,
|
||||||
@ -62,8 +62,8 @@ func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
|||||||
Labels: []string{"label1", "label4", "label5"},
|
Labels: []string{"label1", "label4", "label5"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 2,
|
||||||
Namespace: "library",
|
Namespace: "retention",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
Tag: "4.1",
|
Tag: "4.1",
|
||||||
Kind: res.Image,
|
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)
|
// Check whether the returned result matched the expected ones (only check repo:tag)
|
||||||
func expect(expected []string, candidates []*res.Candidate) bool {
|
func expect(expected []string, candidates []*res.Candidate) bool {
|
||||||
hash := make(map[string]bool)
|
hash := make(map[string]bool)
|
||||||
|
Loading…
Reference in New Issue
Block a user