mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 11:18:16 +00:00
Dump stdin to a temporary file in kubectl replace --force
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
@@ -298,3 +299,25 @@ func TestCheckInvalidErr(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDumpReaderToFile(t *testing.T) {
|
||||
testString := "TEST STRING"
|
||||
tempFile, err := ioutil.TempFile("", "hlpers_test_dump_")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error setting up a temporary file %v", err)
|
||||
}
|
||||
defer syscall.Unlink(tempFile.Name())
|
||||
defer tempFile.Close()
|
||||
err = DumpReaderToFile(strings.NewReader(testString), tempFile.Name())
|
||||
if err != nil {
|
||||
t.Errorf("error in DumpReaderToFile: %v", err)
|
||||
}
|
||||
data, err := ioutil.ReadFile(tempFile.Name())
|
||||
if err != nil {
|
||||
t.Errorf("error when reading %s: %v", tempFile, err)
|
||||
}
|
||||
stringData := string(data)
|
||||
if stringData != testString {
|
||||
t.Fatalf("Wrong file content %s != %s", testString, stringData)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user