-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
222 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package finder | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFindMavenRoots(t *testing.T) { | ||
|
||
files := []string{"test/asd/pom.xml", "test2/pom.xml", "test2/test/asd/pom.xml", "test3/tes"} | ||
f := Finder{} | ||
roots, err := f.FindMavenRoots(files) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, roots, 0) | ||
} | ||
|
||
func TestFindJavaClassDirs(t *testing.T) { | ||
files := []string{"test/asd/pom.xml", "test2/basd/qwe/asd.class", "test2/test/asd", "test3/tes"} | ||
f := Finder{} | ||
files, err := f.FindJavaClassDirs(files) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, files, 1) | ||
assert.Equal(t, files[0], "test2/basd/qwe") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package finder | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFindFiles(t *testing.T) { | ||
files, err := FindFiles([]string{"."}, nil) | ||
assert.Nil(t, err) | ||
assert.NotEmpty(t, files) | ||
} | ||
|
||
func TestFindFilesErr(t *testing.T) { | ||
files, err := FindFiles([]string{"totaly-not-a-valid-path-123123123"}, nil) | ||
assert.NotNil(t, err) | ||
assert.Empty(t, files) | ||
} | ||
|
||
func TestConvertPathsToAbsPaths(t *testing.T) { | ||
before := "321" | ||
files, err := ConvertPathsToAbsPaths([]string{before}) | ||
after := files[0] | ||
assert.Nil(t, err) | ||
assert.True(t, len(before) < len(after)) | ||
} | ||
|
||
func TestMapFilesToDir(t *testing.T) { | ||
|
||
dirs := []string{"test/", "test2/"} | ||
files := []string{"test/asd", "test2/basd/qwe", "test2/test/asd", "test3/tes"} | ||
mapFiles := MapFilesToDir(dirs, files) | ||
|
||
assert.Len(t, mapFiles["test/"], 1) | ||
assert.Len(t, mapFiles["test2/"], 2) | ||
} | ||
|
||
func TestMapFilesToEmptyDir(t *testing.T) { | ||
|
||
dirs := []string{} | ||
files := []string{"test/asd", "test2/basd/qwe", "test2/test/asd", "test3/tes"} | ||
mapFiles := MapFilesToDir(dirs, files) | ||
|
||
assert.Empty(t, mapFiles) | ||
} | ||
|
||
func TestGCDPath(t *testing.T) { | ||
files := []string{"test2/bas", "test2/basd/qwe", "test2/test/asd"} | ||
res := GCDPath(files) | ||
|
||
assert.Equal(t, res, "test2/") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package tui | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"os" | ||
"testing" | ||
|
||
"github.com/debricked/cli/pkg/callgraph/job" | ||
"github.com/debricked/cli/pkg/callgraph/job/testdata" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewCallgraphJobsErrorList(t *testing.T) { | ||
mirror := os.Stdout | ||
errList := NewCallgraphJobsErrorList(mirror, []job.IJob{}) | ||
assert.NotNil(t, errList) | ||
} | ||
|
||
func TestRenderNoCallgraphJobs(t *testing.T) { | ||
var listBuffer bytes.Buffer | ||
errList := NewCallgraphJobsErrorList(&listBuffer, []job.IJob{}) | ||
|
||
err := errList.Render() | ||
|
||
assert.NoError(t, err) | ||
output := listBuffer.String() | ||
assertOutput(t, output, nil) | ||
} | ||
|
||
func TestRenderWarningCallgraphJob(t *testing.T) { | ||
var listBuffer bytes.Buffer | ||
|
||
warningErr := errors.New("warning-message") | ||
jobMock := testdata.NewJobMock("file", nil) | ||
jobMock.Errors().Warning(warningErr) | ||
errList := NewCallgraphJobsErrorList(&listBuffer, []job.IJob{jobMock}) | ||
|
||
err := errList.Render() | ||
|
||
assert.NoError(t, err) | ||
output := listBuffer.String() | ||
contains := []string{ | ||
"file", | ||
"\n* ", | ||
"Warning", | ||
"|", | ||
"warning-message\n", | ||
} | ||
assertOutput(t, output, contains) | ||
} | ||
|
||
func TestRenderCriticalCallgraphJob(t *testing.T) { | ||
var listBuffer bytes.Buffer | ||
|
||
warningErr := errors.New("critical-message") | ||
jobMock := testdata.NewJobMock("file", nil) | ||
jobMock.Errors().Critical(warningErr) | ||
errList := NewCallgraphJobsErrorList(&listBuffer, []job.IJob{jobMock}) | ||
|
||
err := errList.Render() | ||
|
||
assert.NoError(t, err) | ||
output := listBuffer.String() | ||
contains := []string{ | ||
"file", | ||
"\n* ", | ||
"Critical", | ||
"|", | ||
"critical-message\n", | ||
} | ||
assertOutput(t, output, contains) | ||
} | ||
|
||
func TestRenderCriticalAndWarningCallgraphJob(t *testing.T) { | ||
var listBuffer bytes.Buffer | ||
|
||
jobMock := testdata.NewJobMock("manifest-file", nil) | ||
|
||
warningErr := errors.New("warning-message") | ||
jobMock.Errors().Warning(warningErr) | ||
|
||
criticalErr := errors.New("critical-message") | ||
jobMock.Errors().Critical(criticalErr) | ||
|
||
errList := NewCallgraphJobsErrorList(&listBuffer, []job.IJob{jobMock}) | ||
|
||
err := errList.Render() | ||
|
||
assert.NoError(t, err) | ||
output := listBuffer.String() | ||
contains := []string{ | ||
"manifest-file", | ||
"\n* ", | ||
"Critical", | ||
"critical-message\n", | ||
"Warning", | ||
"|", | ||
"warning-message\n", | ||
} | ||
assertOutput(t, output, contains) | ||
} | ||
|
||
func TestRenderCriticalAndWorkingCallgraphJob(t *testing.T) { | ||
var listBuffer bytes.Buffer | ||
|
||
jobWithErrMock := testdata.NewJobMock("manifest-file", nil) | ||
|
||
criticalErr := errors.New("critical-message") | ||
jobWithErrMock.Errors().Critical(criticalErr) | ||
|
||
jobWorkingMock := testdata.NewJobMock("working-manifest-file", nil) | ||
|
||
errList := NewCallgraphJobsErrorList(&listBuffer, []job.IJob{jobWithErrMock, jobWorkingMock}) | ||
|
||
err := errList.Render() | ||
|
||
assert.NoError(t, err) | ||
output := listBuffer.String() | ||
contains := []string{ | ||
"manifest-file", | ||
"\n* ", | ||
"Critical", | ||
"|", | ||
"critical-message\n", | ||
} | ||
assertOutput(t, output, contains) | ||
|
||
assert.NotContains(t, output, jobWorkingMock) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters