Skip to content

Commit

Permalink
Merging develop to master for v0.13.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Jun 6, 2016
2 parents 3589d5b + c569983 commit 53ac311
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 129 deletions.
7 changes: 4 additions & 3 deletions jobs/app/controllers/status.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package controllers

import (
"github.com/revel/revel"
"github.com/revel/modules/jobs/app/jobs"
"github.com/robfig/cron"
"strings"

"github.com/revel/cron"
"github.com/revel/modules/jobs/app/jobs"
"github.com/revel/revel"
)

type Jobs struct {
Expand Down
5 changes: 3 additions & 2 deletions jobs/app/jobs/job.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package jobs

import (
"github.com/revel/revel"
"github.com/robfig/cron"
"reflect"
"runtime/debug"
"sync"
"sync/atomic"

"github.com/revel/cron"
"github.com/revel/revel"
)

type Job struct {
Expand Down
5 changes: 3 additions & 2 deletions jobs/app/jobs/jobrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
package jobs

import (
"github.com/revel/revel"
"github.com/robfig/cron"
"strings"
"time"

"github.com/revel/cron"
"github.com/revel/revel"
)

// Callers can use jobs.Func to wrap a raw func.
Expand Down
3 changes: 2 additions & 1 deletion jobs/app/jobs/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package jobs

import (
"fmt"

"github.com/revel/cron"
"github.com/revel/revel"
"github.com/robfig/cron"
)

const DEFAULT_JOB_POOL_SIZE = 10
Expand Down
103 changes: 89 additions & 14 deletions testrunner/app/controllers/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"html/template"
"reflect"
"sort"
"strings"

"github.com/revel/revel"
Expand Down Expand Up @@ -67,9 +68,26 @@ var (

// Index is an action which renders the full list of available test suites and their tests.
func (c TestRunner) Index() revel.Result {
c.RenderArgs["suiteFound"] = len(testSuites) > 0
return c.Render(testSuites)
}

// Suite method allows user to navigate to individual Test Suite and their tests
func (c TestRunner) Suite(suite string) revel.Result {
var foundTestSuites []TestSuiteDesc
for _, testSuite := range testSuites {
if strings.EqualFold(testSuite.Name, suite) {
foundTestSuites = append(foundTestSuites, testSuite)
}
}

c.RenderArgs["testSuites"] = foundTestSuites
c.RenderArgs["suiteFound"] = len(foundTestSuites) > 0
c.RenderArgs["suiteName"] = suite

return c.RenderTemplate("TestRunner/Index.html")
}

// Run runs a single test, given by the argument.
func (c TestRunner) Run(suite, test string) revel.Result {
// Check whether requested test exists.
Expand Down Expand Up @@ -191,21 +209,40 @@ func describeSuite(testSuite interface{}) TestSuiteDesc {

// errorSummary gets an error and returns its summary in human readable format.
func errorSummary(err *revel.Error) (message string) {
message = fmt.Sprintf("%4sStatus: %s\n%4sIn %s", "", err.Description, "", err.Path)
expected_prefix := "(expected)"
actual_prefix := "(actual)"
errDesc := err.Description
//strip the actual/expected stuff to provide more condensed display.
if strings.Index(errDesc, expected_prefix) == 0 {
errDesc = errDesc[len(expected_prefix):len(errDesc)]
}
if strings.LastIndex(errDesc, actual_prefix) > 0 {
errDesc = errDesc[0 : len(errDesc)-len(actual_prefix)]
}

// If line of error isn't known return the message as is.
if err.Line == 0 {
return
errFile := err.Path
slashIdx := strings.LastIndex(errFile, "/")
if slashIdx > 0 {
errFile = errFile[slashIdx+1 : len(errFile)]
}

// Otherwise, include info about the line number and the relevant
// source code lines.
message += fmt.Sprintf(" (around line %d): ", err.Line)
for _, line := range err.ContextSource() {
if line.IsError {
message += line.Source
message = fmt.Sprintf("%s %s#%d", errDesc, errFile, err.Line)

/*
// If line of error isn't known return the message as is.
if err.Line == 0 {
return
}
}
// Otherwise, include info about the line number and the relevant
// source code lines.
message += fmt.Sprintf(" (around line %d): ", err.Line)
for _, line := range err.ContextSource() {
if line.IsError {
message += line.Source
}
}
*/

return
}
Expand All @@ -217,10 +254,38 @@ func formatResponse(t testing.TestSuite) map[string]string {
return map[string]string{}
}

// Since Go 1.6 http.Request struct contains `Cancel <-chan struct{}` which
// results in `json: unsupported type: <-chan struct {}`
// So pull out required things for Request and Response
req := map[string]interface{}{
"Method": t.Response.Request.Method,
"URL": t.Response.Request.URL,
"Proto": t.Response.Request.Proto,
"ContentLength": t.Response.Request.ContentLength,
"Header": t.Response.Request.Header,
"Form": t.Response.Request.Form,
"PostForm": t.Response.Request.PostForm,
}

resp := map[string]interface{}{
"Status": t.Response.Status,
"StatusCode": t.Response.StatusCode,
"Proto": t.Response.Proto,
"Header": t.Response.Header,
"ContentLength": t.Response.ContentLength,
"TransferEncoding": t.Response.TransferEncoding,
}

// Beautify the response JSON to make it human readable.
resp, err := json.MarshalIndent(t.Response, "", " ")
respBytes, err := json.MarshalIndent(
map[string]interface{}{
"Response": resp,
"Request": req,
},
"",
" ")
if err != nil {
revel.ERROR.Println(err)
fmt.Println(err)
}

// Remove extra new line symbols so they do not take too much space on a result page.
Expand All @@ -229,18 +294,28 @@ func formatResponse(t testing.TestSuite) map[string]string {
body = strings.Replace(body, "\r\n\r\n", "\r\n", -1)

return map[string]string{
"Headers": string(resp),
"Headers": string(respBytes),
"Body": strings.TrimSpace(body),
}
}

//sortbySuiteName sorts the testsuites by name.
type sortBySuiteName []interface{}

func (a sortBySuiteName) Len() int { return len(a) }
func (a sortBySuiteName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a sortBySuiteName) Less(i, j int) bool {
return reflect.TypeOf(a[i]).Elem().Name() < reflect.TypeOf(a[j]).Elem().Name()
}

func init() {
// Every time app is restarted convert the list of available test suites
// provided by the revel testing package into a format which will be used by
// the testrunner module and revel test cmd.
revel.OnAppStart(func() {
// Extracting info about available test suites from revel/testing package.
registeredTests = map[string]int{}
sort.Sort(sortBySuiteName(testing.TestSuites))
for _, testSuite := range testing.TestSuites {
testSuites = append(testSuites, describeSuite(testSuite))
}
Expand Down
Loading

0 comments on commit 53ac311

Please sign in to comment.