Skip to content

Commit 32f5756

Browse files
committed
Support proconio on run command
1 parent 759e866 commit 32f5756

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
BUILD_OPTION=-o acd -ldflags "-X github.com/sachaos/ac-deck/cmd.version=${VERSION}"
44

55
prepare:
6-
go get github.com/rakyll/statik
6+
go install github.com/rakyll/statik@latest
77
go generate
88

99
build: prepare

lib/tester/container.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

statik/statik.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)