fix(lint): noctx fixes and dead-code cleanup
- install_script_test.go: exec.Command -> exec.CommandContext (noctx) - architecture_test.go, store_test.go: go fix removed now-unused inspectEngineFamilies/parsePackageFiles/stringPtr helpers.
This commit is contained in:
1 parent
536e4bc0d1
commit
0fc20319c7
3 files changed
+6
-58
No files matched your search
@@ -504,6 +504,3 @@ func itoa(n int) string {
|
||||
}
|
||||
return string(buf[i:])
|
||||
}
|
||||
|
||||
//go:fix inline
|
||||
func stringPtr(s string) *string { return new(s) }
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/fs"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -164,58 +163,6 @@ type engineFamily struct {
|
||||
singleOwner bool
|
||||
}
|
||||
|
||||
func inspectEngineFamilies(root string) ([]engineFamily, error) {
|
||||
dirs := make(map[string]struct{})
|
||||
err := filepath.WalkDir(root, func(path string, entry fs.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if entry.IsDir() {
|
||||
dirs[path] = struct{}{}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var families []engineFamily
|
||||
for dir := range dirs {
|
||||
packages, err := parsePackageFiles(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, files := range packages {
|
||||
families = append(families, engineFamiliesInPackage(root, dir, files)...)
|
||||
}
|
||||
}
|
||||
slices.SortFunc(families, func(a, b engineFamily) int {
|
||||
return strings.Compare(a.packagePath+"."+a.engineName, b.packagePath+"."+b.engineName)
|
||||
})
|
||||
return families, nil
|
||||
}
|
||||
|
||||
func parsePackageFiles(dir string) (map[string][]*ast.File, error) {
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
packages := make(map[string][]*ast.File)
|
||||
fileSet := token.NewFileSet()
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".go") || strings.HasSuffix(entry.Name(), "_test.go") {
|
||||
continue
|
||||
}
|
||||
file, err := parser.ParseFile(fileSet, filepath.Join(dir, entry.Name()), nil, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
packages[file.Name.Name] = append(packages[file.Name.Name], file)
|
||||
}
|
||||
return packages, nil
|
||||
}
|
||||
|
||||
func engineFamiliesInPackage(root, dir string, files []*ast.File) []engineFamily {
|
||||
engines := make(map[string]bool)
|
||||
interfaces := make(map[string]*ast.InterfaceType)
|
||||
|
||||
@@ -123,6 +123,8 @@ func TestUpdateWatchdogRollsBackManagedWorkerImageAndReportsOnlyChangedComponent
|
||||
|
||||
func runUpdateInstallScript(t *testing.T, environment map[string]string) (Result, []string) {
|
||||
t.Helper()
|
||||
ctx := t.Context()
|
||||
|
||||
root, err := filepath.Abs(filepath.Join("..", ".."))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -199,7 +201,7 @@ printf '%s\n' "cp $*" >> "$ARCHIE_TEST_CALLS"
|
||||
if err := os.WriteFile(scriptPath, scriptData, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.Command(scriptPath)
|
||||
cmd := exec.CommandContext(ctx, scriptPath)
|
||||
cmd.Env = append(
|
||||
os.Environ(),
|
||||
"PATH="+fakeDir+":"+os.Getenv("PATH"),
|
||||
@@ -254,6 +256,8 @@ func writeFakeCommand(t *testing.T, dir, name, body string) {
|
||||
|
||||
func runUpdateWatchdogFailure(t *testing.T, components string) (Report, string, []string) {
|
||||
t.Helper()
|
||||
ctx := t.Context()
|
||||
|
||||
root, err := filepath.Abs(filepath.Join("..", ".."))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -279,7 +283,7 @@ func runUpdateWatchdogFailure(t *testing.T, components string) (Report, string,
|
||||
writeFakeCommand(t, fakeDir, "docker", `printf '%s\n' "docker $*" >> "$ARCHIE_TEST_CALLS"`)
|
||||
callsPath := filepath.Join(work, "calls")
|
||||
|
||||
cmd := exec.Command(filepath.Join(root, "scripts", "archie-update-watchdog"))
|
||||
cmd := exec.CommandContext(ctx, filepath.Join(root, "scripts", "archie-update-watchdog"))
|
||||
cmd.Env = append(
|
||||
os.Environ(),
|
||||
"PATH="+fakeDir+":"+os.Getenv("PATH"),
|
||||
|
||||
Reference in new issue
Block a user