From d04af36a7d1e4a4e790670d47f69522579e43706 Mon Sep 17 00:00:00 2001 From: Philipp Heuer Date: Mon, 22 Apr 2024 00:47:56 +0200 Subject: [PATCH] perf: update fs utils to use fastwalk --- analyzer.go | 10 +++--- analyzer/cargo/cargo_test.go | 3 +- analyzer/composer/composer_test.go | 3 +- analyzer/container/container.go | 4 +-- analyzer/dotnet/dotnet_test.go | 3 +- analyzer/gomod/gomod.go | 5 ++- analyzer/gradle/gradle_test.go | 5 ++- analyzer/helm/helm_test.go | 4 +-- analyzer/hugo/hugo.go | 5 ++- analyzer/hugo/hugo_test.go | 4 +-- analyzer/maven/maven_test.go | 3 +- analyzer/mkdocs/mkdocs_test.go | 5 ++- analyzer/node/node_test.go | 4 +-- analyzer/python/python_test.go | 9 +++--- analyzerapi/test.go | 16 +++++++++ analyzerapi/types.go | 6 ++-- analyzerapi/util.go | 49 +++++++--------------------- go.mod | 8 +++-- go.sum | 12 ++++--- renovate.json | 3 +- util/filesystem.go | 52 ------------------------------ 21 files changed, 71 insertions(+), 142 deletions(-) create mode 100644 analyzerapi/test.go delete mode 100644 util/filesystem.go diff --git a/analyzer.go b/analyzer.go index 31e59a4..17cfa92 100644 --- a/analyzer.go +++ b/analyzer.go @@ -61,17 +61,17 @@ func AnalyzeProject(projectDir string, path string) []*analyzerapi.ProjectModule func initAnalyzers() { analyzerapi.Analyzers = append(analyzerapi.Analyzers, + cargo.Analyzer{}, + composer.Analyzer{}, container.Analyzer{}, + dotnet.Analyzer{}, gomod.Analyzer{}, gradle.Analyzer{}, - maven.Analyzer{}, helm.Analyzer{}, hugo.Analyzer{}, + maven.Analyzer{}, + mkdocs.Analyzer{}, node.Analyzer{}, python.Analyzer{}, - mkdocs.Analyzer{}, - dotnet.Analyzer{}, - composer.Analyzer{}, - cargo.Analyzer{}, ) } diff --git a/analyzer/cargo/cargo_test.go b/analyzer/cargo/cargo_test.go index 67a33ba..5369fc4 100644 --- a/analyzer/cargo/cargo_test.go +++ b/analyzer/cargo/cargo_test.go @@ -4,12 +4,11 @@ import ( "testing" "github.com/cidverse/repoanalyzer/analyzerapi" - "github.com/cidverse/repoanalyzer/util" "github.com/stretchr/testify/assert" ) func TestAnalyzer_AnalyzeCargo(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "cargo")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "cargo")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzer/composer/composer_test.go b/analyzer/composer/composer_test.go index 16fb9e4..408f274 100644 --- a/analyzer/composer/composer_test.go +++ b/analyzer/composer/composer_test.go @@ -4,12 +4,11 @@ import ( "testing" "github.com/cidverse/repoanalyzer/analyzerapi" - "github.com/cidverse/repoanalyzer/util" "github.com/stretchr/testify/assert" ) func TestAnalyzer_AnalyzeComposer(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "composer")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "composer")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzer/container/container.go b/analyzer/container/container.go index bfb1243..03347fb 100644 --- a/analyzer/container/container.go +++ b/analyzer/container/container.go @@ -4,7 +4,7 @@ import ( "path/filepath" "strings" - "github.com/cidverse/repoanalyzer/util" + "github.com/cidverse/cidverseutils/filesystem" "github.com/rs/zerolog/log" "golang.org/x/exp/slices" @@ -57,7 +57,7 @@ func (a Analyzer) Analyze(ctx analyzerapi.AnalyzerContext) []*analyzerapi.Projec filename := filepath.Base(file) if strings.HasSuffix(filename, ".sh") { - content, contentErr := util.GetFileContent(file) + content, contentErr := filesystem.GetFileContent(file) if contentErr != nil { log.Warn().Str("file", file).Msg("failed to read file content") } else if strings.Contains(content, "buildah from") { diff --git a/analyzer/dotnet/dotnet_test.go b/analyzer/dotnet/dotnet_test.go index fd812f1..3c490bd 100644 --- a/analyzer/dotnet/dotnet_test.go +++ b/analyzer/dotnet/dotnet_test.go @@ -4,12 +4,11 @@ import ( "testing" "github.com/cidverse/repoanalyzer/analyzerapi" - "github.com/cidverse/repoanalyzer/util" "github.com/stretchr/testify/assert" ) func TestAnalyzer_AnalyzeVisualStudioSolution(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "dotnet")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "dotnet")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzer/gomod/gomod.go b/analyzer/gomod/gomod.go index c6cee9a..2c06b92 100644 --- a/analyzer/gomod/gomod.go +++ b/analyzer/gomod/gomod.go @@ -3,8 +3,7 @@ package gomod import ( "path/filepath" - "github.com/cidverse/repoanalyzer/util" - + "github.com/cidverse/cidverseutils/filesystem" "github.com/cidverse/repoanalyzer/analyzerapi" "github.com/gosimple/slug" "golang.org/x/mod/modfile" @@ -25,7 +24,7 @@ func (a Analyzer) Analyze(ctx analyzerapi.AnalyzerContext) []*analyzerapi.Projec // detect build system syntax if filename == "go.mod" { // parse go.mod - contentBytes, contentReadErr := util.GetFileBytes(file) + contentBytes, contentReadErr := filesystem.GetFileBytes(file) if contentReadErr != nil { continue } diff --git a/analyzer/gradle/gradle_test.go b/analyzer/gradle/gradle_test.go index fc9aca5..27a8162 100644 --- a/analyzer/gradle/gradle_test.go +++ b/analyzer/gradle/gradle_test.go @@ -5,13 +5,12 @@ import ( "testing" "github.com/cidverse/repoanalyzer/analyzerapi" - "github.com/cidverse/repoanalyzer/util" "github.com/stretchr/testify/assert" ) func TestGradleAnalyzer_AnalyzeGroovy(t *testing.T) { _ = os.Setenv("REPOANAYLZER_DEBUG", "true") - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "gradle-groovy")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "gradle-groovy")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) @@ -40,7 +39,7 @@ func TestGradleAnalyzer_AnalyzeGroovy(t *testing.T) { func TestGradleAnalyzer_AnalyzeKotlin(t *testing.T) { _ = os.Setenv("REPOANAYLZER_DEBUG", "true") - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "gradle-kotlin")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "gradle-kotlin")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzer/helm/helm_test.go b/analyzer/helm/helm_test.go index fd53167..5be0b65 100644 --- a/analyzer/helm/helm_test.go +++ b/analyzer/helm/helm_test.go @@ -3,14 +3,12 @@ package helm import ( "testing" - "github.com/cidverse/repoanalyzer/util" - "github.com/cidverse/repoanalyzer/analyzerapi" "github.com/stretchr/testify/assert" ) func TestAnalyzer_AnalyzeHugo(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "helm")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "helm")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzer/hugo/hugo.go b/analyzer/hugo/hugo.go index 8c5544b..34a11e1 100644 --- a/analyzer/hugo/hugo.go +++ b/analyzer/hugo/hugo.go @@ -3,8 +3,7 @@ package hugo import ( "path/filepath" - "github.com/cidverse/repoanalyzer/util" - + "github.com/cidverse/cidverseutils/filesystem" "github.com/cidverse/repoanalyzer/analyzerapi" "github.com/gosimple/slug" ) @@ -23,7 +22,7 @@ func (a Analyzer) Analyze(ctx analyzerapi.AnalyzerContext) []*analyzerapi.Projec filename := filepath.Base(file) if filename == "config.toml" || filename == "config.yaml" { hugoDir := filepath.Dir(file) - if util.DirectoryExists(filepath.Join(hugoDir, "content")) { + if filesystem.DirectoryExists(filepath.Join(hugoDir, "content")) { // module module := analyzerapi.ProjectModule{ RootDirectory: ctx.ProjectDir, diff --git a/analyzer/hugo/hugo_test.go b/analyzer/hugo/hugo_test.go index 07e3d67..5b958c9 100644 --- a/analyzer/hugo/hugo_test.go +++ b/analyzer/hugo/hugo_test.go @@ -3,14 +3,12 @@ package hugo import ( "testing" - "github.com/cidverse/repoanalyzer/util" - "github.com/cidverse/repoanalyzer/analyzerapi" "github.com/stretchr/testify/assert" ) func TestAnalyzer_AnalyzeHugo(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "hugo")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "hugo")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzer/maven/maven_test.go b/analyzer/maven/maven_test.go index 09b2f13..8de514a 100644 --- a/analyzer/maven/maven_test.go +++ b/analyzer/maven/maven_test.go @@ -4,12 +4,11 @@ import ( "testing" "github.com/cidverse/repoanalyzer/analyzerapi" - "github.com/cidverse/repoanalyzer/util" "github.com/stretchr/testify/assert" ) func TestAnalyzer_AnalyzeMaven(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "maven")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "maven")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzer/mkdocs/mkdocs_test.go b/analyzer/mkdocs/mkdocs_test.go index 31b2cd7..0898b5a 100644 --- a/analyzer/mkdocs/mkdocs_test.go +++ b/analyzer/mkdocs/mkdocs_test.go @@ -4,12 +4,11 @@ import ( "testing" "github.com/cidverse/repoanalyzer/analyzerapi" - "github.com/cidverse/repoanalyzer/util" "github.com/stretchr/testify/assert" ) func TestAnalyzer_AnalyzeMkdocs(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "mkdocs")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "mkdocs")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) @@ -27,7 +26,7 @@ func TestAnalyzer_AnalyzeMkdocs(t *testing.T) { } func TestAnalyzer_AnalyzeTechdocs(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "techdocs")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "techdocs")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzer/node/node_test.go b/analyzer/node/node_test.go index fd2aa60..794b5f3 100644 --- a/analyzer/node/node_test.go +++ b/analyzer/node/node_test.go @@ -3,13 +3,11 @@ package node import ( "testing" - "github.com/cidverse/repoanalyzer/util" - "github.com/cidverse/repoanalyzer/analyzerapi" ) func TestAnalyzer_AnalyzeReact(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "react")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "react")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzer/python/python_test.go b/analyzer/python/python_test.go index 4fa335c..ca34ad7 100644 --- a/analyzer/python/python_test.go +++ b/analyzer/python/python_test.go @@ -3,14 +3,13 @@ package python import ( "testing" - "github.com/cidverse/repoanalyzer/util" "github.com/stretchr/testify/assert" "github.com/cidverse/repoanalyzer/analyzerapi" ) func TestAnalyzer_AnalyzePythonPipfile(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "python-pipfile")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "python-pipfile")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) @@ -27,7 +26,7 @@ func TestAnalyzer_AnalyzePythonPipfile(t *testing.T) { } func TestAnalyzer_AnalyzePythonPeotry(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "python-poetry")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "python-poetry")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) @@ -44,7 +43,7 @@ func TestAnalyzer_AnalyzePythonPeotry(t *testing.T) { } func TestAnalyzer_AnalyzePythonRequirementsTXT(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "python-requirementstxt")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "python-requirementstxt")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) @@ -61,7 +60,7 @@ func TestAnalyzer_AnalyzePythonRequirementsTXT(t *testing.T) { } func TestAnalyzer_AnalyzePythonSetuppy(t *testing.T) { - ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "python-setuppy")) + ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "python-setuppy")) analyzer := Analyzer{} result := analyzer.Analyze(ctx) diff --git a/analyzerapi/test.go b/analyzerapi/test.go new file mode 100644 index 0000000..d151d1a --- /dev/null +++ b/analyzerapi/test.go @@ -0,0 +1,16 @@ +package analyzerapi + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func GetTestDataDir(t *testing.T, dir string) string { + cwd, err := os.Getwd() + assert.NoError(t, err) + + return filepath.Join(filepath.Dir(cwd), "..", "testdata", dir) +} diff --git a/analyzerapi/types.go b/analyzerapi/types.go index 4b2b354..3a1d221 100644 --- a/analyzerapi/types.go +++ b/analyzerapi/types.go @@ -121,7 +121,9 @@ type AnalyzerContext struct { // FilesByExtension contains all files by extension FilesByExtension map[string][]string `json:"files_by_extension"` +} - // FilesWithoutExtension contains all files without an extension - FilesWithoutExtension []string `json:"files_without_extension"` +func (ctx *AnalyzerContext) ContainsFile(extension string) bool { + _, ok := ctx.FilesByExtension[extension] + return ok } diff --git a/analyzerapi/util.go b/analyzerapi/util.go index 39f9aeb..8ac6925 100644 --- a/analyzerapi/util.go +++ b/analyzerapi/util.go @@ -1,55 +1,29 @@ package analyzerapi import ( - "io/fs" "os" "path/filepath" "sort" "strings" - "github.com/rs/zerolog/log" + "github.com/cidverse/cidverseutils/filesystem" ignore "github.com/sabhiram/go-gitignore" + "golang.org/x/exp/slog" ) func GetAnalyzerContext(projectDir string) AnalyzerContext { // respect gitignore ignoreMatcher := ProcessIgnoreFiles([]string{filepath.Join(projectDir, ".gitignore"), filepath.Join(projectDir, ".cidignore")}) - // files - var files []string - filesByExtension := make(map[string][]string) - var filesWithoutExtension []string - - err := filepath.WalkDir(projectDir, func(path string, d fs.DirEntry, err error) error { - // check for directory skip - if err != nil { - log.Warn().Err(err).Str("path", projectDir).Msg("output") - return nil - } - - if d.IsDir() { - if d.Name() == ".git" || ignoreMatcher.MatchesPath(path) { - return filepath.SkipDir - } - } else { - if ignoreMatcher.MatchesPath(path) { - return nil - } - - files = append(files, path) - splitByExt := strings.SplitN(d.Name(), ".", 2) - if len(splitByExt) == 2 { - filesByExtension[splitByExt[1]] = append(filesByExtension[splitByExt[1]], path) - } else { - filesWithoutExtension = append(filesWithoutExtension, path) - } - } - - return nil + files, err := filesystem.FindFiles(projectDir, func(absPath string, name string) bool { + return ignoreMatcher.MatchesPath(absPath) + }, func(absPath string, name string) bool { + return true }) if err != nil { - log.Fatal().Err(err).Str("path", projectDir).Msg("failed to get directory list") + slog.Error("failed to get directory list", err, slog.String("path", projectDir)) } + filesByExtension := filesystem.GenerateFileMapByDeepExtension(files) // sorting sort.Slice(files, func(i, j int) bool { @@ -58,10 +32,9 @@ func GetAnalyzerContext(projectDir string) AnalyzerContext { // result return AnalyzerContext{ - ProjectDir: projectDir, - Files: files, - FilesByExtension: filesByExtension, - FilesWithoutExtension: filesWithoutExtension, + ProjectDir: projectDir, + Files: files, + FilesByExtension: filesByExtension, } } diff --git a/go.mod b/go.mod index a20ece9..0d48460 100644 --- a/go.mod +++ b/go.mod @@ -1,23 +1,25 @@ module github.com/cidverse/repoanalyzer -go 1.21 +go 1.22 require ( + github.com/cidverse/cidverseutils/filesystem v0.0.0-20240421215032-ae9bd53b804a github.com/gosimple/slug v1.14.0 github.com/pelletier/go-toml/v2 v2.2.1 github.com/rs/zerolog v1.32.0 github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 github.com/stretchr/testify v1.9.0 - golang.org/x/exp v0.0.0-20240119083558-1b970713d09a + golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f golang.org/x/mod v0.17.0 ) require ( + github.com/charlievieth/fastwalk v1.0.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/gosimple/unidecode v1.0.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/sys v0.19.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 22e6da0..6f1ec64 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,7 @@ +github.com/charlievieth/fastwalk v1.0.3 h1:eNWFaNPe5srPqQ5yyDbhAf11paeZaHWcihRhpuYFfSg= +github.com/charlievieth/fastwalk v1.0.3/go.mod h1:JSfglY/gmL/rqsUS1NCsJTocB5n6sSl9ApAqif4CUbs= +github.com/cidverse/cidverseutils/filesystem v0.0.0-20240421215032-ae9bd53b804a h1:rBIgcVyG/fjja6fV75IMrxYOhmfB757mWBhC4J2uGh0= +github.com/cidverse/cidverseutils/filesystem v0.0.0-20240421215032-ae9bd53b804a/go.mod h1:yHvwdbkDXUiQweTWYyEwhGc7xJSRcRnQzsQBu7xQxUs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -33,15 +37,15 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA= -golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= +golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY= +golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/renovate.json b/renovate.json index 78c53b2..e2b0940 100644 --- a/renovate.json +++ b/renovate.json @@ -6,8 +6,7 @@ ], "baseBranches": ["main"], "ignorePaths": [ - ".github/workflows/cid.yml", - ".github/workflows/cid-pullrequest.yml", + ".github/workflows/cid**", "**/testdata/**", "**/examples/**" ] diff --git a/util/filesystem.go b/util/filesystem.go deleted file mode 100644 index d2d480e..0000000 --- a/util/filesystem.go +++ /dev/null @@ -1,52 +0,0 @@ -package util - -import ( - "errors" - "github.com/stretchr/testify/assert" - "os" - "path/filepath" - "testing" -) - -func GetTestDataDir(t *testing.T, dir string) string { - cwd, err := os.Getwd() - assert.NoError(t, err) - - return filepath.Join(filepath.Dir(cwd), "..", "testdata", dir) -} - -// GetFileBytes will retrieve the content of a file as bytes -func GetFileBytes(file string) ([]byte, error) { - if _, err := os.Stat(file); !os.IsNotExist(err) { - fileBytes, fileErr := os.ReadFile(file) - if fileErr == nil { - return fileBytes, nil - } - return nil, err - } - - return nil, errors.New("file does not exist") -} - -// GetFileContent will retrieve the content of a file as text -func GetFileContent(file string) (string, error) { - if _, err := os.Stat(file); !os.IsNotExist(err) { - fileBytes, fileErr := os.ReadFile(file) - if fileErr == nil { - return string(fileBytes), nil - } - return "", err - } - - return "", errors.New("file does not exist") -} - -// DirectoryExists checks if the dir exists -func DirectoryExists(dir string) bool { - info, err := os.Stat(dir) - if err != nil { - return false - } - - return info.IsDir() -}