@@ -728,16 +728,20 @@ func TestRoundTripFragments(t *testing.T) {
728728func TestRoundTripFragmentMixedSizes (t * testing.T ) {
729729 blockSize := uint32 (4096 ) // small block size for testing
730730 data := buildImage (t , []squashfs.WriterOption {squashfs .WithBlockSize (blockSize )}, func (w * squashfs.Writer ) {
731- // 1 byte — entirely in fragment
732- w .AddFile ("tiny.txt" , []byte ("x" ), 0644 )
733- // blockSize-1 — entirely in fragment
734- w .AddFile ("almost_block.txt" , bytes .Repeat ([]byte ("a" ), int (blockSize )- 1 ), 0644 )
735- // Exactly blockSize — full block, no fragment
736- w .AddFile ("exact_block.txt" , bytes .Repeat ([]byte ("b" ), int (blockSize )), 0644 )
737- // blockSize+1 — one full block + 1 byte fragment
738- w .AddFile ("block_plus_one.txt" , bytes .Repeat ([]byte ("c" ), int (blockSize )+ 1 ), 0644 )
739- // 2*blockSize+50 — two full blocks + 50 byte fragment
740- w .AddFile ("two_blocks_plus.txt" , bytes .Repeat ([]byte ("d" ), int (blockSize )* 2 + 50 ), 0644 )
731+ for _ , tc := range []struct {
732+ name string
733+ data []byte
734+ }{
735+ {"tiny.txt" , []byte ("x" )},
736+ {"almost_block.txt" , bytes .Repeat ([]byte ("a" ), int (blockSize )- 1 )},
737+ {"exact_block.txt" , bytes .Repeat ([]byte ("b" ), int (blockSize ))},
738+ {"block_plus_one.txt" , bytes .Repeat ([]byte ("c" ), int (blockSize )+ 1 )},
739+ {"two_blocks_plus.txt" , bytes .Repeat ([]byte ("d" ), int (blockSize )* 2 + 50 )},
740+ } {
741+ if err := w .AddFile (tc .name , tc .data , 0644 ); err != nil {
742+ t .Fatal (err )
743+ }
744+ }
741745 })
742746
743747 sb := openImage (t , data )
@@ -782,14 +786,22 @@ func TestCloneFile(t *testing.T) {
782786
783787 // Image with clone
784788 cloneData := buildImage (t , nil , func (w * squashfs.Writer ) {
785- w .AddFile ("original.txt" , content , 0644 )
786- w .CloneInode ("clone.txt" , "original.txt" )
789+ if err := w .AddFile ("original.txt" , content , 0644 ); err != nil {
790+ t .Fatal (err )
791+ }
792+ if err := w .CloneInode ("clone.txt" , "original.txt" ); err != nil {
793+ t .Fatal (err )
794+ }
787795 })
788796
789797 // Image without clone (two copies)
790798 noCloneData := buildImage (t , nil , func (w * squashfs.Writer ) {
791- w .AddFile ("original.txt" , content , 0644 )
792- w .AddFile ("clone.txt" , content , 0644 )
799+ if err := w .AddFile ("original.txt" , content , 0644 ); err != nil {
800+ t .Fatal (err )
801+ }
802+ if err := w .AddFile ("clone.txt" , content , 0644 ); err != nil {
803+ t .Fatal (err )
804+ }
793805 })
794806
795807 t .Logf ("With clone: %d bytes, without: %d bytes, saving: %d bytes" ,
@@ -818,12 +830,21 @@ func TestCloneFile(t *testing.T) {
818830
819831func TestXattrRoundTrip (t * testing.T ) {
820832 data := buildImage (t , nil , func (w * squashfs.Writer ) {
821- w .AddFile ("file.txt" , []byte ("hello" ), 0644 )
822- w .SetXattr ("file.txt" , "user.myattr" , []byte ("myvalue" ))
823- w .SetXattr ("file.txt" , "user.another" , []byte ("val2" ))
824-
825- w .AddDirectory ("dir" , 0755 )
826- w .SetXattr ("dir" , "user.dirattr" , []byte ("dirval" ))
833+ if err := w .AddFile ("file.txt" , []byte ("hello" ), 0644 ); err != nil {
834+ t .Fatal (err )
835+ }
836+ if err := w .SetXattr ("file.txt" , "user.myattr" , []byte ("myvalue" )); err != nil {
837+ t .Fatal (err )
838+ }
839+ if err := w .SetXattr ("file.txt" , "user.another" , []byte ("val2" )); err != nil {
840+ t .Fatal (err )
841+ }
842+ if err := w .AddDirectory ("dir" , 0755 ); err != nil {
843+ t .Fatal (err )
844+ }
845+ if err := w .SetXattr ("dir" , "user.dirattr" , []byte ("dirval" )); err != nil {
846+ t .Fatal (err )
847+ }
827848 })
828849
829850 sb := openImage (t , data )
0 commit comments