fix(replication) gitlab filters may not work

Signed-off-by: Ziming Zhang <zziming@vmware.com>
This commit is contained in:
Ziming Zhang 2021-09-13 17:22:55 +08:00
parent 3ce072016f
commit d62aaaa625
2 changed files with 14 additions and 3 deletions

View File

@ -90,10 +90,8 @@ func (a *adapter) FetchArtifacts(filters []*model.Filter) ([]*model.Resource, er
for _, filter := range filters {
if filter.Type == model.FilterTypeName {
nameFilter = filter.Value.(string)
break
} else if filter.Type == model.FilterTypeTag {
tagFilter = filter.Value.(string)
break
}
}
@ -142,7 +140,7 @@ func (a *adapter) FetchArtifacts(filters []*model.Filter) ([]*model.Resource, er
tags := []string{}
for _, vTag := range vTags {
if len(tagFilter) > 0 {
if ok, _ := util.Match(strings.ToLower(vTag.Name), strings.ToLower(tagFilter)); !ok {
if ok, _ := util.Match(strings.ToLower(tagFilter), strings.ToLower(vTag.Name)); !ok {
continue
}
}

View File

@ -122,4 +122,17 @@ func TestFetchImages(t *testing.T) {
assertions.Len(resources, v, k, v)
}
resources, err := adapter.FetchArtifacts([]*model.Filter{
{
Type: model.FilterTypeName,
Value: "library/dockers",
},
{
Type: model.FilterTypeTag,
Value: "{late*,v2}",
},
})
require.Nil(t, err)
require.Equal(t, 1, len(resources))
require.Equal(t, 2, len(resources[0].Metadata.Vtags))
}