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

Commit 9c47911

Browse files
committed
add tests
1 parent 265b622 commit 9c47911

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

cmd/analyze_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ var analyzeArgNumTests = []testpair{
2929
func TestAnalyzeArgNum(t *testing.T) {
3030
for _, test := range analyzeArgNumTests {
3131
err := checkAnalyzeArgNum(test.input)
32-
if (err == nil) != test.expected_output {
33-
if test.expected_output {
34-
t.Errorf("Got unexpected error: %s", err)
35-
} else {
32+
if (err == nil) != test.shouldError {
33+
if test.shouldError {
3634
t.Errorf("Expected error but got none")
35+
} else {
36+
t.Errorf("Got unexpected error: %s", err)
3737
}
3838
}
3939
}

cmd/diff_test.go

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,46 @@ import (
2121
)
2222

2323
var diffArgNumTests = []testpair{
24-
{[]string{}, false},
25-
{[]string{"one"}, false},
26-
{[]string{"one", "two"}, true},
27-
{[]string{"one", "two", "three"}, false},
24+
{[]string{}, true},
25+
{[]string{"one"}, true},
26+
{[]string{"one", "two"}, false},
27+
{[]string{"one", "two", "three"}, true},
2828
}
2929

3030
func TestDiffArgNum(t *testing.T) {
3131
for _, test := range diffArgNumTests {
3232
err := checkDiffArgNum(test.input)
33-
if (err == nil) != test.expected_output {
34-
if test.expected_output {
35-
t.Errorf("Got unexpected error: %s", err)
36-
} else {
37-
t.Errorf("Expected error but got none")
38-
}
33+
checkError(t, err, test.shouldError)
34+
}
35+
}
36+
37+
type imageDiff struct {
38+
image1 string
39+
image2 string
40+
shouldError bool
41+
}
42+
43+
var imageDiffs = []imageDiff{
44+
{"", "", true},
45+
{"gcr.io/google-appengine/python", "gcr.io/google-appengine/debian9", false},
46+
{"gcr.io/google-appengine/python", "cats", true},
47+
}
48+
49+
func TestDiffImages(t *testing.T) {
50+
for _, test := range imageDiffs {
51+
err := diffImages(test.image1, test.image2, []string{"apt"})
52+
checkError(t, err, test.shouldError)
53+
err = diffImages(test.image1, test.image2, []string{"metadata"})
54+
checkError(t, err, test.shouldError)
55+
}
56+
}
57+
58+
func checkError(t *testing.T, err error, shouldError bool) {
59+
if (err == nil) == shouldError {
60+
if shouldError {
61+
t.Errorf("expected error but got none")
62+
} else {
63+
t.Errorf("got unexpected error: %s", err)
3964
}
4065
}
4166
}

cmd/root_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ limitations under the License.
1717
package cmd
1818

1919
type testpair struct {
20-
input []string
21-
expected_output bool
20+
input []string
21+
shouldError bool
2222
}

0 commit comments

Comments
 (0)