Skip to content

Commit a4abc1d

Browse files
committed
refactor(golint): lint fixes for iptables test file
Signed-off-by: gkarthiks <[email protected]>
1 parent a812880 commit a4abc1d

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ pkg/ssh
219219
pkg/util/config
220220
pkg/util/ebtables
221221
pkg/util/goroutinemap/exponentialbackoff
222-
pkg/util/iptables/testing
223222
pkg/util/labels # See previous effort in PR #80685
224223
pkg/util/oom
225224
pkg/util/procfs

pkg/util/iptables/testing/fake.go

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,80 +26,106 @@ import (
2626
)
2727

2828
const (
29+
// Destination represents the destination address flag
2930
Destination = "-d "
30-
Source = "-s "
31-
DPort = "--dport "
32-
Protocol = "-p "
33-
Jump = "-j "
34-
Reject = "REJECT"
35-
ToDest = "--to-destination "
36-
Recent = "recent "
37-
MatchSet = "--match-set "
38-
SrcType = "--src-type "
39-
Masquerade = "MASQUERADE "
31+
// Source represents the source address flag
32+
Source = "-s "
33+
// DPort represents the destination port
34+
DPort = "--dport "
35+
// Protocol represents the protocol flag which takes input by number of name
36+
Protocol = "-p "
37+
// Jump represents jump flag specifies the jump target
38+
Jump = "-j "
39+
// Reject specifies the reject target
40+
Reject = "REJECT"
41+
// ToDest represents the --to-destination flag used to specify the destination address in DNAT
42+
ToDest = "--to-destination "
43+
// Recent represents the sub-command recent that allows to dynamically create list of IP address to match against
44+
Recent = "recent "
45+
// MatchSet represents the --match-set flag which match packets against the specified set
46+
MatchSet = "--match-set "
47+
// SrcType represents the --src-type flag which matches if the source address is of given type
48+
SrcType = "--src-type "
49+
// Masquerade represents the target that is used in nat table.
50+
Masquerade = "MASQUERADE "
4051
)
4152

53+
// Rule holds a map of rules.
4254
type Rule map[string]string
4355

44-
// no-op implementation of iptables Interface
56+
// FakeIPTables no-op implementation of iptables Interface.
4557
type FakeIPTables struct {
4658
hasRandomFully bool
4759
Lines []byte
4860
}
4961

62+
// NewFake returns a pointer for no-op implementation of iptables Interface.
5063
func NewFake() *FakeIPTables {
5164
return &FakeIPTables{}
5265
}
5366

67+
// SetHasRandomFully will enable the port maping fully randomized in the no-op implementation of iptables Interface.
5468
func (f *FakeIPTables) SetHasRandomFully(can bool) *FakeIPTables {
5569
f.hasRandomFully = can
5670
return f
5771
}
5872

73+
// EnsureChain will returns true and states the specified chain exists for testing.
5974
func (*FakeIPTables) EnsureChain(table iptables.Table, chain iptables.Chain) (bool, error) {
6075
return true, nil
6176
}
6277

78+
// FlushChain returns nil and states that the specified chain is cleared.
6379
func (*FakeIPTables) FlushChain(table iptables.Table, chain iptables.Chain) error {
6480
return nil
6581
}
6682

83+
// DeleteChain returns nil and states that the specified chain exists and it is deleted.
6784
func (*FakeIPTables) DeleteChain(table iptables.Table, chain iptables.Chain) error {
6885
return nil
6986
}
7087

88+
// EnsureRule return true and states that the specified rule is present.
7189
func (*FakeIPTables) EnsureRule(position iptables.RulePosition, table iptables.Table, chain iptables.Chain, args ...string) (bool, error) {
7290
return true, nil
7391
}
7492

93+
// DeleteRule returns nil and states that the specified rule is present and is deleted.
7594
func (*FakeIPTables) DeleteRule(table iptables.Table, chain iptables.Chain, args ...string) error {
7695
return nil
7796
}
7897

98+
// IsIpv6 returns false and states that it is managing only ipv4 tables.
7999
func (*FakeIPTables) IsIpv6() bool {
80100
return false
81101
}
82102

103+
// Save returns a copy of the iptables lines byte array.
83104
func (f *FakeIPTables) Save(table iptables.Table) ([]byte, error) {
84105
lines := make([]byte, len(f.Lines))
85106
copy(lines, f.Lines)
86107
return lines, nil
87108
}
88109

110+
// SaveInto calls `iptables-save` command for table and stores result in a given buffer.
89111
func (f *FakeIPTables) SaveInto(table iptables.Table, buffer *bytes.Buffer) error {
90112
buffer.Write(f.Lines)
91113
return nil
92114
}
93115

116+
// Restore returns null and states that it ran `iptables-restore` successfully.
94117
func (*FakeIPTables) Restore(table iptables.Table, data []byte, flush iptables.FlushFlag, counters iptables.RestoreCountersFlag) error {
95118
return nil
96119
}
97120

121+
// RestoreAll is the same as Restore except that no table is specified.
98122
func (f *FakeIPTables) RestoreAll(data []byte, flush iptables.FlushFlag, counters iptables.RestoreCountersFlag) error {
99123
f.Lines = data
100124
return nil
101125
}
102126

127+
// Monitor detects when the given iptables tables have been flushed by an external
128+
// tool (e.g. a firewall reload) by creating canary chains and polling to see if they have been deleted.
103129
func (f *FakeIPTables) Monitor(canary iptables.Chain, tables []iptables.Table, reloadFunc func(), interval time.Duration, stopCh <-chan struct{}) {
104130
}
105131

@@ -111,7 +137,7 @@ func getToken(line, separator string) string {
111137
return ""
112138
}
113139

114-
// GetChain returns a list of rules for the given chain.
140+
// GetRules returns a list of rules for the given chain.
115141
// The chain name must match exactly.
116142
// The matching is pretty dumb, don't rely on it for anything but testing.
117143
func (f *FakeIPTables) GetRules(chainName string) (rules []Rule) {
@@ -130,6 +156,7 @@ func (f *FakeIPTables) GetRules(chainName string) (rules []Rule) {
130156
return
131157
}
132158

159+
// HasRandomFully returns the value of the flag --random-fully
133160
func (f *FakeIPTables) HasRandomFully() bool {
134161
return f.hasRandomFully
135162
}

0 commit comments

Comments
 (0)