@@ -140,23 +140,14 @@ func TestUpgrader_unpackTarGz(t *testing.T) {
140140 }
141141
142142 tests := []struct {
143- << << << < HEAD
144- name string
145- args args
146- want UnpackResult
147- wantErr assert.ErrorAssertionFunc
148- checkFiles checkExtractedPath
149- == == == =
150143 name string
151144 args args
152145 want UnpackResult
153146 expectedError error
154147 checkFiles checkExtractedPath
155- flavor string
156148 copy copyFunc
157149 mkdirAll mkdirAllFunc
158150 openFile openFileFunc
159- >> >> >> > f70ff023f (Enhancement / 5235 handle insufficient disk space errors in artifact unpack (#9322 ))
160151 }{
161152 {
162153 name : "file before containing folder" ,
@@ -199,70 +190,11 @@ func TestUpgrader_unpackTarGz(t *testing.T) {
199190 mkdirAll : os .MkdirAll ,
200191 openFile : os .OpenFile ,
201192 },
202- << << << < HEAD
203- == == == =
204- {
205- name : "package with basic flavor" ,
206- args : args {
207- version : "1.2.3" ,
208- archiveFiles : append (archiveFilesWithMoreComponents , agentArchiveSymLink ),
209- archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
210- return createTarArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.tar.gz" , i )
211- },
212- },
213- want : UnpackResult {
214- Hash : "abcdef" ,
215- VersionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-SNAPSHOT-abcdef" ),
216- },
217- expectedError : nil ,
218- flavor : "basic" ,
219- checkFiles : func (t * testing.T , testDataDir string ) {
220- checkFilesPresence (t , testDataDir ,
221- []string {
222- filepath .Join ("components" , "comp1" + binarySuffix ), filepath .Join ("components" , "comp1.spec.yml" ),
223- filepath .Join ("components" , "comp2" + binarySuffix ), filepath .Join ("components" , "comp2.spec.yml" ),
224- filepath .Join ("components" , "component_dir" , "inner_file" ),
225- },
226- []string {filepath .Join ("components" , "comp3" ), filepath .Join ("components" , "comp3.spec.yml" ), filepath .Join ("components" , "component.zip" )})
227- },
228- copy : io .Copy ,
229- mkdirAll : os .MkdirAll ,
230- openFile : os .OpenFile ,
231- },
232- {
233- name : "package with servers flavor" ,
234- args : args {
235- version : "1.2.3" ,
236- archiveFiles : append (archiveFilesWithMoreComponents , agentArchiveSymLink ),
237- archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
238- return createTarArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.tar.gz" , i )
239- },
240- },
241- want : UnpackResult {
242- Hash : "abcdef" ,
243- VersionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-SNAPSHOT-abcdef" ),
244- },
245- expectedError : nil ,
246- flavor : "servers" ,
247- checkFiles : func (t * testing.T , testDataDir string ) {
248- checkFilesPresence (t , testDataDir ,
249- []string {
250- filepath .Join ("components" , "comp1" + binarySuffix ), filepath .Join ("components" , "comp1.spec.yml" ),
251- filepath .Join ("components" , "comp2" + binarySuffix ), filepath .Join ("components" , "comp2.spec.yml" ),
252- filepath .Join ("components" , "component_dir" , "inner_file" ),
253- filepath .Join ("components" , "comp3" + binarySuffix ), filepath .Join ("components" , "comp3.spec.yml" ), filepath .Join ("components" , "component.zip" ),
254- },
255- []string {})
256- },
257- copy : io .Copy ,
258- mkdirAll : os .MkdirAll ,
259- openFile : os .OpenFile ,
260- },
261193 {
262194 name : "copying file fails" ,
263195 args : args {
264196 version : "1.2.3" ,
265- archiveFiles : append (archiveFilesWithMoreComponents , agentArchiveSymLink ),
197+ archiveFiles : append (archiveFilesWithManifestNoSymlink , agentArchiveSymLink ),
266198 archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
267199 return createTarArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.tar.gz" , i )
268200 },
@@ -278,7 +210,7 @@ func TestUpgrader_unpackTarGz(t *testing.T) {
278210 name : "opening file fails" ,
279211 args : args {
280212 version : "1.2.3" ,
281- archiveFiles : append (archiveFilesWithMoreComponents , agentArchiveSymLink ),
213+ archiveFiles : append (archiveFilesWithManifestNoSymlink , agentArchiveSymLink ),
282214 archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
283215 return createTarArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.tar.gz" , i )
284216 },
@@ -294,7 +226,7 @@ func TestUpgrader_unpackTarGz(t *testing.T) {
294226 name : "creating directory fails" ,
295227 args : args {
296228 version : "1.2.3" ,
297- archiveFiles : append (archiveFilesWithMoreComponents , agentArchiveSymLink ),
229+ archiveFiles : append (archiveFilesWithManifestNoSymlink , agentArchiveSymLink ),
298230 archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
299231 return createTarArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.tar.gz" , i )
300232 },
@@ -306,7 +238,6 @@ func TestUpgrader_unpackTarGz(t *testing.T) {
306238 openFile : os .OpenFile ,
307239 copy : io .Copy ,
308240 },
309- >> >> >> > f70ff023f (Enhancement / 5235 handle insufficient disk space errors in artifact unpack (#9322 ))
310241 }
311242 for _ , tt := range tests {
312243 t .Run (tt .name , func (t * testing.T ) {
@@ -319,14 +250,9 @@ func TestUpgrader_unpackTarGz(t *testing.T) {
319250 archiveFile , err := tt .args .archiveGenerator (t , tt .args .archiveFiles )
320251 require .NoError (t , err , "creation of test archive file failed" )
321252
322- << << << < HEAD
323- got , err := untar (log , archiveFile , testDataDir )
324- if ! tt .wantErr (t , err , fmt .Sprintf ("untar(%v, %v, %v)" , tt .args .version , archiveFile , testDataDir )) {
325- == == == =
326- got , err := untar (log , archiveFile , testDataDir , tt .flavor , tt .copy , tt .mkdirAll , tt .openFile )
253+ got , err := untar (log , archiveFile , testDataDir , tt .copy , tt .mkdirAll , tt .openFile )
327254 if tt .expectedError != nil {
328255 assert .ErrorIsf (t , err , tt .expectedError , "untar(%v, %v, %v)" , tt .args .version , archiveFile , testDataDir )
329- >> >> >> > f70ff023f (Enhancement / 5235 handle insufficient disk space errors in artifact unpack (#9322 ))
330256 return
331257 }
332258 assert .NoErrorf (t , err , "untar(%v, %v, %v)" , tt .args .version , archiveFile , testDataDir )
@@ -346,23 +272,14 @@ func TestUpgrader_unpackZip(t *testing.T) {
346272 }
347273
348274 tests := []struct {
349- << << << < HEAD
350- name string
351- args args
352- want UnpackResult
353- wantErr assert.ErrorAssertionFunc
354- checkFiles checkExtractedPath
355- == == == =
356275 name string
357276 args args
358277 want UnpackResult
359278 expectedError error
360279 checkFiles checkExtractedPath
361- flavor string
362280 copy copyFunc
363281 mkdirAll mkdirAllFunc
364282 openFile openFileFunc
365- >> >> >> > f70ff023f (Enhancement / 5235 handle insufficient disk space errors in artifact unpack (#9322 ))
366283 }{
367284 {
368285 name : "file before containing folder" ,
@@ -403,68 +320,10 @@ func TestUpgrader_unpackZip(t *testing.T) {
403320 mkdirAll : os .MkdirAll ,
404321 openFile : os .OpenFile ,
405322 },
406- << << << < HEAD
407- == == == =
408-
409- {
410- name : "package with basic flavor" ,
411- args : args {
412- archiveFiles : archiveFilesWithMoreComponents ,
413- archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
414- return createZipArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.zip" , i )
415- },
416- },
417- want : UnpackResult {
418- Hash : "abcdef" ,
419- VersionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-SNAPSHOT-abcdef" ),
420- },
421- expectedError : nil ,
422- flavor : "basic" ,
423- checkFiles : func (t * testing.T , testDataDir string ) {
424- checkFilesPresence (t , testDataDir ,
425- []string {
426- filepath .Join ("components" , "comp1" + binarySuffix ), filepath .Join ("components" , "comp1.spec.yml" ),
427- filepath .Join ("components" , "comp2" + binarySuffix ), filepath .Join ("components" , "comp2.spec.yml" ),
428- filepath .Join ("components" , "component_dir" , "inner_file" ),
429- },
430- []string {filepath .Join ("components" , "comp3" + binarySuffix ), filepath .Join ("components" , "comp3.spec.yml" ), filepath .Join ("components" , "component.zip" )})
431- },
432- copy : io .Copy ,
433- mkdirAll : os .MkdirAll ,
434- openFile : os .OpenFile ,
435- },
436- {
437- name : "package with servers flavor" ,
438- args : args {
439- archiveFiles : archiveFilesWithMoreComponents ,
440- archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
441- return createZipArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.zip" , i )
442- },
443- },
444- want : UnpackResult {
445- Hash : "abcdef" ,
446- VersionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-SNAPSHOT-abcdef" ),
447- },
448- expectedError : nil ,
449- flavor : "servers" ,
450- checkFiles : func (t * testing.T , testDataDir string ) {
451- checkFilesPresence (t , testDataDir ,
452- []string {
453- filepath .Join ("components" , "comp1" + binarySuffix ), filepath .Join ("components" , "comp1.spec.yml" ),
454- filepath .Join ("components" , "comp2" + binarySuffix ), filepath .Join ("components" , "comp2.spec.yml" ),
455- filepath .Join ("components" , "component_dir" , "inner_file" ),
456- filepath .Join ("components" , "comp3" + binarySuffix ), filepath .Join ("components" , "comp3.spec.yml" ), filepath .Join ("components" , "component.zip" ),
457- },
458- []string {})
459- },
460- copy : io .Copy ,
461- mkdirAll : os .MkdirAll ,
462- openFile : os .OpenFile ,
463- },
464323 {
465324 name : "copying file fails" ,
466325 args : args {
467- archiveFiles : archiveFilesWithMoreComponents ,
326+ archiveFiles : archiveFilesWithManifestNoSymlink ,
468327 archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
469328 return createZipArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.zip" , i )
470329 },
@@ -479,7 +338,7 @@ func TestUpgrader_unpackZip(t *testing.T) {
479338 {
480339 name : "opening file fails" ,
481340 args : args {
482- archiveFiles : archiveFilesWithMoreComponents ,
341+ archiveFiles : archiveFilesWithManifestNoSymlink ,
483342 archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
484343 return createZipArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.zip" , i )
485344 },
@@ -494,7 +353,7 @@ func TestUpgrader_unpackZip(t *testing.T) {
494353 {
495354 name : "creating directory fails" ,
496355 args : args {
497- archiveFiles : archiveFilesWithMoreComponents ,
356+ archiveFiles : archiveFilesWithManifestNoSymlink ,
498357 archiveGenerator : func (t * testing.T , i []files ) (string , error ) {
499358 return createZipArchive (t , "elastic-agent-1.2.3-SNAPSHOT-someos-x86_64.zip" , i )
500359 },
@@ -506,7 +365,6 @@ func TestUpgrader_unpackZip(t *testing.T) {
506365 openFile : os .OpenFile ,
507366 copy : io .Copy ,
508367 },
509- >> >> >> > f70ff023f (Enhancement / 5235 handle insufficient disk space errors in artifact unpack (#9322 ))
510368 }
511369 for _ , tt := range tests {
512370 t .Run (tt .name , func (t * testing.T ) {
@@ -520,14 +378,9 @@ func TestUpgrader_unpackZip(t *testing.T) {
520378 archiveFile , err := tt .args .archiveGenerator (t , tt .args .archiveFiles )
521379 require .NoError (t , err , "creation of test archive file failed" )
522380
523- << << << < HEAD
524- got , err := unzip (log , archiveFile , testDataDir )
525- if ! tt .wantErr (t , err , fmt .Sprintf ("unzip(%v, %v)" , archiveFile , testDataDir )) {
526- == == == =
527- got , err := unzip (log , archiveFile , testDataDir , tt .flavor , tt .copy , tt .mkdirAll , tt .openFile )
381+ got , err := unzip (log , archiveFile , testDataDir , tt .copy , tt .mkdirAll , tt .openFile )
528382 if tt .expectedError != nil {
529383 assert .ErrorIs (t , err , tt .expectedError , "error mismatch" )
530- >> >> >> > f70ff023f (Enhancement / 5235 handle insufficient disk space errors in artifact unpack (#9322 ))
531384 return
532385 }
533386 assert .NoErrorf (t , err , "unzip(%v, %v)" , archiveFile , testDataDir )
@@ -685,38 +538,12 @@ func addEntryToZipArchive(af files, writer *zip.Writer) error {
685538
686539 return nil
687540}
688- << << << < HEAD
689- == == == =
690-
691- func TestGetFileNamePrefix (t * testing.T ) {
692- tests := map [string ]struct {
693- archivePath string
694- expectedPrefix string
695- }{
696- "fips" : {
697- archivePath : "/foo/bar/elastic-agent-fips-9.1.0-SNAPSHOT-linux-arm64.tar.gz" ,
698- expectedPrefix : "elastic-agent-9.1.0-SNAPSHOT-linux-arm64/" ,
699- },
700- "no_fips" : {
701- archivePath : "/foo/bar/elastic-agent-9.1.0-SNAPSHOT-linux-arm64.tar.gz" ,
702- expectedPrefix : "elastic-agent-9.1.0-SNAPSHOT-linux-arm64/" ,
703- },
704- }
705-
706- for name , test := range tests {
707- t .Run (name , func (t * testing.T ) {
708- prefix := getFileNamePrefix (test .archivePath )
709- require .Equal (t , test .expectedPrefix , prefix )
710- })
711- }
712-
713- }
714541
715542func TestUnpack (t * testing.T ) {
716543 log , _ := loggertest .New ("TestUnpack" )
717544
718545 unarchiveSetup := func (unpackResult UnpackResult , err error ) unarchiveFunc {
719- return func (log * logger.Logger , archivePath , dataDir string , flavor string , copy copyFunc , mkdirAll mkdirAllFunc , openFile openFileFunc ) (UnpackResult , error ) {
546+ return func (log * logger.Logger , archivePath , dataDir string , copy copyFunc , mkdirAll mkdirAllFunc , openFile openFileFunc ) (UnpackResult , error ) {
720547 return unpackResult , err
721548 }
722549 }
@@ -751,10 +578,9 @@ func TestUnpack(t *testing.T) {
751578 unpacker := newUnpacker (log )
752579 unpacker .untar = test .unarchiveFunc
753580 unpacker .unzip = test .unarchiveFunc
754- unpackResult , unpackErr := unpacker .unpack ("mockVersion" , "mockArchivePath" , "mockDataDir" , "mockFlavor" )
581+ unpackResult , unpackErr := unpacker .unpack ("mockVersion" , "mockArchivePath" , "mockDataDir" )
755582 assert .Equal (t , test .expectedUnpackResult , unpackResult )
756583 assert .Equal (t , test .expectedErr , unpackErr )
757584 })
758585 }
759586}
760- >> >> >> > f70ff023f (Enhancement / 5235 handle insufficient disk space errors in artifact unpack (#9322 ))
0 commit comments