mirror of https://github.com/k3s-io/k3s
Discard stderr output when calling iptables-save
parent
df23697ae7
commit
00e7505618
|
@ -20,6 +20,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -332,7 +333,7 @@ func (runner *runner) SaveInto(table Table, buffer *bytes.Buffer) error {
|
|||
// creates a new buffer, redirects stdout and stderr to it and also
|
||||
// calls Run()].
|
||||
cmd.SetStdout(buffer)
|
||||
cmd.SetStderr(buffer)
|
||||
cmd.SetStderr(ioutil.Discard)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
|
|
|
@ -932,6 +932,8 @@ func testSaveInto(t *testing.T, protocol Protocol) {
|
|||
COMMIT
|
||||
# Completed on Thu Jan 19 11:38:09 2017`, iptablesSaveCmd+version)
|
||||
|
||||
stderrOutput := "#STDERR OUTPUT" // SaveInto() should should NOT capture stderr into the buffer
|
||||
|
||||
fcmd := fakeexec.FakeCmd{
|
||||
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
|
||||
// iptables version check
|
||||
|
@ -940,7 +942,7 @@ COMMIT
|
|||
func() ([]byte, error) { return []byte(iptablesRestoreCmd + version), nil },
|
||||
},
|
||||
RunScript: []fakeexec.FakeRunAction{
|
||||
func() ([]byte, []byte, error) { return []byte(output), nil, nil },
|
||||
func() ([]byte, []byte, error) { return []byte(output), []byte(stderrOutput), nil },
|
||||
func() ([]byte, []byte, error) { return nil, nil, &fakeexec.FakeExitError{Status: 1} },
|
||||
},
|
||||
}
|
||||
|
@ -962,8 +964,8 @@ COMMIT
|
|||
t.Fatalf("%s: Expected success, got %v", protoStr, err)
|
||||
}
|
||||
|
||||
if string(buffer.Bytes()[:len(output)]) != output {
|
||||
t.Errorf("%s: Expected output '%s', got '%v'", protoStr, output, buffer.Bytes())
|
||||
if string(buffer.Bytes()) != output {
|
||||
t.Errorf("%s: Expected output '%s', got '%v'", protoStr, output, string(buffer.Bytes()))
|
||||
}
|
||||
|
||||
if fcmd.CombinedOutputCalls != 2 {
|
||||
|
|
Loading…
Reference in New Issue