github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/wrench/wrench_nix_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 // +build !windows 4 5 package wrench_test 6 7 import ( 8 "os" 9 "syscall" 10 11 gc "gopkg.in/check.v1" 12 13 "github.com/juju/juju/wrench" 14 ) 15 16 const fileNotFound = `stat .+: no such file or directory` 17 18 // Patch out the os.Stat call used by wrench so that a particular file 19 // appears to be owned by a UID that isn't Juju's UID. 20 func (s *wrenchSuite) tweakOwner(c *gc.C, targetPath string) { 21 s.PatchValue(wrench.Stat, func(path string) (fi os.FileInfo, err error) { 22 fi, err = os.Stat(path) 23 if err != nil { 24 return 25 } 26 if path == targetPath { 27 statStruct, ok := fi.Sys().(*syscall.Stat_t) 28 if !ok { 29 c.Skip("this test only supports POSIX systems") 30 } 31 statStruct.Uid = notJujuUid 32 } 33 return 34 }) 35 }