From 48d3250f1636f39cba449cf3ddf17bd5e8206582 Mon Sep 17 00:00:00 2001 From: ProgHaj Date: Fri, 20 Oct 2023 13:52:27 +0200 Subject: [PATCH] Fix failing tests --- .../callgraph/language/java11/strategy_test.go | 18 ++++++++++++++++++ internal/callgraph/scheduler.go | 2 +- internal/cmd/root/root_test.go | 4 ++-- internal/file/exclusion_test.go | 4 ++-- internal/resolution/scheduler.go | 2 -- internal/tui/spinner_manager_test.go | 2 -- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/internal/callgraph/language/java11/strategy_test.go b/internal/callgraph/language/java11/strategy_test.go index 0f07ddc1..d95b58d9 100644 --- a/internal/callgraph/language/java11/strategy_test.go +++ b/internal/callgraph/language/java11/strategy_test.go @@ -1,12 +1,14 @@ package java import ( + "fmt" "path/filepath" "testing" ctxTestdata "github.com/debricked/cli/internal/callgraph/cgexec/testdata" "github.com/debricked/cli/internal/callgraph/config" "github.com/debricked/cli/internal/callgraph/finder/testdata" + javaTestdata "github.com/debricked/cli/internal/callgraph/language/java11/testdata" "github.com/stretchr/testify/assert" ) @@ -84,3 +86,19 @@ func TestInvokeManyFilesWCorrectFilters(t *testing.T) { } } + +func TestBuildProjectsError(t *testing.T) { + conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, false, "maven") + finder := testdata.NewEmptyFinderMock() + testFiles := []string{"file-1", "file-2", "file-3"} + finder.FindMavenRootsNames = []string{"file-3/pom.xml"} + finder.FindJavaClassDirsNames = []string{"file-3/test.class"} + ctx, _ := ctxTestdata.NewContextMock() + s := NewStrategy(conf, testFiles, testFiles, []string{"test"}, finder, ctx) + factoryMock := javaTestdata.NewEchoCmdFactory() + factoryMock.BuildMavenErr = fmt.Errorf("build-error") + s.cmdFactory = factoryMock + err := buildProjects(s, []string{"file-3/pom.xml"}) + + assert.NotNil(t, err) +} diff --git a/internal/callgraph/scheduler.go b/internal/callgraph/scheduler.go index 51408a3b..0d655851 100644 --- a/internal/callgraph/scheduler.go +++ b/internal/callgraph/scheduler.go @@ -40,7 +40,7 @@ func (scheduler *Scheduler) Schedule(jobs []job.IJob, ctx cgexec.IContext) (IGen scheduler.spinnerManager.Start() for _, j := range jobs { - spinner := scheduler.spinnerManager.AddSpinner(callgraph, j.GetDir()) + spinner := scheduler.spinnerManager.AddSpinner(j.GetDir()) scheduler.queue <- queueItem{ job: j, spinner: spinner, diff --git a/internal/cmd/root/root_test.go b/internal/cmd/root/root_test.go index ca4fb6e0..38914922 100644 --- a/internal/cmd/root/root_test.go +++ b/internal/cmd/root/root_test.go @@ -11,7 +11,7 @@ import ( func TestNewRootCmd(t *testing.T) { cmd := NewRootCmd("v0.0.0", wire.GetCliContainer()) commands := cmd.Commands() - nbrOfCommands := 5 + nbrOfCommands := 6 if len(commands) != nbrOfCommands { t.Errorf("failed to assert that there were %d sub commands connected", nbrOfCommands) } @@ -31,7 +31,7 @@ func TestNewRootCmd(t *testing.T) { } } assert.Truef(t, match, "failed to assert that flag was present: "+AccessTokenFlag) - assert.Len(t, viperKeys, 13) + assert.Len(t, viperKeys, 14) } func TestPreRun(t *testing.T) { diff --git a/internal/file/exclusion_test.go b/internal/file/exclusion_test.go index 32321cd7..4ed426b8 100644 --- a/internal/file/exclusion_test.go +++ b/internal/file/exclusion_test.go @@ -114,7 +114,7 @@ func TestExclude(t *testing.T) { { name: "FileExclusionWithDoublestar", exclusions: []string{"**/composer.json"}, - expectedExclusions: []string{"composer.json"}, + expectedExclusions: []string{"composer.json", "composer.json"}, // Two composer.json files in testdata folder }, { name: "DirectoryExclusion", @@ -129,7 +129,7 @@ func TestExclude(t *testing.T) { { name: "ExtensionExclusionWithWildcardAndDoublestar", exclusions: []string{"**/*.mod"}, - expectedExclusions: []string{"go.mod"}, + expectedExclusions: []string{"go.mod", "go.mod"}, // Two go.mod files in testdata folder }, { name: "DirectoryExclusionWithDoublestar", diff --git a/internal/resolution/scheduler.go b/internal/resolution/scheduler.go index b699030d..6d2bb895 100644 --- a/internal/resolution/scheduler.go +++ b/internal/resolution/scheduler.go @@ -25,8 +25,6 @@ type Scheduler struct { spinnerManager tui.ISpinnerManager } -const resolving = "Resolving" - func NewScheduler(workers int) *Scheduler { return &Scheduler{workers: workers, waitGroup: sync.WaitGroup{}} } diff --git a/internal/tui/spinner_manager_test.go b/internal/tui/spinner_manager_test.go index 6beaef9d..f1e8aaed 100644 --- a/internal/tui/spinner_manager_test.go +++ b/internal/tui/spinner_manager_test.go @@ -9,8 +9,6 @@ import ( "github.com/stretchr/testify/assert" ) -const resolving = "Resolving" - func TestNewSpinnerManager(t *testing.T) { spinnerManager := NewSpinnerManager( "Resolving",