Skip to content

Commit e9fcfa6

Browse files
committed
refactor: rename GetImageByDigest() to GetImageById()
1 parent 39cc901 commit e9fcfa6

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

client.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ func (p *Prometheus) pullImage(imageName, dstName string, progressCh chan types.
188188
return nil
189189
}
190190

191-
/* GetImageByDigest returns an image from the Prometheus store by its digest. */
192-
func (p *Prometheus) GetImageByDigest(digest string) (cstorage.Image, error) {
191+
/* GetImageById returns an image from the Prometheus store by its ID. */
192+
func (p *Prometheus) GetImageById(id string) (cstorage.Image, error) {
193193
images, err := p.Store.Images()
194194
if err != nil {
195195
return cstorage.Image{}, err
196196
}
197197

198198
for _, img := range images {
199-
if img.ID == digest {
199+
if img.ID == id {
200200
return img, nil
201201
}
202202
}
@@ -205,16 +205,15 @@ func (p *Prometheus) GetImageByDigest(digest string) (cstorage.Image, error) {
205205
return cstorage.Image{}, err
206206
}
207207

208-
/* DoesImageExist checks if an image exists in the Prometheus store by its
209-
* digest. It returns a boolean indicating if the image exists and an error
210-
* if any. */
211-
func (p *Prometheus) DoesImageExist(digest string) (bool, error) {
212-
image, err := p.GetImageByDigest(digest)
208+
/* DoesImageExist checks if an image exists in the Prometheus store by its ID.
209+
* It returns a boolean indicating if the image exists and an error if any. */
210+
func (p *Prometheus) DoesImageExist(id string) (bool, error) {
211+
image, err := p.GetImageById(id)
213212
if err != nil {
214213
return false, err
215214
}
216215

217-
if image.ID == digest {
216+
if image.ID == id {
218217
return true, nil
219218
}
220219

@@ -259,7 +258,7 @@ func (p *Prometheus) BuildContainerFile(dockerfilePath string, imageName string)
259258
return cstorage.Image{}, err
260259
}
261260

262-
image, err := p.GetImageByDigest(id)
261+
image, err := p.GetImageById(id)
263262
if err != nil {
264263
return cstorage.Image{}, err
265264
}

tests/pull_image_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func TestPullImage(t *testing.T) {
4545
t.Fatal("image digest is empty")
4646
}
4747

48+
if image.Config.Digest == "" {
49+
t.Fatal("image config digest is empty")
50+
}
51+
4852
if image.Config.Size == 0 {
4953
t.Fatal("image config size is 0")
5054
}

0 commit comments

Comments
 (0)