Debian Codegraph @

pkg/utils/iptables_test.go

raw symbols SCIP
1 // Copyright 2017-2018 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 utilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/
16
17 import (
18 "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/"
19 "math/randscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/"
20 "runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/"
21
22 "github.com/coreos/go-iptables/iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/"
23 . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/"
24 . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/"
25
26 "github.com/containernetworking/plugins/pkg/nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/"
27 "github.com/containernetworking/plugins/pkg/testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/"
28 )
29
30 const TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/TABLE. = "filter" // We'll monkey around here
31
32 var _ = Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("chain tests", func() {
33 var testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:testChain. string
34 var iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt. *iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.IPTablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#
35 var cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:cleanup. func()
36
37 BeforeEachscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/BeforeEach().(func() {
38 // Save a reference to the original namespace,
39 // Add a new NS
40 currNs, err := nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.GetCurrentNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/GetCurrentNS().()
41 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().())
42
43 testNs, err := testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.NewNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/NewNS().()
44 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().())
45
46 testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:testChain. = fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("cni-test-%d", randscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/Intn().(10000000))
47
48 iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt., err = iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.NewWithProtocolscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/NewWithProtocol().(iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.ProtocolIPv4scip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/ProtocolIPv4.)
49 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().())
50
51 runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/.LockOSThreadscip-go gomod github.com/golang/go/src go1.24.2 runtime/LockOSThread().()
52 err = testNs.Setscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Set.()
53 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().())
54
55 cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:cleanup. = func() {
56 if iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt. == nil {
57 return
58 }
59 iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt..ClearChainscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ClearChain().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:testChain.)
60 iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt..DeleteChainscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#DeleteChain().(TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:testChain.)
61 currNs.Setscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Set.()
62 }
63 })
64
65 AfterEachscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/AfterEach().(func() {
66 cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:cleanup.()
67 })
68
69 Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("EnsureChain", func() {
70 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("creates chains idempotently", func() {
71 err := EnsureChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/EnsureChain().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt., TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:testChain.)
72 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().())
73
74 // Create it again!
75 err = EnsureChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/EnsureChain().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt., TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:testChain.)
76 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().())
77 })
78 })
79
80 Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("DeleteChain", func() {
81 Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("delete chains idempotently", func() {
82 // Create chain
83 err := EnsureChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/EnsureChain().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt., TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:testChain.)
84 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().())
85
86 // Delete chain
87 err = DeleteChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/DeleteChain().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt., TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:testChain.)
88 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().())
89
90 // Delete it again!
91 err = DeleteChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/DeleteChain().(iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:ipt., TABLEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/TABLE., testChainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:testChain.)
92 Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().())
93 })
94 })
95 })