Skip to content

Commit

Permalink
Merge pull request moby#46246 from thaJeztah/fix_TestFirewalldInit
Browse files Browse the repository at this point in the history
libnetwork/iptables: fix TestFirewalldInit
  • Loading branch information
thaJeztah authored Aug 23, 2023
2 parents 9b9348c + d979d2a commit 71f4916
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions libnetwork/iptables/firewalld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@ import (
"net"
"strconv"
"testing"

"github.com/godbus/dbus/v5"
)

func TestFirewalldInit(t *testing.T) {
if !checkRunning() {
t.Skip("firewalld is not running")
func skipIfNoFirewalld(t *testing.T) {
t.Helper()
conn, err := dbus.SystemBus()
if err != nil {
t.Skipf("cannot connect to D-bus system bus: %v", err)
}
defer conn.Close()

var zone string
err = conn.Object(dbusInterface, dbusPath).Call(dbusInterface+".getDefaultZone", 0).Store(&zone)
if err != nil {
t.Skipf("firewalld is not running: %v", err)
}
}

func TestFirewalldInit(t *testing.T) {
skipIfNoFirewalld(t)
if err := firewalldInit(); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -71,9 +86,7 @@ func TestReloaded(t *testing.T) {
}

func TestPassthrough(t *testing.T) {
if !firewalldRunning {
t.Skip("firewalld is not running")
}
skipIfNoFirewalld(t)
rule1 := []string{
"-i", "lo",
"-p", "udp",
Expand Down

0 comments on commit 71f4916

Please sign in to comment.