Extract inode inspection functions into testhelpers

This commit is contained in:
Gabe Rosenhouse
2016-04-17 18:35:49 -07:00
parent 5d932e4716
commit 54d7f73092
2 changed files with 28 additions and 27 deletions

View File

@ -11,6 +11,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package testhelpers provides common support behavior for tests
package testhelpers
import (
@ -24,6 +26,21 @@ import (
. "github.com/onsi/gomega"
)
func GetInode(path string) (uint64, error) {
file, err := os.Open(path)
if err != nil {
return 0, err
}
defer file.Close()
return GetInodeF(file)
}
func GetInodeF(file *os.File) (uint64, error) {
stat := &unix.Stat_t{}
err := unix.Fstat(int(file.Fd()), stat)
return stat.Ino, err
}
func MakeNetworkNS(containerID string) string {
namespace := "/var/run/netns/" + containerID
pid := unix.Getpid()