Skip to content

Commit

Permalink
bazel: allow "bazel test" to work without cgo dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 committed Aug 18, 2023
1 parent e06b64c commit 9de510b
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 130 deletions.
33 changes: 10 additions & 23 deletions bootstrapper/internal/diskencryption/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
],
)
2 changes: 0 additions & 2 deletions bootstrapper/internal/diskencryption/diskencryption_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build linux && cgo

/*
Copyright (c) Edgeless Systems GmbH
Expand Down
12 changes: 4 additions & 8 deletions bootstrapper/internal/initserver/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -55,9 +57,3 @@ go_test(
"@org_uber_go_goleak//:goleak",
],
)

go_ld_test(
name = "initserver_ld_test",
src = "initserver_test",
ld = "//rpm:ld",
)
12 changes: 4 additions & 8 deletions bootstrapper/internal/joinclient/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -53,9 +55,3 @@ go_test(
"@org_uber_go_goleak//:goleak",
],
)

go_ld_test(
name = "joinclient_ld_test",
src = "joinclient_test",
ld = "//rpm:ld",
)
12 changes: 4 additions & 8 deletions csi/cryptmapper/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
)
18 changes: 9 additions & 9 deletions hack/qemu-metadata-api/server/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -33,9 +39,3 @@ go_test(
"@org_libvirt_go_libvirt//:libvirt",
],
)

go_ld_test(
name = "server_ld_test",
src = "server_test",
ld = "//rpm:ld",
)
41 changes: 41 additions & 0 deletions hack/qemu-metadata-api/server/server_cgo_test.go
Original file line number Diff line number Diff line change
@@ -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
}
31 changes: 31 additions & 0 deletions hack/qemu-metadata-api/server/server_cross_test.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 9de510b

Please sign in to comment.