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

Fix and re-enable the multi diff test #187

Merged
merged 3 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,40 @@ func getPrepperForImage(image string) (pkgutil.Prepper, error) {
Source: image,
Client: cli,
}, nil

}

ref, err := docker.ParseReference("//" + image)
if err != nil {
return nil, err
}
src, err := ref.NewImageSource(nil)
if err != nil {
return nil, err
// see if the image name has tag provided, if not add latest as tag
if !strings.Contains(image, ":") {
image = image + ":latest"
}

if strings.HasPrefix(image, DaemonPrefix) {

// remove the DaemonPrefix
image := strings.Replace(image, DaemonPrefix, "", -1)
// see if the image name has tag provided, if not add latest as tag
if !strings.Contains(image, ":") {
image = image + ":latest"
}

return pkgutil.DaemonPrepper{
Source: image,
Client: cli,
ImageSource: src,
Source: image,
Client: cli,
}, nil
}
// either has remote prefix or has no prefix, in which case we force remote

// see if the image name has tag provided, if not add latest as tag
if !strings.Contains(image, ":") {
image = image + ":latest"
}
ref, err := docker.ParseReference("//" + image)
if err != nil {
return nil, err
}
src, err := ref.NewImageSource(nil)
if err != nil {
return nil, err
}

if !noCache {
cacheDir, err := cacheDir()
if err != nil {
Expand Down
13 changes: 8 additions & 5 deletions pkg/util/daemon_prepper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ import (
"strings"

"github.com/containers/image/docker/daemon"
"github.com/containers/image/types"

"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)

type DaemonPrepper struct {
Source string
Client *client.Client
ImageSource types.ImageSource
Source string
Client *client.Client
}

func (p DaemonPrepper) Name() string {
Expand All @@ -54,14 +52,19 @@ func (p DaemonPrepper) GetFileSystem() (string, error) {
return "", err
}

src, err := ref.NewImageSource(nil)
if err != nil {
return "", err
}

sanitizedName := strings.Replace(p.Source, ":", "", -1)
sanitizedName = strings.Replace(sanitizedName, "/", "", -1)

path, err := ioutil.TempDir("", sanitizedName)
if err != nil {
return "", err
}
return path, getFileSystemFromReference(ref, p.ImageSource, path)
return path, getFileSystemFromReference(ref, src, path)
}

func (p DaemonPrepper) GetConfig() (ConfigSchema, error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/apt_analysis_expected.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"Image": "gcr.io/gcp-runtimes/apt-modified",
"Image": "gcr.io/gcp-runtimes/apt-modified:latest",
"AnalyzeType": "Apt",
"Analysis": [
{
Expand Down
4 changes: 2 additions & 2 deletions tests/apt_diff_expected.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"Image1": "gcr.io/gcp-runtimes/apt-base",
"Image2": "gcr.io/gcp-runtimes/apt-modified",
"Image1": "gcr.io/gcp-runtimes/apt-base:latest",
"Image2": "gcr.io/gcp-runtimes/apt-modified:latest",
"DiffType": "Apt",
"Diff": {
"Packages1": [
Expand Down
4 changes: 2 additions & 2 deletions tests/apt_sorted_diff_expected.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"Image1": "gcr.io/gcp-runtimes/apt-base",
"Image2": "gcr.io/gcp-runtimes/apt-modified",
"Image1": "gcr.io/gcp-runtimes/apt-base:latest",
"Image2": "gcr.io/gcp-runtimes/apt-modified:latest",
"DiffType": "Apt",
"Diff": {
"Packages1": [
Expand Down
4 changes: 2 additions & 2 deletions tests/file_diff_expected.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"Image1": "gcr.io/gcp-runtimes/diff-base",
"Image2": "gcr.io/gcp-runtimes/diff-modified",
"Image1": "gcr.io/gcp-runtimes/diff-base:latest",
"Image2": "gcr.io/gcp-runtimes/diff-modified:latest",
"DiffType": "File",
"Diff": {
"Adds": null,
Expand Down
2 changes: 1 addition & 1 deletion tests/file_sorted_analysis_expected.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"Image": "gcr.io/gcp-runtimes/diff-modified",
"Image": "gcr.io/gcp-runtimes/diff-modified:latest",
"AnalyzeType": "File",
"Analysis": [
{
Expand Down
4 changes: 2 additions & 2 deletions tests/hist_diff_expected.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"Image1": "gcr.io/gcp-runtimes/diff-base",
"Image2": "gcr.io/gcp-runtimes/diff-modified",
"Image1": "gcr.io/gcp-runtimes/diff-base:latest",
"Image2": "gcr.io/gcp-runtimes/diff-modified:latest",
"DiffType": "History",
"Diff": {
"Adds": [
Expand Down
22 changes: 13 additions & 9 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -135,14 +136,14 @@ func TestDiffAndAnalysis(t *testing.T) {
differFlags: []string{"--type=node", "--type=pip", "--type=apt"},
expectedFile: "multi_diff_expected.json",
},
// {
// description: "multi differ local",
// subcommand: "diff",
// imageA: multiBaseLocal,
// imageB: multiModifiedLocal,
// differFlags: []string{"--type=node", "--type=pip", "--type=apt"},
// expectedFile: "multi_diff_expected.json",
// },
{
description: "multi differ local",
subcommand: "diff",
imageA: multiBaseLocal,
imageB: multiModifiedLocal,
differFlags: []string{"--type=node", "--type=pip", "--type=apt"},
expectedFile: "multi_diff_expected.json",
},
{
description: "history differ",
subcommand: "diff",
Expand Down Expand Up @@ -232,12 +233,15 @@ func TestMain(m *testing.M) {
fmt.Printf("Error retrieving docker client: %s", err)
os.Exit(1)
}
closer.Close()
io.Copy(os.Stdout, closer)

closer, err = cli.ImagePull(ctx, multiModified, types.ImagePullOptions{})
if err != nil {
fmt.Printf("Error retrieving docker client: %s", err)
os.Exit(1)
}
io.Copy(os.Stdout, closer)

closer.Close()
os.Exit(m.Run())
}
12 changes: 6 additions & 6 deletions tests/multi_diff_expected.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"Image1": "gcr.io/gcp-runtimes/multi-base",
"Image2": "gcr.io/gcp-runtimes/multi-modified",
"Image1": "gcr.io/gcp-runtimes/multi-base:latest",
"Image2": "gcr.io/gcp-runtimes/multi-modified:latest",
"DiffType": "Apt",
"Diff": {
"Packages1": [],
Expand Down Expand Up @@ -56,8 +56,8 @@
}
},
{
"Image1": "gcr.io/gcp-runtimes/multi-base",
"Image2": "gcr.io/gcp-runtimes/multi-modified",
"Image1": "gcr.io/gcp-runtimes/multi-base:latest",
"Image2": "gcr.io/gcp-runtimes/multi-modified:latest",
"DiffType": "Node",
"Diff": {
"Packages1": [],
Expand Down Expand Up @@ -89,8 +89,8 @@
}
},
{
"Image1": "gcr.io/gcp-runtimes/multi-base",
"Image2": "gcr.io/gcp-runtimes/multi-modified",
"Image1": "gcr.io/gcp-runtimes/multi-base:latest",
"Image2": "gcr.io/gcp-runtimes/multi-modified:latest",
"DiffType": "Pip",
"Diff": {
"Packages1": [
Expand Down
2 changes: 1 addition & 1 deletion tests/node_analysis_expected.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"Image": "gcr.io/gcp-runtimes/node-modified",
"Image": "gcr.io/gcp-runtimes/node-modified:latest",
"AnalyzeType": "Node",
"Analysis": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/node_diff_order_expected.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"Image1": "gcr.io/gcp-runtimes/node-modified:2.0",
"Image2": "gcr.io/gcp-runtimes/node-modified",
"Image2": "gcr.io/gcp-runtimes/node-modified:latest",
"DiffType": "Node",
"Diff": {
"Packages1": [],
Expand Down
2 changes: 1 addition & 1 deletion tests/pip_analysis_expected.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"Image": "gcr.io/gcp-runtimes/pip-modified",
"Image": "gcr.io/gcp-runtimes/pip-modified:latest",
"AnalyzeType": "Pip",
"Analysis": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/rpm_analysis_expected.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"Image": "valentinrothberg/containerdiff:diff-modified",
"Image": "valentinrothberg/containerdiff:diff-modified:latest",
"AnalyzeType": "RPM",
"Analysis": [
{
Expand Down