mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 20:26:13 +01:00
Split populating author as a method and add unit test
This commit is contained in:
parent
745d83e393
commit
d9b0f54c5e
@ -466,15 +466,26 @@ func getTagDetail(client *registry.Repository, tag string) (*tagDetail, error) {
|
||||
return detail, err
|
||||
}
|
||||
|
||||
if len(detail.Author) == 0 && detail.Config != nil {
|
||||
populateAuthor(detail)
|
||||
|
||||
return detail, nil
|
||||
}
|
||||
|
||||
func populateAuthor(detail *tagDetail) {
|
||||
// has author info already
|
||||
if len(detail.Author) > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// try to set author with the value of label "maintainer"
|
||||
if detail.Config != nil {
|
||||
for k, v := range detail.Config.Labels {
|
||||
if strings.ToLower(k) == "maintainer" {
|
||||
detail.Author = v
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return detail, nil
|
||||
}
|
||||
|
||||
// GetManifests returns the manifest of a tag
|
||||
|
@ -199,3 +199,27 @@ func TestGetReposTop(t *testing.T) {
|
||||
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
func TestPopulateAuthor(t *testing.T) {
|
||||
author := "author"
|
||||
detail := &tagDetail{
|
||||
Author: author,
|
||||
}
|
||||
populateAuthor(detail)
|
||||
assert.Equal(t, author, detail.Author)
|
||||
|
||||
detail = &tagDetail{}
|
||||
populateAuthor(detail)
|
||||
assert.Equal(t, "", detail.Author)
|
||||
|
||||
maintainer := "maintainer"
|
||||
detail = &tagDetail{
|
||||
Config: &cfg{
|
||||
Labels: map[string]string{
|
||||
"Maintainer": maintainer,
|
||||
},
|
||||
},
|
||||
}
|
||||
populateAuthor(detail)
|
||||
assert.Equal(t, maintainer, detail.Author)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user