From d1f85ffa71808551cdb9941a908ba13c0774494d Mon Sep 17 00:00:00 2001 From: Yi Tao Date: Tue, 29 Jan 2019 20:57:26 +0800 Subject: [PATCH] fix TestEntry --- pkg/util/ipset/ipset.go | 2 +- pkg/util/ipset/ipset_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/util/ipset/ipset.go b/pkg/util/ipset/ipset.go index 2d400a6244e..454157ca5f6 100644 --- a/pkg/util/ipset/ipset.go +++ b/pkg/util/ipset/ipset.go @@ -330,7 +330,7 @@ func (runner *runner) DelEntry(entry string, set string) error { // TestEntry is used to check whether the specified entry is in the set or not. func (runner *runner) TestEntry(entry string, set string) (bool, error) { if out, err := runner.exec.Command(IPSetCmd, "test", set, entry).CombinedOutput(); err == nil { - reg, e := regexp.Compile("NOT") + reg, e := regexp.Compile("is NOT in set " + set) if e == nil && reg.MatchString(string(out)) { return false, nil } else if e == nil { diff --git a/pkg/util/ipset/ipset_test.go b/pkg/util/ipset/ipset_test.go index f5b95da0d2f..db041bab6da 100644 --- a/pkg/util/ipset/ipset_test.go +++ b/pkg/util/ipset/ipset_test.go @@ -461,14 +461,14 @@ func TestTestEntry(t *testing.T) { Protocol: ProtocolTCP, SetType: HashIPPort, } - + setName := "NOT" fcmd := fakeexec.FakeCmd{ CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{ // Success - func() ([]byte, error) { return []byte("10.120.7.100,tcp:8080 is in set FOOBAR."), nil }, + func() ([]byte, error) { return []byte("10.120.7.100,tcp:8080 is in set " + setName + "."), nil }, // Failure func() ([]byte, error) { - return []byte("192.168.1.3,tcp:8080 is NOT in set FOOBAR."), &fakeexec.FakeExitError{Status: 1} + return []byte("192.168.1.3,tcp:8080 is NOT in set " + setName + "."), &fakeexec.FakeExitError{Status: 1} }, }, } @@ -480,14 +480,14 @@ func TestTestEntry(t *testing.T) { } runner := New(&fexec) // Success - ok, err := runner.TestEntry(testEntry.String(), "FOOBAR") + ok, err := runner.TestEntry(testEntry.String(), setName) if err != nil { t.Errorf("expected success, got %v", err) } if fcmd.CombinedOutputCalls != 1 { t.Errorf("expected 2 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls) } - if !sets.NewString(fcmd.CombinedOutputLog[0]...).HasAll("ipset", "test", "FOOBAR", "10.120.7.100,tcp:8080") { + if !sets.NewString(fcmd.CombinedOutputLog[0]...).HasAll("ipset", "test", setName, "10.120.7.100,tcp:8080") { t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[0]) } if !ok {