11package java
22
33import (
4+ "fmt"
45 "testing"
56
67 ioFs "github.com/debricked/cli/internal/io"
@@ -18,15 +19,70 @@ func TestInitializeSootWrapper(t *testing.T) {
1819 assert .NoError (t , err )
1920}
2021
22+ func TestInitializeSootWrapperOpenEmbedError (t * testing.T ) {
23+ errString := "fs open embed error"
24+ fsMock := ioTestData.FileSystemMock {FsOpenEmbedError : fmt .Errorf (errString )}
25+ tempDir , err := fsMock .MkdirTemp (".tmp" )
26+ assert .NoError (t , err )
27+ _ , err = initializeSootWrapper (fsMock , tempDir )
28+ assert .Error (t , err )
29+ assert .Equal (t , err .Error (), errString )
30+ }
31+
32+ func TestInitializeSootWrapperFsReadAllError (t * testing.T ) {
33+ errString := "fs read all error"
34+ fsMock := ioTestData.FileSystemMock {FsReadAllError : fmt .Errorf (errString )}
35+ tempDir , err := fsMock .MkdirTemp (".tmp" )
36+ assert .NoError (t , err )
37+ _ , err = initializeSootWrapper (fsMock , tempDir )
38+ assert .Error (t , err )
39+ assert .Equal (t , err .Error (), errString )
40+ }
41+
42+ func TestInitializeSootWrapperFsWriteFileError (t * testing.T ) {
43+ errString := "fs write file error"
44+ fsMock := ioTestData.FileSystemMock {FsWriteFileError : fmt .Errorf (errString )}
45+ tempDir , err := fsMock .MkdirTemp (".tmp" )
46+ assert .NoError (t , err )
47+ _ , err = initializeSootWrapper (fsMock , tempDir )
48+ assert .Error (t , err )
49+ assert .Equal (t , err .Error (), errString )
50+ }
51+
2152func TestDownloadSootWrapper (t * testing.T ) {
22- fs := ioFs.FileSystem {}
23- dir , _ := fs .MkdirTemp (".test_tmp" )
24- zip := ioFs.Zip {}
25- arc := ioFs .NewArchiveWithStructs (dir , fs , zip )
26- err := downloadSootWrapper (arc , fs , "soot-wrapper.jar" , "11" )
53+ fsMock := ioTestData.FileSystemMock {}
54+ arcMock := ioTestData.ArchiveMock {}
55+ err := downloadSootWrapper (arcMock , fsMock , "soot-wrapper.jar" , "11" )
2756 assert .NoError (t , err , "expected no error for downloading soot-wrapper jar" )
2857}
2958
59+ func TestDownloadSootWrapperMkdirTempError (t * testing.T ) {
60+ errString := "mkdir temp error"
61+ fsMock := ioTestData.FileSystemMock {MkdirTempError : fmt .Errorf (errString )}
62+ arcMock := ioTestData.ArchiveMock {}
63+ err := downloadSootWrapper (arcMock , fsMock , "soot-wrapper.jar" , "11" )
64+ assert .Error (t , err )
65+ assert .Equal (t , err .Error (), errString )
66+ }
67+
68+ func TestDownloadSootWrapperCreateError (t * testing.T ) {
69+ errString := "create error"
70+ fsMock := ioTestData.FileSystemMock {CreateError : fmt .Errorf (errString )}
71+ arcMock := ioTestData.ArchiveMock {}
72+ err := downloadSootWrapper (arcMock , fsMock , "soot-wrapper.jar" , "11" )
73+ assert .Error (t , err )
74+ assert .Equal (t , err .Error (), errString )
75+ }
76+
77+ func TestDownloadSootWrapperUnzipError (t * testing.T ) {
78+ errString := "create error"
79+ fsMock := ioTestData.FileSystemMock {}
80+ arcMock := ioTestData.ArchiveMock {UnzipFileError : fmt .Errorf (errString )}
81+ err := downloadSootWrapper (arcMock , fsMock , "soot-wrapper.jar" , "11" )
82+ assert .Error (t , err )
83+ assert .Equal (t , err .Error (), errString )
84+ }
85+
3086func TestDownloadCompressedSootWrapper (t * testing.T ) {
3187 fs := ioFs.FileSystem {}
3288 dir , err := fs .MkdirTemp (".test_tmp" )
@@ -69,6 +125,11 @@ func TestGetSootWrapper(t *testing.T) {
69125 version : "21" ,
70126 expectError : false ,
71127 },
128+ {
129+ name : "Version not int" ,
130+ version : "akjwdm" ,
131+ expectError : true ,
132+ },
72133 }
73134
74135 for _ , tt := range tests {
@@ -85,3 +146,29 @@ func TestGetSootWrapper(t *testing.T) {
85146 })
86147 }
87148}
149+
150+ func TestGetSootWrapperDownload (t * testing.T ) {
151+ fsMock := ioTestData.FileSystemMock {StatError : fmt .Errorf ("" ), IsNotExistBool : true }
152+ arcMock := ioTestData.ArchiveMock {}
153+ sootHandler := SootHandler {}
154+ _ , err := sootHandler .GetSootWrapper ("17" , fsMock , arcMock )
155+ assert .NoError (t , err )
156+ }
157+
158+ func TestGetSootWrapperInitialize (t * testing.T ) {
159+ fsMock := ioTestData.FileSystemMock {StatError : fmt .Errorf ("" ), IsNotExistBool : true }
160+ arcMock := ioTestData.ArchiveMock {}
161+ sootHandler := SootHandler {}
162+ _ , err := sootHandler .GetSootWrapper ("23" , fsMock , arcMock )
163+ assert .NoError (t , err )
164+ }
165+
166+ func TestGetSootWrapperMkdirError (t * testing.T ) {
167+ errString := "mkdir error"
168+ fsMock := ioTestData.FileSystemMock {MkdirError : fmt .Errorf (errString ), StatError : fmt .Errorf ("" ), IsNotExistBool : true }
169+ arcMock := ioTestData.ArchiveMock {}
170+ sootHandler := SootHandler {}
171+ _ , err := sootHandler .GetSootWrapper ("11" , fsMock , arcMock )
172+ assert .Error (t , err )
173+ assert .Equal (t , err .Error (), errString )
174+ }
0 commit comments