Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
fix(arch): replace from AnalysisTarget to AnalysisInput
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n committed Mar 3, 2022
1 parent cc438b9 commit 7caa249
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
6 changes: 3 additions & 3 deletions analyzer/os/archlinux/archlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package archlinux

import (
"bufio"
"bytes"
"context"
"os"
"strings"

Expand All @@ -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") {
Expand Down
10 changes: 7 additions & 3 deletions analyzer/os/archlinux/archlinux_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package archlinux

import (
"context"
"os"
"testing"

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions analyzer/pkg/pacman/pacman.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pacman

import (
"bufio"
"bytes"
"context"
"log"
"os"
"path/filepath"
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
10 changes: 7 additions & 3 deletions analyzer/pkg/pacman/pacman_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pacman

import (
"context"
"os"
"testing"

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 7caa249

Please sign in to comment.