Merge pull request #73468 from randmonkey/issue73462_fix_testentry

fix TestEntry
This commit is contained in:
Kubernetes Prow Robot 2019-01-29 18:22:31 -08:00 committed by GitHub
commit 1386b148df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -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. // 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) { func (runner *runner) TestEntry(entry string, set string) (bool, error) {
if out, err := runner.exec.Command(IPSetCmd, "test", set, entry).CombinedOutput(); err == nil { 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)) { if e == nil && reg.MatchString(string(out)) {
return false, nil return false, nil
} else if e == nil { } else if e == nil {

View File

@ -461,14 +461,14 @@ func TestTestEntry(t *testing.T) {
Protocol: ProtocolTCP, Protocol: ProtocolTCP,
SetType: HashIPPort, SetType: HashIPPort,
} }
setName := "NOT"
fcmd := fakeexec.FakeCmd{ fcmd := fakeexec.FakeCmd{
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{ CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
// Success // 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 // Failure
func() ([]byte, error) { 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) runner := New(&fexec)
// Success // Success
ok, err := runner.TestEntry(testEntry.String(), "FOOBAR") ok, err := runner.TestEntry(testEntry.String(), setName)
if err != nil { if err != nil {
t.Errorf("expected success, got %v", err) t.Errorf("expected success, got %v", err)
} }
if fcmd.CombinedOutputCalls != 1 { if fcmd.CombinedOutputCalls != 1 {
t.Errorf("expected 2 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls) 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]) t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[0])
} }
if !ok { if !ok {