Allow unit tests on non-Linux OS
This commit is contained in:
@@ -23,21 +23,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ibm-messaging/mq-container/internal/capabilities"
|
"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 {
|
func logBaseImage() error {
|
||||||
buf, err := ioutil.ReadFile("/etc/os-release")
|
buf, err := ioutil.ReadFile("/etc/os-release")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -109,22 +96,6 @@ func readMounts() error {
|
|||||||
return nil
|
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() {
|
func logConfig() {
|
||||||
log.Printf("CPU architecture: %v", runtime.GOARCH)
|
log.Printf("CPU architecture: %v", runtime.GOARCH)
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
|
|||||||
36
cmd/runmqserver/mqconfig_linux.go
Normal file
36
cmd/runmqserver/mqconfig_linux.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
9
cmd/runmqserver/mqconfig_other.go
Normal file
9
cmd/runmqserver/mqconfig_other.go
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user