示例#1
0
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)
}
示例#2
0
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)
}
示例#3
0
文件: junit.go 项目: pbochis/api
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)
}