Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 78ff4af

Browse files
authored
Fix and re-enable the multi diff test (#187)
* Fix daemon prefix prepping. * Make latest consistent between daemon and registry. * Wait for the image pulls to complete.
1 parent af8783d commit 78ff4af

14 files changed

+59
-47
lines changed

cmd/root.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,35 +132,40 @@ func getPrepperForImage(image string) (pkgutil.Prepper, error) {
132132
Source: image,
133133
Client: cli,
134134
}, nil
135-
136135
}
137136

138-
ref, err := docker.ParseReference("//" + image)
139-
if err != nil {
140-
return nil, err
141-
}
142-
src, err := ref.NewImageSource(nil)
143-
if err != nil {
144-
return nil, err
137+
// see if the image name has tag provided, if not add latest as tag
138+
if !strings.Contains(image, ":") {
139+
image = image + ":latest"
145140
}
146141

147142
if strings.HasPrefix(image, DaemonPrefix) {
148-
149143
// remove the DaemonPrefix
150144
image := strings.Replace(image, DaemonPrefix, "", -1)
151-
// see if the image name has tag provided, if not add latest as tag
152145
if !strings.Contains(image, ":") {
153146
image = image + ":latest"
154147
}
155148

156149
return pkgutil.DaemonPrepper{
157-
Source: image,
158-
Client: cli,
159-
ImageSource: src,
150+
Source: image,
151+
Client: cli,
160152
}, nil
161153
}
162154
// either has remote prefix or has no prefix, in which case we force remote
163155

156+
// see if the image name has tag provided, if not add latest as tag
157+
if !strings.Contains(image, ":") {
158+
image = image + ":latest"
159+
}
160+
ref, err := docker.ParseReference("//" + image)
161+
if err != nil {
162+
return nil, err
163+
}
164+
src, err := ref.NewImageSource(nil)
165+
if err != nil {
166+
return nil, err
167+
}
168+
164169
if !noCache {
165170
cacheDir, err := cacheDir()
166171
if err != nil {

pkg/util/daemon_prepper.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ import (
2222
"strings"
2323

2424
"github.com/containers/image/docker/daemon"
25-
"github.com/containers/image/types"
2625

2726
"github.com/docker/docker/client"
2827
"github.com/sirupsen/logrus"
2928
)
3029

3130
type DaemonPrepper struct {
32-
Source string
33-
Client *client.Client
34-
ImageSource types.ImageSource
31+
Source string
32+
Client *client.Client
3533
}
3634

3735
func (p DaemonPrepper) Name() string {
@@ -54,14 +52,19 @@ func (p DaemonPrepper) GetFileSystem() (string, error) {
5452
return "", err
5553
}
5654

55+
src, err := ref.NewImageSource(nil)
56+
if err != nil {
57+
return "", err
58+
}
59+
5760
sanitizedName := strings.Replace(p.Source, ":", "", -1)
5861
sanitizedName = strings.Replace(sanitizedName, "/", "", -1)
5962

6063
path, err := ioutil.TempDir("", sanitizedName)
6164
if err != nil {
6265
return "", err
6366
}
64-
return path, getFileSystemFromReference(ref, p.ImageSource, path)
67+
return path, getFileSystemFromReference(ref, src, path)
6568
}
6669

6770
func (p DaemonPrepper) GetConfig() (ConfigSchema, error) {

tests/apt_analysis_expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"Image": "gcr.io/gcp-runtimes/apt-modified",
3+
"Image": "gcr.io/gcp-runtimes/apt-modified:latest",
44
"AnalyzeType": "Apt",
55
"Analysis": [
66
{

tests/apt_diff_expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"Image1": "gcr.io/gcp-runtimes/apt-base",
4-
"Image2": "gcr.io/gcp-runtimes/apt-modified",
3+
"Image1": "gcr.io/gcp-runtimes/apt-base:latest",
4+
"Image2": "gcr.io/gcp-runtimes/apt-modified:latest",
55
"DiffType": "Apt",
66
"Diff": {
77
"Packages1": [

tests/apt_sorted_diff_expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"Image1": "gcr.io/gcp-runtimes/apt-base",
4-
"Image2": "gcr.io/gcp-runtimes/apt-modified",
3+
"Image1": "gcr.io/gcp-runtimes/apt-base:latest",
4+
"Image2": "gcr.io/gcp-runtimes/apt-modified:latest",
55
"DiffType": "Apt",
66
"Diff": {
77
"Packages1": [

tests/file_diff_expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"Image1": "gcr.io/gcp-runtimes/diff-base",
4-
"Image2": "gcr.io/gcp-runtimes/diff-modified",
3+
"Image1": "gcr.io/gcp-runtimes/diff-base:latest",
4+
"Image2": "gcr.io/gcp-runtimes/diff-modified:latest",
55
"DiffType": "File",
66
"Diff": {
77
"Adds": null,

tests/file_sorted_analysis_expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"Image": "gcr.io/gcp-runtimes/diff-modified",
3+
"Image": "gcr.io/gcp-runtimes/diff-modified:latest",
44
"AnalyzeType": "File",
55
"Analysis": [
66
{

tests/hist_diff_expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"Image1": "gcr.io/gcp-runtimes/diff-base",
4-
"Image2": "gcr.io/gcp-runtimes/diff-modified",
3+
"Image1": "gcr.io/gcp-runtimes/diff-base:latest",
4+
"Image2": "gcr.io/gcp-runtimes/diff-modified:latest",
55
"DiffType": "History",
66
"Diff": {
77
"Adds": [

tests/integration_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"bytes"
2323
"context"
2424
"fmt"
25+
"io"
2526
"io/ioutil"
2627
"os"
2728
"os/exec"
@@ -135,14 +136,14 @@ func TestDiffAndAnalysis(t *testing.T) {
135136
differFlags: []string{"--type=node", "--type=pip", "--type=apt"},
136137
expectedFile: "multi_diff_expected.json",
137138
},
138-
// {
139-
// description: "multi differ local",
140-
// subcommand: "diff",
141-
// imageA: multiBaseLocal,
142-
// imageB: multiModifiedLocal,
143-
// differFlags: []string{"--type=node", "--type=pip", "--type=apt"},
144-
// expectedFile: "multi_diff_expected.json",
145-
// },
139+
{
140+
description: "multi differ local",
141+
subcommand: "diff",
142+
imageA: multiBaseLocal,
143+
imageB: multiModifiedLocal,
144+
differFlags: []string{"--type=node", "--type=pip", "--type=apt"},
145+
expectedFile: "multi_diff_expected.json",
146+
},
146147
{
147148
description: "history differ",
148149
subcommand: "diff",
@@ -232,12 +233,15 @@ func TestMain(m *testing.M) {
232233
fmt.Printf("Error retrieving docker client: %s", err)
233234
os.Exit(1)
234235
}
235-
closer.Close()
236+
io.Copy(os.Stdout, closer)
237+
236238
closer, err = cli.ImagePull(ctx, multiModified, types.ImagePullOptions{})
237239
if err != nil {
238240
fmt.Printf("Error retrieving docker client: %s", err)
239241
os.Exit(1)
240242
}
243+
io.Copy(os.Stdout, closer)
244+
241245
closer.Close()
242246
os.Exit(m.Run())
243247
}

tests/multi_diff_expected.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"Image1": "gcr.io/gcp-runtimes/multi-base",
4-
"Image2": "gcr.io/gcp-runtimes/multi-modified",
3+
"Image1": "gcr.io/gcp-runtimes/multi-base:latest",
4+
"Image2": "gcr.io/gcp-runtimes/multi-modified:latest",
55
"DiffType": "Apt",
66
"Diff": {
77
"Packages1": [],
@@ -56,8 +56,8 @@
5656
}
5757
},
5858
{
59-
"Image1": "gcr.io/gcp-runtimes/multi-base",
60-
"Image2": "gcr.io/gcp-runtimes/multi-modified",
59+
"Image1": "gcr.io/gcp-runtimes/multi-base:latest",
60+
"Image2": "gcr.io/gcp-runtimes/multi-modified:latest",
6161
"DiffType": "Node",
6262
"Diff": {
6363
"Packages1": [],
@@ -89,8 +89,8 @@
8989
}
9090
},
9191
{
92-
"Image1": "gcr.io/gcp-runtimes/multi-base",
93-
"Image2": "gcr.io/gcp-runtimes/multi-modified",
92+
"Image1": "gcr.io/gcp-runtimes/multi-base:latest",
93+
"Image2": "gcr.io/gcp-runtimes/multi-modified:latest",
9494
"DiffType": "Pip",
9595
"Diff": {
9696
"Packages1": [

0 commit comments

Comments
 (0)