Debian Codegraph @

pkg/utils/netfilter_test.go

raw symbols SCIP
1 // Copyright 2023 CNI authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package utils
16
17 import (
18 "os"
19
20 . "github.com/onsi/ginkgo/v2"
21 . "github.com/onsi/gomega"
22 )
23
24 var _ = Describe("netfilter support", func() {
25 When("it is available", func() {
26 It("reports that iptables is supported", func() {
27 Expect(SupportsIPTables()).To(BeTrue(), "This test should only fail if iptables is not available, but the test suite as a whole requires it to be available.")
28 })
29 It("reports that nftables is supported", func() {
30 Expect(SupportsNFTables()).To(BeTrue(), "This test should only fail if nftables is not available, but the test suite as a whole requires it to be available.")
31 })
32 })
33
34 // These are Serial because os.Setenv has process-wide effect
35 When("it is not available", Serial, func() {
36 var origPath string
37 BeforeEach(func() {
38 origPath = os.Getenv("PATH")
39 os.Setenv("PATH", "/does-not-exist")
40 })
41 AfterEach(func() {
42 os.Setenv("PATH", origPath)
43 })
44
45 It("reports that iptables is not supported", func() {
46 Expect(SupportsIPTables()).To(BeFalse(), "found iptables outside of PATH??")
47 })
48 It("reports that nftables is not supported", func() {
49 Expect(SupportsNFTables()).To(BeFalse(), "found nftables outside of PATH??")
50 })
51 })
52 })