From 6878696efd2d4e85586a7803ba908cd792cb360e Mon Sep 17 00:00:00 2001 From: MaineK00n Date: Mon, 17 Jan 2022 00:05:44 +0900 Subject: [PATCH] fix(arch): replace from AnalysisTarget to AnalysisInput --- analyzer/os/archlinux/archlinux.go | 6 +++--- analyzer/os/archlinux/archlinux_test.go | 10 +++++++--- analyzer/pkg/pacman/pacman.go | 10 +++++----- analyzer/pkg/pacman/pacman_test.go | 10 +++++++--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/analyzer/os/archlinux/archlinux.go b/analyzer/os/archlinux/archlinux.go index 65bab6f76..590e358a2 100644 --- a/analyzer/os/archlinux/archlinux.go +++ b/analyzer/os/archlinux/archlinux.go @@ -2,7 +2,7 @@ package archlinux import ( "bufio" - "bytes" + "context" "os" "strings" @@ -26,8 +26,8 @@ var requiredFiles = []string{ type archlinuxOSAnalyzer struct{} -func (a archlinuxOSAnalyzer) Analyze(target analyzer.AnalysisTarget) (*analyzer.AnalysisResult, error) { - scanner := bufio.NewScanner(bytes.NewBuffer(target.Content)) +func (a archlinuxOSAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) { + scanner := bufio.NewScanner(input.Content) for scanner.Scan() { line := scanner.Text() if strings.HasPrefix(line, "NAME=\"Arch Linux") { diff --git a/analyzer/os/archlinux/archlinux_test.go b/analyzer/os/archlinux/archlinux_test.go index 77ac7fb9e..7cc8c9a7f 100644 --- a/analyzer/os/archlinux/archlinux_test.go +++ b/analyzer/os/archlinux/archlinux_test.go @@ -1,6 +1,7 @@ package archlinux import ( + "context" "os" "testing" @@ -34,12 +35,15 @@ func Test_archlinuxOSAnalyzer_Analyze(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { a := archlinuxOSAnalyzer{} - b, err := os.ReadFile(tt.inputFile) + f, err := os.Open(tt.inputFile) require.NoError(t, err) + defer f.Close() - got, err := a.Analyze(analyzer.AnalysisTarget{ + ctx := context.Background() + + got, err := a.Analyze(ctx, analyzer.AnalysisInput{ FilePath: "etc/os-release", - Content: b, + Content: f, }) if tt.wantErr != "" { require.Error(t, err) diff --git a/analyzer/pkg/pacman/pacman.go b/analyzer/pkg/pacman/pacman.go index 27d0e3c87..354c03af3 100644 --- a/analyzer/pkg/pacman/pacman.go +++ b/analyzer/pkg/pacman/pacman.go @@ -2,7 +2,7 @@ package pacman import ( "bufio" - "bytes" + "context" "log" "os" "path/filepath" @@ -26,9 +26,9 @@ const installDir = "var/lib/pacman/local/" type pacmanAnalyzer struct{} -func (a pacmanAnalyzer) Analyze(target analyzer.AnalysisTarget) (*analyzer.AnalysisResult, error) { - scanner := bufio.NewScanner(bytes.NewBuffer(target.Content)) - dir, fileName := filepath.Split(target.FilePath) +func (a pacmanAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) { + scanner := bufio.NewScanner(input.Content) + dir, fileName := filepath.Split(input.FilePath) if !strings.HasPrefix(dir, installDir) { return nil, nil } @@ -39,7 +39,7 @@ func (a pacmanAnalyzer) Analyze(target analyzer.AnalysisTarget) (*analyzer.Analy } return &analyzer.AnalysisResult{ PackageInfos: []types.PackageInfo{ - {FilePath: target.FilePath, Packages: []types.Package{pkg}}, + {FilePath: input.FilePath, Packages: []types.Package{pkg}}, }, }, nil } diff --git a/analyzer/pkg/pacman/pacman_test.go b/analyzer/pkg/pacman/pacman_test.go index 2c98a4819..920b622d1 100644 --- a/analyzer/pkg/pacman/pacman_test.go +++ b/analyzer/pkg/pacman/pacman_test.go @@ -1,6 +1,7 @@ package pacman import ( + "context" "os" "testing" @@ -204,13 +205,16 @@ func Test_pacmanAnalyzer_Analyze(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - b, err := os.ReadFile(tt.testFile) + f, err := os.Open(tt.testFile) require.NoError(t, err) + defer f.Close() + + ctx := context.Background() a := pacmanAnalyzer{} - got, err := a.Analyze(analyzer.AnalysisTarget{ + got, err := a.Analyze(ctx, analyzer.AnalysisInput{ FilePath: tt.filepath, - Content: b, + Content: f, }) require.NoError(t, err)