mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 02:38:17 +08:00
Merge pull request #423 from GLYASAI/imageinfo
[FIX] nil pointer dereference
This commit is contained in:
commit
2fa59856e3
@ -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())
|
||||
|
@ -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")))
|
||||
|
Loading…
Reference in New Issue
Block a user