Skip to content

Commit

Permalink
Merge pull request #95697 from masap/ipset1
Browse files Browse the repository at this point in the history
ipset: Address a TODO, add test for TestEntry() with IPv6 address
  • Loading branch information
k8s-ci-robot committed Nov 5, 2020
2 parents fdd2f51 + c6d2808 commit f3fbd17
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion pkg/util/ipset/ipset_test.go
Expand Up @@ -454,7 +454,6 @@ func TestDelEntry(t *testing.T) {
}

func TestTestEntry(t *testing.T) {
// TODO: IPv6?
testEntry := &Entry{
IP: "10.120.7.100",
Port: 8080,
Expand Down Expand Up @@ -502,6 +501,54 @@ func TestTestEntry(t *testing.T) {
}
}

func TestTestEntryIPv6(t *testing.T) {
testEntry := &Entry{
IP: "fd00:1234:5678:dead:beaf::1",
Port: 8080,
Protocol: ProtocolTCP,
SetType: HashIPPort,
}
setName := "NOT"
fcmd := fakeexec.FakeCmd{
CombinedOutputScript: []fakeexec.FakeAction{
// Success
func() ([]byte, []byte, error) {
return []byte("fd00:1234:5678:dead:beaf::1,tcp:8080 is in set " + setName + "."), nil, nil
},
// Failure
func() ([]byte, []byte, error) {
return []byte("fd00::2,tcp:8080 is NOT in set FOOBAR."), nil, &fakeexec.FakeExitError{Status: 1}
},
},
}
fexec := fakeexec.FakeExec{
CommandScript: []fakeexec.FakeCommandAction{
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
},
}
runner := New(&fexec)
// Success
ok, err := runner.TestEntry(testEntry.String(), setName)
if err != nil {
t.Errorf("expected success, got %v", err)
}
if fcmd.CombinedOutputCalls != 1 {
t.Errorf("expected 1 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls)
}
if !sets.NewString(fcmd.CombinedOutputLog[0]...).HasAll("ipset", "test", setName, "fd00:1234:5678:dead:beaf::1,tcp:8080") {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[0])
}
if !ok {
t.Errorf("expect entry exists in test set, got not")
}
// Failure
ok, err = runner.TestEntry(testEntry.String(), "FOOBAR")
if err == nil || ok {
t.Errorf("expect entry doesn't exist in test set")
}
}

func TestListEntries(t *testing.T) {

output := `Name: foobar
Expand Down

0 comments on commit f3fbd17

Please sign in to comment.