func junit(ctx context.Context, t model.KeyedTest, sub model.KeyedSubmission, ball io.Reader) error { if _, ok := t.Params["test"]; !ok { return ErrMissingParam("test") } tests := model.StoredObject{ Bucket: util.TestsBucket, Name: t.Params["test"], } testStream := stream(ctx, tests) tr, err := runner.JUnit(ctx, testStream, ball) if err != nil { return err } if _, err := tr.PutWithParent(ctx, sub.Key); err != nil { return err } // TODO(flowlo): Use a json.Encoder body, err := json.Marshal(tr) if err != nil { return err } return ws.Write(sub.Key.Parent(), body) }
func coderJunit(ctx context.Context, t model.KeyedTest, sub model.KeyedSubmission, ball io.Reader) (err error) { if _, ok := t.Params["code"]; !ok { return ErrMissingParam("code") } code := model.StoredObject{ Bucket: util.TestsBucket, Name: t.Params["code"], } codeStream := stream(ctx, code) var tr *model.JunitTestResult if tr, err = runner.JUnit(ctx, ball, codeStream); err != nil { return } shouldFail, err := strconv.ParseBool(t.Params["shouldFail"]) if err != nil { return } ctr := model.CoderJunitTestResult{ JunitTestResult: *tr, ShouldFail: shouldFail, } if _, err = ctr.Put(ctx, nil); err != nil { return } var body []byte if body, err = json.Marshal(ctr); err != nil { return } return ws.Write(sub.Key.Parent(), body) }
func simple(ctx context.Context, t model.KeyedTest, sub model.KeyedSubmission, ball io.Reader) (err error) { str, err := runner.Simple(ctx, sub, ball) if err != nil { return } // TODO(flowlo): Use a json.Encoder var body []byte if body, err = json.Marshal(str); err != nil { return } return ws.Write(sub.Key.Parent(), body) }
func simple(ctx context.Context, params map[string]string, sub model.KeyedSubmission) error { log.Debugf(ctx, "Executing simple tester") stdout, stderr, err := runner.Simple(ctx, sub) log.Warningf(ctx, "%s %s %s", stdout, stderr, err) j, _ := json.Marshal(struct { Stdout string Stderr string }{ Stdout: stdout.String(), Stderr: stderr.String(), }) return ws.Write(sub.Key, j) }
func junit(ctx context.Context, params map[string]string, sub model.KeyedSubmission) error { log.Debugf(ctx, "Executing junit tester") stdout, stderr, utr, err := runner.JUnit(ctx, params, sub) log.Warningf(ctx, "%s %s %s", stdout, stderr, err) j, _ := json.Marshal(struct { Stdout string Stderr string Results []model.UnitTestResults }{ Stdout: stdout.String(), Stderr: stderr.String(), Results: utr, }) return ws.Write(sub.Key, j) }
func diff(ctx context.Context, t model.KeyedTest, sub model.KeyedSubmission, ball io.Reader) (err error) { if _, ok := t.Params["tests"]; !ok { return ErrMissingParam("tests") } ts, err := runner.OutMatchDiffRun(ctx, t, sub, ball) if err != nil { return } // TODO(flowlo): Use a json.Encoder var body []byte if body, err = json.Marshal(ts); err != nil { return err } return ws.Write(sub.Key.Parent(), body) }
func iot(ctx context.Context, t model.KeyedTest, sub model.KeyedSubmission, ball io.Reader) error { if err := checkIoParams(t.Params); err != nil { return err } ts, err := runner.IODiffRun(ctx, t, sub, ball) if err != nil { return err } // TODO(flowlo): Use a json.Encoder var body []byte if body, err = json.Marshal(ts); err != nil { return err } return ws.Write(sub.Key.Parent(), body) }
func robot(ctx context.Context, t model.KeyedTest, sub model.KeyedSubmission, ball io.Reader) (err error) { log.Debugf(ctx, "Executing robot tester") var testMap io.ReadCloser if testMap, err = util.Load(util.CloudContext(ctx), util.TemplateBucket, t.Params["tests"]); err != nil { return } defer testMap.Close() var testMapBytes, stdinBytes []byte tr := tar.NewReader(ball) if _, err = tr.Next(); err != nil { return err } if stdinBytes, err = ioutil.ReadAll(tr); err != nil { return err } if testMapBytes, err = ioutil.ReadAll(testMap); err != nil { return } var m Map if err = json.Unmarshal(testMapBytes, &m); err != nil { return } moves, err := testRobot(m, string(stdinBytes)) if err != nil { // TODO(victorbalan): Pass the error to the ws so the client knows what he's doing wrong return } var body []byte if body, err = json.Marshal(moves); err != nil { return } return ws.Write(sub.Key.Parent(), body) }