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

Commit 83e6720

Browse files
committed
Run tests in parallel, dont use working dir
This changes the CloudPrepper to not store intermediate artifacts in the current directory, allowing the tests to be ran in parallel.
1 parent f024fad commit 83e6720

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

cmd/analyze.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ func analyzeImage(imageArg string, analyzerArgs []string) error {
9494
outputResults(analyses)
9595

9696
if save {
97-
dir, _ := os.Getwd()
98-
glog.Infof("Image was saved at %s as %s", dir, image.FSPath)
97+
glog.Infof("Image was saved at %s", image.FSPath)
9998
}
10099

101100
return nil

cmd/diff.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
110110
outputResults(diffs)
111111

112112
if save {
113-
dir, _ := os.Getwd()
114-
glog.Infof("Images were saved at %s as %s and %s", dir, imageMap[image1Arg].FSPath,
113+
glog.Infof("Images were saved at %s and %s", imageMap[image1Arg].FSPath,
115114
imageMap[image2Arg].FSPath)
116115

117116
}

tests/integration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func TestDiffAndAnalysis(t *testing.T) {
162162
}
163163
for _, test := range tests {
164164
t.Run(test.description, func(t *testing.T) {
165+
t.Parallel()
165166
args := []string{test.subcommand, test.imageA}
166167
if test.imageB != "" {
167168
args = append(args, test.imageB)

utils/image_prep_utils.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ func (p CloudPrepper) getFileSystem() (string, error) {
128128
URLPattern := regexp.MustCompile("^.+/(.+(:.+){0,1})$")
129129
URLMatch := URLPattern.FindStringSubmatch(p.Source)
130130
// Removing the ":" so that the image path name can be <image><tag>
131-
path := strings.Replace(URLMatch[1], ":", "", -1)
131+
sanitizedName := strings.Replace(URLMatch[1], ":", "", -1)
132+
133+
path, err := ioutil.TempDir("", sanitizedName)
134+
if err != nil {
135+
return "", err
136+
}
137+
132138
ref, err := docker.ParseReference("//" + p.Source)
133139
if err != nil {
134140
return "", err
@@ -156,10 +162,6 @@ func (p CloudPrepper) getFileSystem() (string, error) {
156162
return "", err
157163
}
158164

159-
if _, ok := os.Stat(path); ok != nil {
160-
os.MkdirAll(path, 0777)
161-
}
162-
163165
for _, b := range img.LayerInfos() {
164166
bi, _, err := imgSrc.GetBlob(b)
165167
if err != nil {

0 commit comments

Comments
 (0)