Skip to content

Commit

Permalink
Remove test deps from definition
Browse files Browse the repository at this point in the history
This lets us migrate away from WORKSPACE files to bzlmod.  Currently,
the test dependencies were pulled in via WORKSPACE.bzlmod, but this is
no longer necessary.  This change instead moves them into MODULE.bazel
and into the appropriate end to end test.  In addition, we move the
path construction in our tests to use bazel runfiles instead of raw
path construction.
  • Loading branch information
kellyma2 committed Feb 5, 2025
1 parent 850d24a commit 5e4e039
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 55 deletions.
7 changes: 0 additions & 7 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,3 @@ bzl_library(
"@bazeldnf//bazeldnf:deps",
],
)

bzl_library(
name = "test_deps",
srcs = ["test_deps.bzl"],
visibility = ["//visibility:public"],
deps = ["@bazeldnf//bazeldnf:defs"],
)
31 changes: 30 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,35 @@ module(

bazeldnf = use_extension("//bazeldnf:extensions.bzl", "bazeldnf")
bazeldnf.toolchain()
use_repo(bazeldnf, "bazeldnf_toolchains")
bazeldnf.rpm(
name = "abseil-cpp-devel-20240722.1-1.fc42.x86_64.rpm",
sha256 = "1393c28f5a3f3029769bbe3436b3eec58c7b11761c4ad6695c309b21474d9804",
urls = [
"https://kojipkgs.fedoraproject.org//packages/abseil-cpp/20240722.1/1.fc42/x86_64/abseil-cpp-devel-20240722.1-1.fc42.x86_64.rpm",
],
)
bazeldnf.rpm(
name = "libvirt-devel-11.0.0-1.fc42.x86_64.rpm",
sha256 = "dba37bbe57903afe49b5666f1781eb50001baa81af4584b355db0b6a2afad9fa",
urls = [
"https://kojipkgs.fedoraproject.org//packages/libvirt/11.0.0/1.fc42/x86_64/libvirt-devel-11.0.0-1.fc42.x86_64.rpm",
],
)
bazeldnf.rpm(
name = "libvirt-libs-11.0.0-1.fc42.x86_64.rpm",
sha256 = "aac272a2ace134b5ef60a41e6624deb24331e79c76699ef6cef0dca22d94ac7e",
urls = [
"https://kojipkgs.fedoraproject.org//packages/libvirt/11.0.0/1.fc42/x86_64/libvirt-libs-11.0.0-1.fc42.x86_64.rpm",
],
)

use_repo(
bazeldnf,
"bazeldnf_toolchains",
"abseil-cpp-devel-20240722.1-1.fc42.x86_64.rpm",
"libvirt-devel-11.0.0-1.fc42.x86_64.rpm",
"libvirt-libs-11.0.0-1.fc42.x86_64.rpm",
)

# registers toolchain for consumers of the repo
register_toolchains("@bazeldnf_toolchains//:all")
Expand All @@ -27,6 +55,7 @@ use_repo(
go_deps,
"com_github_adrg_xdg",
"com_github_bazelbuild_buildtools",
"com_github_bazelbuild_rules_go",
"com_github_crillab_gophersat",
"com_github_onsi_gomega",
"com_github_sassoftware_go_rpmutils",
Expand Down
3 changes: 0 additions & 3 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
workspace(name = "bazeldnf")

load(":test_deps.bzl", "bazeldnf_test_dependencies")

bazeldnf_test_dependencies()
19 changes: 15 additions & 4 deletions e2e/bazel-workspace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local_repository(
path = "../../",
)

load("@bazeldnf//bazeldnf:defs.bzl", "rpm")
load(
"@bazeldnf//bazeldnf:repositories.bzl",
"bazeldnf_dependencies",
Expand All @@ -15,10 +16,20 @@ bazeldnf_register_toolchains(
name = "bazeldnf_prebuilt",
)

# dependencies for integration tests
load("@bazeldnf//:test_deps.bzl", "bazeldnf_test_dependencies")

bazeldnf_test_dependencies()
rpm(
name = "libvirt-devel-11.0.0-1.fc42.x86_64.rpm",
sha256 = "dba37bbe57903afe49b5666f1781eb50001baa81af4584b355db0b6a2afad9fa",
urls = [
"https://kojipkgs.fedoraproject.org//packages/libvirt/11.0.0/1.fc42/x86_64/libvirt-devel-11.0.0-1.fc42.x86_64.rpm",
],
)
rpm(
name = "libvirt-libs-11.0.0-1.fc42.x86_64.rpm",
sha256 = "aac272a2ace134b5ef60a41e6624deb24331e79c76699ef6cef0dca22d94ac7e",
urls = [
"https://kojipkgs.fedoraproject.org//packages/libvirt/11.0.0/1.fc42/x86_64/libvirt-libs-11.0.0-1.fc42.x86_64.rpm",
],
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ require (
sigs.k8s.io/yaml v1.4.0
)

require github.com/bazelbuild/rules_go v0.52.0

require (
github.com/adrg/xdg v0.5.3
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.11.1 // indirect
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
github.com/bazelbuild/buildtools v0.0.0-20240823132350-3488089d3661 h1:acJJwAuD2t36RHnvxf3oh9lhg5LISUYXunx+om2ONZw=
github.com/bazelbuild/buildtools v0.0.0-20240823132350-3488089d3661/go.mod h1:yBQGNvRAGhcBTxe4MHiW3Ul7DwoBim4XsKUaXnW1LWc=
github.com/bazelbuild/buildtools v0.0.0-20250110114635-13fa61383b99 h1:3Wvirn7fGxAk5XMO5OV9goElw2ZKya/erxxHChPSPQM=
github.com/bazelbuild/buildtools v0.0.0-20250110114635-13fa61383b99/go.mod h1:PLNUetjLa77TCCziPsz0EI8a6CUxgC+1jgmWv0H25tg=
github.com/bazelbuild/rules_go v0.52.0 h1:+ozpngVAW67pCAwfhepaXSSrG3yHcj8K9hNAxSYBno4=
github.com/bazelbuild/rules_go v0.52.0/go.mod h1:M+YrupNArA7OiTlv++rFUgQ6Sm+ZXbQ5HPUj0cGa0us=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/crillab/gophersat v1.4.0 h1:irf9ajKmNnEURjgPU4oz+ouqIXXLQ59ZNd3NC+hULMc=
github.com/crillab/gophersat v1.4.0/go.mod h1:gDzeMEBrqJR20IL9JW25tFHNGLU5+GDeJzr0zpi3mxs=
Expand All @@ -15,8 +15,8 @@ github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ4
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand All @@ -43,9 +43,9 @@ github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3k
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -65,9 +65,8 @@ golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
Expand Down
1 change: 1 addition & 0 deletions pkg/rpm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ go_test(
embed = [":rpm"],
deps = [
"//pkg/api",
"@com_github_bazelbuild_rules_go//go/runfiles",
"@com_github_onsi_gomega//:gomega",
],
)
24 changes: 20 additions & 4 deletions pkg/rpm/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ import (
"path/filepath"
"testing"

"github.com/bazelbuild/rules_go/go/runfiles"
. "github.com/onsi/gomega"
)

func TestRPMToTar(t *testing.T) {
libvirtLibsRpm, err := runfiles.Rlocation("libvirt-libs-11.0.0-1.fc42.x86_64.rpm/rpm/downloaded")
if err != nil {
panic(err)
}

tests := []struct {
name string
rpm string
Expand All @@ -23,7 +29,7 @@ func TestRPMToTar(t *testing.T) {
}{
{
name: "should convert a RPM to tar and keep all entries",
rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), "libvirt-libs-11.0.0-1.fc42.x86_64.rpm/rpm/downloaded"),
rpm: libvirtLibsRpm,
wantErr: false,
expectedHeaders: []*tar.Header{
{Name: "./etc/libvirt/libvirt-admin.conf", Size: 450, Mode: 33188},
Expand Down Expand Up @@ -83,6 +89,16 @@ func TestRPMToTar(t *testing.T) {
}

func TestTar2Files(t *testing.T) {
abseilCppDevelRpm, err := runfiles.Rlocation("abseil-cpp-devel-20240722.1-1.fc42.x86_64.rpm/rpm/downloaded")
if err != nil {
panic(err)
}

libvirtLibsRpm, err := runfiles.Rlocation("libvirt-libs-11.0.0-1.fc42.x86_64.rpm/rpm/downloaded")
if err != nil {
panic(err)
}

tests := []struct {
name string
rpm string
Expand All @@ -93,7 +109,7 @@ func TestTar2Files(t *testing.T) {
}{
{
name: "should extract a symlink from a tar archive",
rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), "libvirt-libs-11.0.0-1.fc42.x86_64.rpm/rpm/downloaded"),
rpm: libvirtLibsRpm,
wantErr: false,
files: []string{"/usr/lib64/libvirt.so.0"},
expected: []fileInfo{
Expand All @@ -107,7 +123,7 @@ func TestTar2Files(t *testing.T) {
},
{
name: "should extract multiple files from a tar archive",
rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), "libvirt-libs-11.0.0-1.fc42.x86_64.rpm/rpm/downloaded"),
rpm: libvirtLibsRpm,
wantErr: false,
files: []string{
"/etc/libvirt/libvirt-admin.conf",
Expand All @@ -125,7 +141,7 @@ func TestTar2Files(t *testing.T) {
},
{
name: "should extract multiple files with the same name from a tar archive",
rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), "abseil-cpp-devel-20240722.1-1.fc42.x86_64.rpm/rpm/downloaded"),
rpm: abseilCppDevelRpm,
wantErr: false,
files: []string{
"/usr/include/absl/log/globals.h",
Expand Down
28 changes: 0 additions & 28 deletions test_deps.bzl

This file was deleted.

0 comments on commit 5e4e039

Please sign in to comment.