diff --git a/bootstrapper/internal/diskencryption/BUILD.bazel b/bootstrapper/internal/diskencryption/BUILD.bazel index cb89be0e67..9f62bbe55d 100644 --- a/bootstrapper/internal/diskencryption/BUILD.bazel +++ b/bootstrapper/internal/diskencryption/BUILD.bazel @@ -1,5 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") -load("//bazel/go:go_test.bzl", "go_ld_test", "go_test") +load("//bazel/go:go_test.bzl", "go_test") go_library( name = "diskencryption", @@ -20,26 +20,13 @@ go_test( srcs = ["diskencryption_test.go"], embed = [":diskencryption"], # keep - tags = ["manual"], - deps = select({ - "@io_bazel_rules_go//go/platform:android": [ - "@com_github_spf13_afero//:afero", - "@com_github_stretchr_testify//assert", - "@com_github_stretchr_testify//require", - "@org_uber_go_goleak//:goleak", - ], - "@io_bazel_rules_go//go/platform:linux": [ - "@com_github_spf13_afero//:afero", - "@com_github_stretchr_testify//assert", - "@com_github_stretchr_testify//require", - "@org_uber_go_goleak//:goleak", - ], - "//conditions:default": [], - }), -) - -go_ld_test( - name = "diskencryption_ld_test", - src = "diskencryption_test", - ld = "//rpm:ld", + pure = "on", + # keep + race = "off", + deps = [ + "@com_github_spf13_afero//:afero", + "@com_github_stretchr_testify//assert", + "@com_github_stretchr_testify//require", + "@org_uber_go_goleak//:goleak", + ], ) diff --git a/bootstrapper/internal/diskencryption/diskencryption_test.go b/bootstrapper/internal/diskencryption/diskencryption_test.go index 3a84dd38b9..0c4e9c9f57 100644 --- a/bootstrapper/internal/diskencryption/diskencryption_test.go +++ b/bootstrapper/internal/diskencryption/diskencryption_test.go @@ -1,5 +1,3 @@ -//go:build linux && cgo - /* Copyright (c) Edgeless Systems GmbH diff --git a/bootstrapper/internal/initserver/BUILD.bazel b/bootstrapper/internal/initserver/BUILD.bazel index 634c061554..385108c577 100644 --- a/bootstrapper/internal/initserver/BUILD.bazel +++ b/bootstrapper/internal/initserver/BUILD.bazel @@ -1,5 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") -load("//bazel/go:go_test.bzl", "go_ld_test", "go_test") +load("//bazel/go:go_test.bzl", "go_test") go_library( name = "initserver", @@ -36,7 +36,9 @@ go_test( srcs = ["initserver_test.go"], embed = [":initserver"], # keep - tags = ["manual"], + pure = "on", + # keep + race = "off", deps = [ "//bootstrapper/initproto", "//internal/atls", @@ -55,9 +57,3 @@ go_test( "@org_uber_go_goleak//:goleak", ], ) - -go_ld_test( - name = "initserver_ld_test", - src = "initserver_test", - ld = "//rpm:ld", -) diff --git a/bootstrapper/internal/joinclient/BUILD.bazel b/bootstrapper/internal/joinclient/BUILD.bazel index 1186145057..c7d6307b57 100644 --- a/bootstrapper/internal/joinclient/BUILD.bazel +++ b/bootstrapper/internal/joinclient/BUILD.bazel @@ -1,5 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") -load("//bazel/go:go_test.bzl", "go_ld_test", "go_test") +load("//bazel/go:go_test.bzl", "go_test") go_library( name = "joinclient", @@ -32,7 +32,9 @@ go_test( srcs = ["joinclient_test.go"], embed = [":joinclient"], # keep - tags = ["manual"], + pure = "on", + # keep + race = "off", deps = [ "//internal/cloud/metadata", "//internal/constants", @@ -53,9 +55,3 @@ go_test( "@org_uber_go_goleak//:goleak", ], ) - -go_ld_test( - name = "joinclient_ld_test", - src = "joinclient_test", - ld = "//rpm:ld", -) diff --git a/csi/cryptmapper/BUILD.bazel b/csi/cryptmapper/BUILD.bazel index 1981023220..26014dc0a5 100644 --- a/csi/cryptmapper/BUILD.bazel +++ b/csi/cryptmapper/BUILD.bazel @@ -1,5 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") -load("//bazel/go:go_test.bzl", "go_ld_test", "go_test") +load("//bazel/go:go_test.bzl", "go_test") go_library( name = "cryptmapper", @@ -36,15 +36,11 @@ go_test( srcs = ["cryptmapper_test.go"], embed = [":cryptmapper"], # keep - tags = ["manual"], + pure = "on", + # keep + race = "off", deps = [ "@com_github_stretchr_testify//assert", "@org_uber_go_goleak//:goleak", ], ) - -go_ld_test( - name = "cryptmapper_ld_test", - src = "cryptmapper_test", - ld = "//rpm:ld", -) diff --git a/hack/qemu-metadata-api/server/BUILD.bazel b/hack/qemu-metadata-api/server/BUILD.bazel index 386efbfe21..9fe06769b9 100644 --- a/hack/qemu-metadata-api/server/BUILD.bazel +++ b/hack/qemu-metadata-api/server/BUILD.bazel @@ -1,5 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") -load("//bazel/go:go_test.bzl", "go_ld_test", "go_test") +load("//bazel/go:go_test.bzl", "go_test") go_library( name = "server", @@ -20,10 +20,16 @@ go_library( go_test( name = "server_test", - srcs = ["server_test.go"], + srcs = [ + "server_cgo_test.go", + "server_cross_test.go", + "server_test.go", + ], embed = [":server"], # keep - tags = ["manual"], + pure = "on", + # keep + race = "off", deps = [ "//hack/qemu-metadata-api/virtwrapper", "//internal/cloud/metadata", @@ -33,9 +39,3 @@ go_test( "@org_libvirt_go_libvirt//:libvirt", ], ) - -go_ld_test( - name = "server_ld_test", - src = "server_test", - ld = "//rpm:ld", -) diff --git a/hack/qemu-metadata-api/server/server_cgo_test.go b/hack/qemu-metadata-api/server/server_cgo_test.go new file mode 100644 index 0000000000..59c569535c --- /dev/null +++ b/hack/qemu-metadata-api/server/server_cgo_test.go @@ -0,0 +1,41 @@ +//go:build cgo + +/* +Copyright (c) Edgeless Systems GmbH + +SPDX-License-Identifier: AGPL-3.0-only +*/ + +package server + +import ( + "github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/virtwrapper" + "libvirt.org/go/libvirt" +) + +type stubNetwork struct { + leases []libvirt.NetworkDHCPLease + getLeaseErr error +} + +func newStubNetwork(leases []virtwrapper.NetworkDHCPLease, getLeaseErr error) stubNetwork { + libvirtLeases := make([]libvirt.NetworkDHCPLease, len(leases)) + for i, l := range leases { + libvirtLeases[i] = libvirt.NetworkDHCPLease{ + IPaddr: l.IPaddr, + Hostname: l.Hostname, + } + } + return stubNetwork{ + leases: libvirtLeases, + getLeaseErr: getLeaseErr, + } +} + +func (n stubNetwork) GetDHCPLeases() ([]libvirt.NetworkDHCPLease, error) { + return n.leases, n.getLeaseErr +} + +func (n stubNetwork) Free() error { + return nil +} diff --git a/hack/qemu-metadata-api/server/server_cross_test.go b/hack/qemu-metadata-api/server/server_cross_test.go new file mode 100644 index 0000000000..3f4488b263 --- /dev/null +++ b/hack/qemu-metadata-api/server/server_cross_test.go @@ -0,0 +1,31 @@ +//go:build !cgo + +/* +Copyright (c) Edgeless Systems GmbH + +SPDX-License-Identifier: AGPL-3.0-only +*/ + +package server + +import "github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/virtwrapper" + +type stubNetwork struct { + leases []virtwrapper.NetworkDHCPLease + getLeaseErr error +} + +func newStubNetwork(leases []virtwrapper.NetworkDHCPLease, getLeaseErr error) stubNetwork { + return stubNetwork{ + leases: leases, + getLeaseErr: getLeaseErr, + } +} + +func (n stubNetwork) GetDHCPLeases() ([]virtwrapper.NetworkDHCPLease, error) { + return n.leases, n.getLeaseErr +} + +func (n stubNetwork) Free() error { + return nil +} diff --git a/hack/qemu-metadata-api/server/server_test.go b/hack/qemu-metadata-api/server/server_test.go index 554c02118a..d9c78c2a50 100644 --- a/hack/qemu-metadata-api/server/server_test.go +++ b/hack/qemu-metadata-api/server/server_test.go @@ -1,5 +1,3 @@ -//go:build cgo - /* Copyright (c) Edgeless Systems GmbH @@ -23,7 +21,6 @@ import ( "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "libvirt.org/go/libvirt" ) func TestListAll(t *testing.T) { @@ -35,22 +32,20 @@ func TestListAll(t *testing.T) { }{ "success": { connect: &stubConnect{ - network: stubNetwork{ - leases: []libvirt.NetworkDHCPLease{ - { - IPaddr: "192.0.100.1", - Hostname: "control-plane-0", - }, - { - IPaddr: "192.0.100.2", - Hostname: "control-plane-1", - }, - { - IPaddr: "192.0.200.1", - Hostname: "worker-0", - }, + network: newStubNetwork([]virtwrapper.NetworkDHCPLease{ + { + IPaddr: "192.0.100.1", + Hostname: "control-plane-0", }, - }, + { + IPaddr: "192.0.100.2", + Hostname: "control-plane-1", + }, + { + IPaddr: "192.0.200.1", + Hostname: "worker-0", + }, + }, nil), }, }, "LookupNetworkByName error": { @@ -98,14 +93,12 @@ func TestListSelf(t *testing.T) { "success": { remoteAddr: "192.0.100.1:1234", connect: &stubConnect{ - network: stubNetwork{ - leases: []libvirt.NetworkDHCPLease{ - { - IPaddr: "192.0.100.1", - Hostname: "control-plane-0", - }, + network: newStubNetwork([]virtwrapper.NetworkDHCPLease{ + { + IPaddr: "192.0.100.1", + Hostname: "control-plane-0", }, - }, + }, nil), }, }, "listAll error": { @@ -118,28 +111,24 @@ func TestListSelf(t *testing.T) { "remoteAddr error": { remoteAddr: "", connect: &stubConnect{ - network: stubNetwork{ - leases: []libvirt.NetworkDHCPLease{ - { - IPaddr: "192.0.100.1", - Hostname: "control-plane-0", - }, + network: newStubNetwork([]virtwrapper.NetworkDHCPLease{ + { + IPaddr: "192.0.100.1", + Hostname: "control-plane-0", }, - }, + }, nil), }, wantErr: true, }, "peer not found": { remoteAddr: "192.0.200.1:1234", connect: &stubConnect{ - network: stubNetwork{ - leases: []libvirt.NetworkDHCPLease{ - { - IPaddr: "192.0.100.1", - Hostname: "control-plane-0", - }, + network: newStubNetwork([]virtwrapper.NetworkDHCPLease{ + { + IPaddr: "192.0.100.1", + Hostname: "control-plane-0", }, - }, + }, nil), }, wantErr: true, }, @@ -184,18 +173,16 @@ func TestListPeers(t *testing.T) { "success": { remoteAddr: "192.0.100.1:1234", connect: &stubConnect{ - network: stubNetwork{ - leases: []libvirt.NetworkDHCPLease{ - { - IPaddr: "192.0.100.1", - Hostname: "control-plane-0", - }, - { - IPaddr: "192.0.200.1", - Hostname: "worker-0", - }, + network: newStubNetwork([]virtwrapper.NetworkDHCPLease{ + { + IPaddr: "192.0.100.1", + Hostname: "control-plane-0", }, - }, + { + IPaddr: "192.0.200.1", + Hostname: "worker-0", + }, + }, nil), }, }, "listAll error": { @@ -287,14 +274,12 @@ func TestPostLog(t *testing.T) { func TestInitSecretHash(t *testing.T) { defaultConnect := &stubConnect{ - network: stubNetwork{ - leases: []libvirt.NetworkDHCPLease{ - { - IPaddr: "192.0.100.1", - Hostname: "control-plane-0", - }, + network: newStubNetwork([]virtwrapper.NetworkDHCPLease{ + { + IPaddr: "192.0.100.1", + Hostname: "control-plane-0", }, - }, + }, nil), } testCases := map[string]struct { connect *stubConnect @@ -345,16 +330,3 @@ type stubConnect struct { func (c stubConnect) LookupNetworkByName(_ string) (*virtwrapper.Network, error) { return &virtwrapper.Network{Net: c.network}, c.getNetworkErr } - -type stubNetwork struct { - leases []libvirt.NetworkDHCPLease - getLeaseErr error -} - -func (n stubNetwork) GetDHCPLeases() ([]libvirt.NetworkDHCPLease, error) { - return n.leases, n.getLeaseErr -} - -func (n stubNetwork) Free() error { - return nil -} diff --git a/hack/qemu-metadata-api/virtwrapper/virtwrapper_cross.go b/hack/qemu-metadata-api/virtwrapper/virtwrapper_cross.go index 24c1b722c9..2faa959612 100644 --- a/hack/qemu-metadata-api/virtwrapper/virtwrapper_cross.go +++ b/hack/qemu-metadata-api/virtwrapper/virtwrapper_cross.go @@ -20,14 +20,21 @@ func (c *Connect) LookupNetworkByName(_ string) (*Network, error) { } // Network wraps a libvirt network. -type Network struct{} +type Network struct { + Net Net +} // GetDHCPLeases returns the underlying DHCP leases. // This function errors if CGO is disabled. func (n *Network) GetDHCPLeases() ([]NetworkDHCPLease, error) { - return nil, errors.New("using virtwrapper requires building with CGO") + return n.Net.GetDHCPLeases() } // Free the network resource. // This function does nothing if CGO is disabled. func (n *Network) Free() {} + +// Net is a libvirt Network. +type Net interface { + GetDHCPLeases() ([]NetworkDHCPLease, error) +}