mirror of https://github.com/docker/docs.git
Merge pull request #8321 from erikh/ui_save_output
docker save: Do not save to a terminal.
This commit is contained in:
commit
350e1b783d
|
@ -5,6 +5,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -2411,7 +2412,10 @@ func (cli *DockerCli) CmdSave(args ...string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else if cli.isTerminalOut {
|
||||||
|
return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cmd.Args()) == 1 {
|
if len(cmd.Args()) == 1 {
|
||||||
image := cmd.Arg(0)
|
image := cmd.Arg(0)
|
||||||
if err := cli.stream("GET", "/images/"+image+"/get", nil, output, nil); err != nil {
|
if err := cli.stream("GET", "/images/"+image+"/get", nil, output, nil); err != nil {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -8,6 +9,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/vendor/src/github.com/kr/pty"
|
||||||
)
|
)
|
||||||
|
|
||||||
// save a repo and try to load it using stdout
|
// save a repo and try to load it using stdout
|
||||||
|
@ -70,6 +73,34 @@ func TestSaveAndLoadRepoStdout(t *testing.T) {
|
||||||
|
|
||||||
logDone("save - save a repo using stdout")
|
logDone("save - save a repo using stdout")
|
||||||
logDone("load - load a repo using stdout")
|
logDone("load - load a repo using stdout")
|
||||||
|
|
||||||
|
pty, tty, err := pty.Open()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not open pty: %v", err)
|
||||||
|
}
|
||||||
|
cmd := exec.Command(dockerBinary, "save", repoName)
|
||||||
|
cmd.Stdin = tty
|
||||||
|
cmd.Stdout = tty
|
||||||
|
cmd.Stderr = tty
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
t.Fatalf("start err: %v", err)
|
||||||
|
}
|
||||||
|
if err := cmd.Wait(); err == nil {
|
||||||
|
t.Fatal("did not break writing to a TTY")
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := make([]byte, 1024)
|
||||||
|
|
||||||
|
n, err := pty.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("could not read tty output")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bytes.Contains(buf[:n], []byte("Cowardly refusing")) {
|
||||||
|
t.Fatal("help output is not being yielded", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("save - do not save to a tty")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveSingleTag(t *testing.T) {
|
func TestSaveSingleTag(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue