github.com/rigado/snapd@v2.42.5-go-mod+incompatible/snap/squashfs/export_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2018 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package squashfs 21 22 import ( 23 "os" 24 "os/exec" 25 "time" 26 27 "gopkg.in/check.v1" 28 ) 29 30 var ( 31 FromRaw = fromRaw 32 NewUnsquashfsStderrWriter = newUnsquashfsStderrWriter 33 ) 34 35 func (s stat) User() string { return s.user } 36 func (s stat) Group() string { return s.group } 37 38 func MockLink(newLink func(string, string) error) (restore func()) { 39 oldLink := osLink 40 osLink = newLink 41 return func() { 42 osLink = oldLink 43 } 44 } 45 46 func MockCommandFromSystemSnap(f func(string, ...string) (*exec.Cmd, error)) (restore func()) { 47 oldCommandFromSystemSnap := cmdutilCommandFromSystemSnap 48 cmdutilCommandFromSystemSnap = f 49 return func() { 50 cmdutilCommandFromSystemSnap = oldCommandFromSystemSnap 51 } 52 } 53 54 // Alike compares to os.FileInfo to determine if they are sufficiently 55 // alike to say they refer to the same thing. 56 func Alike(a, b os.FileInfo, c *check.C, comment check.CommentInterface) { 57 c.Check(a, check.NotNil, comment) 58 c.Check(b, check.NotNil, comment) 59 if a == nil || b == nil { 60 return 61 } 62 63 // the .Name() of the root will be different on non-squashfs things 64 _, asq := a.(*stat) 65 _, bsq := b.(*stat) 66 if !((asq && a.Name() == "/") || (bsq && b.Name() == "/")) { 67 c.Check(a.Name(), check.Equals, b.Name(), comment) 68 } 69 70 c.Check(a.Mode(), check.Equals, b.Mode(), comment) 71 if a.Mode().IsRegular() { 72 c.Check(a.Size(), check.Equals, b.Size(), comment) 73 } 74 am := a.ModTime().UTC().Truncate(time.Minute) 75 bm := b.ModTime().UTC().Truncate(time.Minute) 76 c.Check(am.Equal(bm), check.Equals, true, check.Commentf("%s != %s (%s)", am, bm, comment)) 77 }