github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/core/cpio/cpio_plan9_test.go (about) 1 // Copyright 2020 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "os" 10 "syscall" 11 "testing" 12 ) 13 14 func checkFileInfo(t *testing.T, ent *dirEnt, newFileInfo os.FileInfo) { 15 t.Helper() 16 17 newStatT := newFileInfo.Sys().(*syscall.Dir) 18 statT := ent.FileInfo.Sys().(*syscall.Dir) 19 t.Logf("Entry %v statT %v", ent, newFileInfo) 20 if ent.FileInfo.Name() != newFileInfo.Name() || 21 ent.FileInfo.Size() != newFileInfo.Size() || 22 ent.FileInfo.Mode() != newFileInfo.Mode() || 23 ent.FileInfo.IsDir() != newFileInfo.IsDir() || 24 statT.Mode != newStatT.Mode || 25 statT.Uid != newStatT.Uid || 26 statT.Gid != newStatT.Gid { 27 msg := "File has mismatched attributes:\n" 28 msg += "Property | Original | Extracted\n" 29 msg += fmt.Sprintf("Name: | %10s | %10s\n", ent.FileInfo.Name(), newFileInfo.Name()) 30 msg += fmt.Sprintf("Size: | %10d | %10d\n", ent.FileInfo.Size(), newFileInfo.Size()) 31 msg += fmt.Sprintf("Mode: | %10d | %10d\n", ent.FileInfo.Mode(), newFileInfo.Mode()) 32 msg += fmt.Sprintf("IsDir: | %10t | %10t\n", ent.FileInfo.IsDir(), newFileInfo.IsDir()) 33 msg += fmt.Sprintf("FI Mode: | %10d | %10d\n", statT.Mode, newStatT.Mode) 34 msg += fmt.Sprintf("Uid: | %10s | %10s\n", statT.Uid, newStatT.Uid) 35 msg += fmt.Sprintf("Gid: | %10s | %10s\n", statT.Gid, newStatT.Gid) 36 t.Error(msg) 37 } 38 }