Allow unit tests on non-Linux OS

This commit is contained in:
Arthur Barr
2018-01-29 09:35:02 +00:00
parent 238529918c
commit d1852d9af4
3 changed files with 45 additions and 29 deletions

View File

@@ -23,21 +23,8 @@ import (
"strings"
"github.com/ibm-messaging/mq-container/internal/capabilities"
"golang.org/x/sys/unix"
)
// fsTypes contains file system identifier codes.
// This code will not compile on some operating systems - Linux only.
var fsTypes = map[int64]string{
0x61756673: "aufs",
0xef53: "ext",
0x6969: "nfs",
0x65735546: "fuse",
0x9123683e: "btrfs",
0x01021994: "tmpfs",
0x794c7630: "overlayfs",
}
func logBaseImage() error {
buf, err := ioutil.ReadFile("/etc/os-release")
if err != nil {
@@ -109,22 +96,6 @@ func readMounts() error {
return nil
}
func checkFS(path string) {
statfs := &unix.Statfs_t{}
err := unix.Statfs(path, statfs)
if err != nil {
log.Println(err)
return
}
t := fsTypes[statfs.Type]
switch t {
case "aufs", "overlayfs", "tmpfs":
log.Fatalf("Error: %v uses unsupported filesystem type %v", path, t)
default:
log.Printf("Detected %v has filesystem type '%v'", path, t)
}
}
func logConfig() {
log.Printf("CPU architecture: %v", runtime.GOARCH)
if runtime.GOOS == "linux" {

View File

@@ -0,0 +1,36 @@
// +build linux
package main
import (
log "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
// fsTypes contains file system identifier codes.
// This code will not compile on some operating systems - Linux only.
var fsTypes = map[int64]string{
0x61756673: "aufs",
0xef53: "ext",
0x6969: "nfs",
0x65735546: "fuse",
0x9123683e: "btrfs",
0x01021994: "tmpfs",
0x794c7630: "overlayfs",
}
func checkFS(path string) {
statfs := &unix.Statfs_t{}
err := unix.Statfs(path, statfs)
if err != nil {
log.Println(err)
return
}
t := fsTypes[statfs.Type]
switch t {
case "aufs", "overlayfs", "tmpfs":
log.Fatalf("Error: %v uses unsupported filesystem type %v", path, t)
default:
log.Printf("Detected %v has filesystem type '%v'", path, t)
}
}

View File

@@ -0,0 +1,9 @@
// +build !linux
package main
// Dummy version of this function, only for non-Linux systems.
// Having this allows unit tests to be run on other platforms (e.g. macOS)
func checkFS(path string) {
return
}