From d1852d9af4a14a5444a1222410523460ea023377 Mon Sep 17 00:00:00 2001 From: Arthur Barr Date: Mon, 29 Jan 2018 09:35:02 +0000 Subject: [PATCH] Allow unit tests on non-Linux OS --- cmd/runmqserver/mqconfig.go | 29 ------------------------- cmd/runmqserver/mqconfig_linux.go | 36 +++++++++++++++++++++++++++++++ cmd/runmqserver/mqconfig_other.go | 9 ++++++++ 3 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 cmd/runmqserver/mqconfig_linux.go create mode 100644 cmd/runmqserver/mqconfig_other.go diff --git a/cmd/runmqserver/mqconfig.go b/cmd/runmqserver/mqconfig.go index a5e0f51..4176399 100644 --- a/cmd/runmqserver/mqconfig.go +++ b/cmd/runmqserver/mqconfig.go @@ -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" { diff --git a/cmd/runmqserver/mqconfig_linux.go b/cmd/runmqserver/mqconfig_linux.go new file mode 100644 index 0000000..cb510a7 --- /dev/null +++ b/cmd/runmqserver/mqconfig_linux.go @@ -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) + } +} diff --git a/cmd/runmqserver/mqconfig_other.go b/cmd/runmqserver/mqconfig_other.go new file mode 100644 index 0000000..81cdf9d --- /dev/null +++ b/cmd/runmqserver/mqconfig_other.go @@ -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 +}