@@ -2,6 +2,7 @@ package squashfs
2
2
3
3
import (
4
4
"bytes"
5
+ "encoding/binary"
5
6
"fmt"
6
7
"strings"
7
8
"testing"
@@ -383,13 +384,64 @@ func TestBasicSymlink(t *testing.T) {
383
384
})
384
385
}
385
386
386
- //nolint:unused,revive // keep for future when we implement it and will need t
387
387
func TestExtendedSymlink (t * testing.T ) {
388
- // when we have more data with which to work
388
+ s := & extendedSymlink {
389
+ links : 1 ,
390
+ target : "/a/b/c/d/ef/g/h" ,
391
+ xAttrIndex : 46 ,
392
+ }
393
+ b , err := testGetInodeMetabytes ()
394
+ if err != nil {
395
+ t .Fatal (err )
396
+ }
397
+
398
+ inodeB := binary .LittleEndian .AppendUint32 (b [testBasicSymlinkStart :testBasicSymlinkEnd ], s .xAttrIndex )
399
+
400
+ t .Run ("toBytes" , func (t * testing.T ) {
401
+ b := s .toBytes ()
402
+ if ! bytes .Equal (b , inodeB ) {
403
+ t .Errorf ("mismatched output, actual then expected" )
404
+ t .Logf ("% x" , b )
405
+ t .Logf ("% x" , inodeB )
406
+ }
407
+ })
408
+ t .Run ("Size" , func (t * testing.T ) {
409
+ size := s .size ()
410
+ if size != 0 {
411
+ t .Errorf ("mismatched sizes, actual %d expected %d" , size , 0 )
412
+ }
413
+ })
414
+
415
+ tests := []struct {
416
+ b []byte
417
+ sym * extendedSymlink
418
+ ext int
419
+ err error
420
+ }{
421
+ {inodeB , s , 0 , nil },
422
+ {inodeB [:7 ], nil , 0 , fmt .Errorf ("received %d bytes instead of expected minimal %d" , 7 , 8 )},
423
+ {inodeB [:20 ], & extendedSymlink {links : 1 }, 19 , nil },
424
+ }
389
425
390
- // func (i extendedSymlink) toBytes() []byte {
391
- // func (i extendedSymlink) size() int64 {
392
- // func parseExtendedSymlink(b []byte) (*extendedSymlink, error) {
426
+ t .Run ("parse" , func (t * testing.T ) {
427
+ for i , tt := range tests {
428
+ sym , ext , err := parseExtendedSymlink (tt .b )
429
+ switch {
430
+ case (err == nil && tt .err != nil ) || (err != nil && tt .err == nil ) || (err != nil && tt .err != nil && ! strings .HasPrefix (err .Error (), tt .err .Error ())):
431
+ t .Errorf ("%d: mismatched error, actual then expected" , i )
432
+ t .Logf ("%v" , err )
433
+ t .Logf ("%v" , tt .err )
434
+ case tt .ext != ext :
435
+ t .Errorf ("%d: mismatched extra, actual then expected" , i )
436
+ t .Logf ("%v" , ext )
437
+ t .Logf ("%v" , tt .ext )
438
+ case (sym == nil && tt .sym != nil ) || (sym != nil && tt .sym == nil ) || (sym != nil && tt .sym != nil && * sym != * tt .sym ):
439
+ t .Errorf ("%d: mismatched results, actual then expected" , i )
440
+ t .Logf ("%#v" , * sym )
441
+ t .Logf ("%#v" , * tt .sym )
442
+ }
443
+ }
444
+ })
393
445
}
394
446
395
447
//nolint:unused,revive // keep for future when we implement it and will need t
0 commit comments