Skip to content

Commit

Permalink
Fix an issue where the zipping tool was looking in root instead of th…
Browse files Browse the repository at this point in the history
…e real location of the call graph.
  • Loading branch information
Duppils authored and ProgHaj committed Jun 13, 2023
1 parent 7650598 commit e4ffeba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
10 changes: 6 additions & 4 deletions internal/callgraph/language/java11/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,27 @@ func (j *Job) runCallGraph(callgraph ICallgraph) {
}

func (j *Job) runPostProcess() {
outputNameZip := outputName + ".zip"
workingDirectory := j.GetDir()
outputFullPath := path.Join(workingDirectory, outputName)
outputFullPathZip := outputFullPath + ".zip"
j.SendStatus("zipping callgraph")
err := j.archive.ZipFile(outputName, outputNameZip)
err := j.archive.ZipFile(outputFullPath, outputFullPathZip)
if err != nil {
j.Errors().Critical(err)

return
}

j.SendStatus("base64 encoding zipped callgraph")
err = j.archive.B64(outputNameZip, outputName)
err = j.archive.B64(outputFullPathZip, outputFullPath)
if err != nil {
j.Errors().Critical(err)

return
}

j.SendStatus("cleanup")
err = j.archive.Cleanup(outputNameZip)
err = j.archive.Cleanup(outputFullPathZip)
if err != nil {
e, ok := err.(*os.PathError)
if ok && e.Err == syscall.ENOENT {
Expand Down
21 changes: 20 additions & 1 deletion internal/callgraph/language/java11/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestRunPostProcessMock(t *testing.T) {

fs := ioTestData.FileSystemMock{}
zip := ioTestData.ZipMock{}
archiveMock := io.NewArchiveWithStructs("dir", fs, zip)
archiveMock := io.NewArchiveWithStructs(dir, fs, zip)

j := NewJob(dir, files, cmdFactoryMock, fileWriterMock, archiveMock, config, ctx)
go jobTestdata.WaitStatus(j)
Expand Down Expand Up @@ -190,3 +190,22 @@ func TestRunPostProcessCleanupNoFileExistError(t *testing.T) {

assert.False(t, j.Errors().HasError())
}

func TestRunPostProcessFromRoot(t *testing.T) {
fileWriterMock := &ioTestData.FileWriterMock{}
cmdFactoryMock := testdata.NewEchoCmdFactory()
config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven")
ctx, _ := ctxTestdata.NewContextMock()

err := &os.PathError{}
err.Err = syscall.ENOENT
archiveMock := ioTestData.ArchiveMock{PathError: err, Dir: "."}

j := NewJob(dir, files, cmdFactoryMock, fileWriterMock, archiveMock, config, ctx)
go jobTestdata.WaitStatus(j)
j.runPostProcess()

jobErrors := j.Errors().GetAll()
assert.True(t, jobErrors[0] == err)

}
7 changes: 7 additions & 0 deletions internal/io/testdata/archive_mock.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package testdata

import "strings"

type ArchiveMock struct {
ZipFileError error
B64Error error
CleanupError error
PathError error
Dir string
}

func (am ArchiveMock) ZipFile(sourceName string, targetName string) error {
if !strings.HasPrefix(sourceName, am.Dir) || !strings.HasPrefix(targetName, am.Dir) {
return am.PathError
}
return am.ZipFileError

}
Expand Down

0 comments on commit e4ffeba

Please sign in to comment.