Skip to content

Commit

Permalink
fix unit test on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
AliDatadog committed Jul 25, 2023
1 parent 3e70a8b commit 95907b5
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/fanal/analyzer/pkg/apk/apk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,29 +402,30 @@ func TestParseApkInfo(t *testing.T) {
wantFiles: files,
},
"do not keep system installed files": {
path: "./testdata/apk",
wantPkgs: pkgs,
wantFiles: files,
path: "./testdata/apk",
keepSystemInstalledFiles: false,
wantPkgs: pkgs,
wantFiles: files,
},
}
a := alpinePkgAnalyzer{}
for testname, v := range tests {
for testname, tt := range tests {
t.Run(testname, func(t *testing.T) {
read, err := os.Open(v.path)
read, err := os.Open(tt.path)
require.NoError(t, err)
scanner := bufio.NewScanner(read)
gotPkgs, gotFiles := a.parseApkInfo(scanner, &analyzer.AnalysisOptions{KeepSystemInstalledFiles: v.keepSystemInstalledFiles})
gotPkgs, gotFiles := a.parseApkInfo(scanner, &analyzer.AnalysisOptions{KeepSystemInstalledFiles: tt.keepSystemInstalledFiles})

// Remove system installed files if necessary
wantPkgs := v.wantPkgs
if !v.keepSystemInstalledFiles {
wantPkgs := tt.wantPkgs
if !tt.keepSystemInstalledFiles {
for i, pkg := range wantPkgs {
pkg.SystemInstalledFiles = nil
wantPkgs[i] = pkg
}
}
assert.Equal(t, v.wantPkgs, gotPkgs)
assert.Equal(t, v.wantFiles, gotFiles)
assert.Equal(t, wantPkgs, gotPkgs)
assert.Equal(t, tt.wantFiles, gotFiles)
})
}
}

0 comments on commit 95907b5

Please sign in to comment.