Dump stdin to a temporary file in kubectl replace --force

This commit is contained in:
Marcin Wielgus
2015-07-15 14:10:47 +02:00
parent 8f3c3108b8
commit 866bd7b4e5
4 changed files with 67 additions and 1 deletions

View File

@@ -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)
}
}