Merge pull request #423 from GLYASAI/imageinfo

[FIX] nil pointer dereference
This commit is contained in:
barnettZQG 2019-09-03 05:43:02 -05:00 committed by GitHub
commit 2fa59856e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -105,6 +105,9 @@ type Image struct {
//String -
func (i Image) String() string {
if i.name == nil {
return ""
}
return i.name.String()
}
@ -115,11 +118,17 @@ func (i Image) GetTag() string {
//GetRepostory get repostory
func (i Image) GetRepostory() string {
if i.name == nil {
return ""
}
return reference.Path(i.name)
}
//GetDomain get image registry domain
func (i Image) GetDomain() string {
if i.name == nil {
return ""
}
domain := reference.Domain(i.name)
if domain == "docker.io" {
domain = "registry-1.docker.io"
@ -289,7 +298,7 @@ func readmemory(s string) int {
func ParseImageName(s string) (i Image) {
ref, err := reference.ParseAnyReference(s)
if err != nil {
logrus.Errorf("parse image failure %s", err.Error())
logrus.Errorf("image name: %s; parse image failure %s", s, err.Error())
return i
}
name, err := reference.ParseNamed(ref.String())

View File

@ -48,6 +48,13 @@ func TestParseImageName(t *testing.T) {
t.Logf("repostory %s", image4.GetRepostory())
t.Logf("name %s", image4.GetSimpleName())
t.Logf("tag %s", image4.GetTag())
image5 := ParseImageName("")
t.Logf("string %s", image5.String())
t.Logf("domain %s", image5.GetDomain())
t.Logf("repostory %s", image5.GetRepostory())
t.Logf("name %s", image5.GetSimpleName())
t.Logf("tag %s", image5.GetTag())
}
func TestDetermineDeployType(t *testing.T) {
t.Log(DetermineDeployType(ParseImageName("barnett/zookeeper:3.2")))