@@ -15,6 +15,7 @@ import (
1515 "github.com/sachaos/ac-deck/lib/atcoder"
1616 "github.com/sirupsen/logrus"
1717 "io"
18+ "io/ioutil"
1819 "os"
1920 "path"
2021 "strings"
@@ -59,14 +60,37 @@ func NewContainerTester(ctx context.Context, cli *client.Client, conf *files.Con
5960 }, nil
6061}
6162
62- func (t * ContainerTester ) Run (ctx context.Context , r io.Reader , w io.Writer , ew io.Writer ) error {
63- result , err := ExecWithStdin ( ctx , t . cli , t . containerId , strings . Split ( t . conf . Environment . Cmd , " " ), r )
63+ func (t * ContainerTester ) Run (ctx context.Context , stdin io.Reader , w io.Writer , ew io.Writer ) error {
64+ contentBytes , err := ioutil . ReadAll ( stdin )
6465 if err != nil {
6566 return err
6667 }
68+ content := string (contentBytes ) + "\n "
6769
68- io .Copy (w , result .Stdout )
69- io .Copy (ew , result .Stderr )
70+ var buf bytes.Buffer
71+ tw := tar .NewWriter (& buf )
72+ tw .WriteHeader (& tar.Header {
73+ Name : "example" ,
74+ Mode : 0666 ,
75+ Size : int64 (len (content )),
76+ })
77+ tw .Write ([]byte (content ))
78+ tw .Close ()
79+
80+ err = t .cli .CopyToContainer (ctx , t .containerId , "/" , & buf , types.CopyToContainerOptions {})
81+ if err != nil {
82+ return err
83+ }
84+
85+ logrus .Debug ("Run test" )
86+ cmd := []string {"sh" , "-c" , fmt .Sprintf ("cat /example | %s" , t .conf .Environment .Cmd )}
87+ r , err := ExecWithStdin (ctx , t .cli , t .containerId , cmd , strings .NewReader ("" ))
88+ if err != nil {
89+ return err
90+ }
91+
92+ io .Copy (w , r .Stdout )
93+ io .Copy (ew , r .Stderr )
7094
7195 return nil
7296}
@@ -222,6 +246,7 @@ func ExecWithStdin(ctx context.Context, cli *client.Client, name string, cmd []s
222246 go func () {
223247 logrus .Debug ("Sending input data" )
224248 _ , err = io .Copy (res .Conn , stdin )
249+ logrus .Debug ("Finish sending input data" )
225250 }()
226251
227252 select {
0 commit comments