Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

improve detection #105

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 0 additions & 113 deletions pkg/scanner/frameworks.go

This file was deleted.

109 changes: 0 additions & 109 deletions pkg/scanner/runtimes.go

This file was deleted.

18 changes: 9 additions & 9 deletions pkg/scanner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@ import (
)

func Scan(sourceDir string) ([]*shared.Micro, error) {
files, err := os.ReadDir(sourceDir)
if err != nil {
return nil, err
}

var micros []*shared.Micro

// scan root source dir for a micro
m, err := scanDir(sourceDir)
if err != nil {
return nil, err
}

if m != nil {
// root folder has a micro return as a single micro app
micros = append(micros, m)
return micros, nil
}

// scan subfolders for micros
for _, file := range files {
if file.IsDir() {
m, err = scanDir(filepath.Join(sourceDir, file.Name()))
entries, err := os.ReadDir(sourceDir)
if err != nil {
return nil, err
}

for _, entry := range entries {
if entry.IsDir() {
m, err = scanDir(filepath.Join(sourceDir, entry.Name()))
if err != nil {
return nil, err
}
Expand All @@ -49,6 +48,7 @@ func scanDir(dir string) (*shared.Micro, error) {
pythonScanner,
nodeScanner,
goScanner,
rustScanner,
staticScanner,
}

Expand Down
17 changes: 6 additions & 11 deletions pkg/scanner/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type ScanTestInfo struct {
ExpectedEngine string
}

var (
microsTestInfo = []ScanTestInfo{
func TestScanSingleMicroProjects(t *testing.T) {
microsTestInfo := []ScanTestInfo{
{Name: "python", Path: "testdata/micros/python", ExpectedEngine: shared.Python39},
{Name: "go", Path: "testdata/micros/go", ExpectedEngine: shared.Custom},
{Name: "next", Path: "testdata/micros/next", ExpectedEngine: shared.Next},
Expand All @@ -27,9 +27,7 @@ var (
{Name: "svelte-kit", Path: "testdata/micros/svelte-kit", ExpectedEngine: shared.SvelteKit},
{Name: "vue", Path: "testdata/micros/vue", ExpectedEngine: shared.Vue},
}
)

func TestScanSingleMicroProjects(t *testing.T) {
for _, project := range microsTestInfo {
t.Run(project.Path, func(t *testing.T) {
micros, err := Scan(project.Path)
Expand All @@ -44,7 +42,6 @@ func TestScanSingleMicroProjects(t *testing.T) {
}

func TestScanMultiMicroProject(t *testing.T) {

expectedMicros := []string{"python", "go", "next", "node", "nuxt", "react", "static", "svelte", "svelte-kit", "vue"}
expectedMicrosToEngines := map[string]string{
"python": shared.Python39,
Expand All @@ -69,12 +66,10 @@ func TestScanMultiMicroProject(t *testing.T) {
assert.Equal(t, len(micros), len(expectedMicros), "detected %d micros, but expected %d", len(micros), len(expectedMicros))

for _, micro := range micros {
t.Run(micro.Name, func(t *testing.T) {
if !slices.Contains(expectedMicros, micro.Name) {
t.Fatalf("micro %s at %s is detected, but should not be detected as part of a multi-micro project", micro.Name, micro.Src)
}
assert.Equal(t, micro.Engine, expectedMicrosToEngines[micro.Name], "detected engine for micro %s as %s, but expected %s", micro.Name, micro.Engine, expectedMicrosToEngines[micro.Name])
})
if !slices.Contains(expectedMicros, micro.Name) {
t.Fatalf("micro %s at %s is detected, but should not be detected as part of a multi-micro project", micro.Name, micro.Src)
}
assert.Equal(t, micro.Engine, expectedMicrosToEngines[micro.Name], "detected engine for micro %s as %s, but expected %s", micro.Name, micro.Engine, expectedMicrosToEngines[micro.Name])
}
}

Expand Down
Loading