From 749038c76d53696f67677434da306bbd5c4726e6 Mon Sep 17 00:00:00 2001 From: Johan Bloemberg Date: Wed, 6 Feb 2019 21:38:33 +0100 Subject: [PATCH] misc: Make build on macOS work --- engine/resources/mount_linux_test.go | 76 +++++++++++++++++++++++ engine/resources/mount_test.go | 48 -------------- engine/resources/net_test.go | 2 + lang/funcs/core/sys/cpucount_fact.go | 2 + lang/funcs/core/sys/cpucount_fact_test.go | 2 + test/test-gotest.sh | 20 +++--- util/socketset/socketset.go | 2 + util/socketset/socketset_test.go | 2 + 8 files changed, 99 insertions(+), 55 deletions(-) create mode 100644 engine/resources/mount_linux_test.go diff --git a/engine/resources/mount_linux_test.go b/engine/resources/mount_linux_test.go new file mode 100644 index 00000000..89b295af --- /dev/null +++ b/engine/resources/mount_linux_test.go @@ -0,0 +1,76 @@ +// Mgmt +// Copyright (C) 2013-2018+ James Shubin and the project contributors +// Written by James Shubin and the project contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// +build !root !darwin + +package resources + +import ( + "io/ioutil" + "os" + "testing" + + fstab "github.com/deniswernert/go-fstab" +) + +func TestMountExists(t *testing.T) { + const procMock1 = `/tmp/mount0 /mnt/proctest ext4 rw,seclabel,relatime,data=ordered 0 0` + "\n" + + var mountExistsTests = []struct { + procMock []byte + in *fstab.Mount + out bool + }{ + { + []byte(procMock1), + &fstab.Mount{ + Spec: "/tmp/mount0", + File: "/mnt/proctest", + VfsType: "ext4", + MntOps: map[string]string{"defaults": ""}, + Freq: 1, + PassNo: 1, + }, + true, + }, + } + + file, err := ioutil.TempFile("", "proc") + if err != nil { + t.Errorf("error creating temp file: %v", err) + return + } + defer os.Remove(file.Name()) + for _, test := range mountExistsTests { + if err := ioutil.WriteFile(file.Name(), test.procMock, 0664); err != nil { + t.Errorf("error writing proc file: %s: %v", file.Name(), err) + return + } + if err := ioutil.WriteFile(test.in.Spec, []byte{}, 0664); err != nil { + t.Errorf("error writing fstab file: %s: %v", file.Name(), err) + return + } + result, err := mountExists(file.Name(), test.in) + if err != nil { + t.Errorf("error checking if fstab entry %s exists: %v", test.in.String(), err) + return + } + if result != test.out { + t.Errorf("mountExistsTests test wanted: %t, got: %t", test.out, result) + } + } +} diff --git a/engine/resources/mount_test.go b/engine/resources/mount_test.go index fcd404ea..8abb70fe 100644 --- a/engine/resources/mount_test.go +++ b/engine/resources/mount_test.go @@ -29,8 +29,6 @@ import ( const fstabMock1 = `UUID=ef5726f2-615c-4350-b0ab-f106e5fc90ad / ext4 defaults 1 1` + "\n" -const procMock1 = `/tmp/mount0 /mnt/proctest ext4 rw,seclabel,relatime,data=ordered 0 0` + "\n" - var fstabWriteTests = []struct { in fstab.Mounts }{ @@ -295,49 +293,3 @@ func TestMountCompare(t *testing.T) { } } } - -var mountExistsTests = []struct { - procMock []byte - in *fstab.Mount - out bool -}{ - { - []byte(procMock1), - &fstab.Mount{ - Spec: "/tmp/mount0", - File: "/mnt/proctest", - VfsType: "ext4", - MntOps: map[string]string{"defaults": ""}, - Freq: 1, - PassNo: 1, - }, - true, - }, -} - -func TestMountExists(t *testing.T) { - file, err := ioutil.TempFile("", "proc") - if err != nil { - t.Errorf("error creating temp file: %v", err) - return - } - defer os.Remove(file.Name()) - for _, test := range mountExistsTests { - if err := ioutil.WriteFile(file.Name(), test.procMock, 0664); err != nil { - t.Errorf("error writing proc file: %s: %v", file.Name(), err) - return - } - if err := ioutil.WriteFile(test.in.Spec, []byte{}, 0664); err != nil { - t.Errorf("error writing fstab file: %s: %v", file.Name(), err) - return - } - result, err := mountExists(file.Name(), test.in) - if err != nil { - t.Errorf("error checking if fstab entry %s exists: %v", test.in.String(), err) - return - } - if result != test.out { - t.Errorf("mountExistsTests test wanted: %t, got: %t", test.out, result) - } - } -} diff --git a/engine/resources/net_test.go b/engine/resources/net_test.go index 110214e8..86ab7d07 100644 --- a/engine/resources/net_test.go +++ b/engine/resources/net_test.go @@ -15,6 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +// +build !darwin + package resources import ( diff --git a/lang/funcs/core/sys/cpucount_fact.go b/lang/funcs/core/sys/cpucount_fact.go index 630fe571..48233b2b 100644 --- a/lang/funcs/core/sys/cpucount_fact.go +++ b/lang/funcs/core/sys/cpucount_fact.go @@ -15,6 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +// +build !darwin + package coresys import ( diff --git a/lang/funcs/core/sys/cpucount_fact_test.go b/lang/funcs/core/sys/cpucount_fact_test.go index 921e4388..52485c85 100644 --- a/lang/funcs/core/sys/cpucount_fact_test.go +++ b/lang/funcs/core/sys/cpucount_fact_test.go @@ -15,6 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +// +build !darwin + package coresys import ( diff --git a/test/test-gotest.sh b/test/test-gotest.sh index 35e054c0..ebfa7618 100755 --- a/test/test-gotest.sh +++ b/test/test-gotest.sh @@ -9,20 +9,26 @@ cd "${ROOT}" # if we want to run this test as root, use build tag -root to ask each test... XSUDO='' -XTAGS='' +XTAGS=() if [[ "$@" = *"--root"* ]]; then if ! timeout 1s sudo -A true; then echo "sudo disabled: can't run as root" exit 1 fi XSUDO='sudo -E' - XTAGS='-tags root' + XTAGS+=('root') +fi + +# As per https://github.com/travis-ci/docs-travis-ci-com/blob/master/user/docker.md +# Docker is not supported on Travis macOS test instances. +if [[ "$TRAVIS_OS_NAME" == "osx" ]];then + XTAGS+=('nodocker') fi failures='' function run-test() { - $XSUDO $@ || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" ) + $XSUDO $@ -tags="${XTAGS[*]}" || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" ) } # NOTE: you can run `go test` with the -tags flag to skip certain tests, eg: @@ -31,17 +37,17 @@ base=$(go list .) if [[ "$@" = *"--integration"* ]]; then if [[ "$@" = *"--race"* ]]; then # adding -count=1 replaces the GOCACHE=off fix that was removed - run-test go test -count=1 -race "${base}/integration" -v ${XTAGS} + run-test go test -count=1 -race "${base}/integration" -v else - run-test go test -count=1 "${base}/integration" -v ${XTAGS} + run-test go test -count=1 "${base}/integration" -v fi else for pkg in `go list -e ./... | grep -v "^${base}/vendor/" | grep -v "^${base}/examples/" | grep -v "^${base}/test/" | grep -v "^${base}/old" | grep -v "^${base}/old/" | grep -v "^${base}/tmp" | grep -v "^${base}/tmp/" | grep -v "^${base}/integration"`; do echo -e "\ttesting: $pkg" if [[ "$@" = *"--race"* ]]; then - run-test go test -count=1 -race "$pkg" ${XTAGS} + run-test go test -count=1 -race "$pkg" else - run-test go test -count=1 "$pkg" ${XTAGS} + run-test go test -count=1 "$pkg" fi done fi diff --git a/util/socketset/socketset.go b/util/socketset/socketset.go index ccaa9e15..4e092a13 100644 --- a/util/socketset/socketset.go +++ b/util/socketset/socketset.go @@ -15,6 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +// +build !darwin + // Package socketset is in API for creating a select style netlink socket to // receive events from the kernel. package socketset diff --git a/util/socketset/socketset_test.go b/util/socketset/socketset_test.go index 07b90101..144cf949 100644 --- a/util/socketset/socketset_test.go +++ b/util/socketset/socketset_test.go @@ -15,6 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +// +build !darwin + package socketset import (