This repository was archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 237
Use go integration tests #57
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
tests/*_actual.json | ||
out/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
sudo: required | ||
dist: trusty | ||
|
||
language: go | ||
os: linux | ||
go: | ||
- 1.8.1 | ||
- 1.8.3 | ||
go_import_path: github.com/GoogleCloudPlatform/container-diff | ||
|
||
script: | ||
- ./.gofmt.sh | ||
- travis_wait ./.container-diff-tests.sh | ||
- make test integration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// +build integration | ||
|
||
package tests | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
const ( | ||
diffBase = "gcr.io/gcp-runtimes/diff-base" | ||
diffModified = "gcr.io/gcp-runtimes/diff-modified" | ||
|
||
aptBase = "gcr.io/gcp-runtimes/apt-base" | ||
aptModified = "gcr.io/gcp-runtimes/apt-modified" | ||
|
||
// Why is this node-modified:2.0? | ||
nodeBase = "gcr.io/gcp-runtimes/node-modified:2.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm...I wonder if the source code for these images is lying around anywhere, I'm not a huge fan of this being abstracted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah as a TODO: get rid of these + get rid of the |
||
nodeModified = "gcr.io/gcp-runtimes/node-modified" | ||
|
||
pipModified = "gcr.io/gcp-runtimes/pip-modified" | ||
|
||
multiBase = "gcr.io/gcp-runtimes/multi-base" | ||
multiModified = "gcr.io/gcp-runtimes/multi-modified" | ||
) | ||
|
||
type ContainerDiffRunner struct { | ||
t *testing.T | ||
binaryPath string | ||
} | ||
|
||
func (c *ContainerDiffRunner) Run(command ...string) (string, error) { | ||
path, err := filepath.Abs(c.binaryPath) | ||
if err != nil { | ||
c.t.Fatalf("Error finding container-diff binary: %s", err) | ||
} | ||
c.t.Logf("Running command: %s %s", path, command) | ||
cmd := exec.Command(path, command...) | ||
|
||
var stdout, stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
if err := cmd.Run(); err != nil { | ||
return "", fmt.Errorf("Error running command %s: %s Stderr: %s", command, err, stderr.String()) | ||
} | ||
return stdout.String(), nil | ||
} | ||
|
||
func TestDiffAndAnalysis(t *testing.T) { | ||
runner := ContainerDiffRunner{ | ||
t: t, | ||
binaryPath: "../out/container-diff", | ||
} | ||
|
||
var tests = []struct { | ||
description string | ||
imageA string | ||
imageB string | ||
differFlag string | ||
subcommand string | ||
|
||
//TODO: Don't consume a json file | ||
expectedFile string | ||
}{ | ||
{ | ||
description: "file differ", | ||
subcommand: "diff", | ||
imageA: diffBase, | ||
imageB: diffModified, | ||
differFlag: "-f", | ||
expectedFile: "file_diff_expected.json", | ||
}, | ||
{ | ||
description: "apt differ", | ||
subcommand: "diff", | ||
imageA: aptBase, | ||
imageB: aptModified, | ||
differFlag: "-a", | ||
expectedFile: "apt_diff_expected.json", | ||
}, | ||
{ | ||
description: "node differ", | ||
subcommand: "diff", | ||
imageA: nodeBase, | ||
imageB: nodeModified, | ||
differFlag: "-n", | ||
expectedFile: "node_diff_order_expected.json", | ||
}, | ||
{ | ||
description: "multi differ", | ||
subcommand: "diff", | ||
imageA: multiBase, | ||
imageB: multiModified, | ||
differFlag: "-npa", | ||
expectedFile: "multi_diff_expected.json", | ||
}, | ||
{ | ||
description: "history differ", | ||
subcommand: "diff", | ||
imageA: diffBase, | ||
imageB: diffModified, | ||
differFlag: "-d", | ||
expectedFile: "hist_diff_expected.json", | ||
}, | ||
{ | ||
description: "apt sorted differ", | ||
subcommand: "diff", | ||
imageA: aptBase, | ||
imageB: aptModified, | ||
differFlag: "-ao", | ||
expectedFile: "apt_sorted_diff_expected.json", | ||
}, | ||
{ | ||
description: "apt analysis", | ||
subcommand: "analyze", | ||
imageA: aptModified, | ||
differFlag: "-a", | ||
expectedFile: "apt_analysis_expected.json", | ||
}, | ||
{ | ||
description: "file sorted analysis", | ||
subcommand: "analyze", | ||
imageA: diffModified, | ||
differFlag: "-fo", | ||
expectedFile: "file_sorted_analysis_expected.json", | ||
}, | ||
{ | ||
description: "pip analysis", | ||
subcommand: "analyze", | ||
imageA: pipModified, | ||
differFlag: "-p", | ||
expectedFile: "pip_analysis_expected.json", | ||
}, | ||
{ | ||
description: "node analysis", | ||
subcommand: "analyze", | ||
imageA: nodeModified, | ||
differFlag: "-n", | ||
expectedFile: "node_analysis_expected.json", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
args := []string{test.subcommand, test.imageA} | ||
if test.imageB != "" { | ||
args = append(args, test.imageB) | ||
} | ||
args = append(args, test.differFlag) | ||
args = append(args, "-j") | ||
actual, err := runner.Run(args...) | ||
if err != nil { | ||
t.Fatalf("Error running command: %s", err) | ||
} | ||
e, err := ioutil.ReadFile(test.expectedFile) | ||
if err != nil { | ||
t.Fatalf("Error reading expected file output file: %s", err) | ||
} | ||
actual = strings.TrimSpace(actual) | ||
expected := strings.TrimSpace(string(e)) | ||
if actual != expected { | ||
t.Errorf("Error actual output does not match expected. \n\nExpected: %s\n\n Actual: %s", expected, actual) | ||
} | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can specify multiple OSes here, should we run these tests on all platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this, but travis always has a backlog of OSX jobs (its at ~800 now). I think its probably best to just test on one platform for now.