--- a/loader/json.go Sat Jul 09 13:35:45 2016 -0500
+++ b/loader/json.go Sat Jul 09 14:08:24 2016 -0500
@@ -162,7 +162,7 @@
if json, found := req["json"]; found {
--- a/main.go Sat Jul 09 13:35:45 2016 -0500
+++ b/main.go Sat Jul 09 14:08:24 2016 -0500
@@ -12,7 +12,7 @@
- test_dir := flag.String("path", "resticide", "The path to search for tests")
+ testDir := flag.String("path", "resticide", "The path to search for tests") verbose := flag.Bool("verbose", false, "Whether or not to use verbose output")
host := flag.String("host", "", "The hostname to use")
workers := flag.Int("workers", runtime.NumCPU(), "How many workers to use to run tests")
@@ -33,7 +33,7 @@
report := reporter.NewReporter(*verbose)
report.AddHandler(new(reporter.ConsoleReporter))
- tests, err := loader.LoadTests(*test_dir, report)
+ tests, err := loader.LoadTests(*testDir, report) fmt.Printf("error %s\n", err.Error())
--- a/reporter/console_reporter.go Sat Jul 09 13:35:45 2016 -0500
+++ b/reporter/console_reporter.go Sat Jul 09 14:08:24 2016 -0500
@@ -46,9 +46,9 @@
writer := new(tabwriter.Writer)
writer.Init(os.Stdout, 2, 2, 2, ' ', 0)
- fmt.Fprintf(writer, "\tStatus Code\t%d\n", res.HttpResponse.StatusCode)
+ fmt.Fprintf(writer, "\tStatus Code\t%d\n", res.HTTPResponse.StatusCode) fmt.Fprintln(writer, "\tHeaders:")
- for name, value := range res.HttpResponse.Header {
+ for name, value := range res.HTTPResponse.Header { fmt.Fprintf(writer, "\t\t%s\t%s\n", name, strings.Join(value, ";"))
--- a/runner.go Sat Jul 09 13:35:45 2016 -0500
+++ b/runner.go Sat Jul 09 14:08:24 2016 -0500
@@ -8,62 +8,63 @@
"bitbucket.org/rw_grim/resticide/test"
-func _test_worker(worker_chan chan test.Test, result_chan chan *test.Result, wait_group *sync.WaitGroup, url *url.URL, reporter *reporter.Reporter) {
- defer wait_group.Done()
+func testWorker(workerChan chan test.Test, resultChan chan *test.Result, waitGroup *sync.WaitGroup, url *url.URL, reporter *reporter.Reporter) { - for test := range worker_chan {
+ for test := range workerChan { reporter.TestFinish(test, *res)
-func RunTests(tests []test.Test, url *url.URL, n_workers int, reporter *reporter.Reporter) int {
+// RunTests will run all of the given test with the given arguments +func RunTests(tests []test.Test, url *url.URL, nWorkers int, reporter *reporter.Reporter) int { - reporter.Start(n_tests)
- worker_chan := make(chan test.Test)
- worker_wg := new(sync.WaitGroup)
- result_chan := make(chan *test.Result)
- result_wg := new(sync.WaitGroup)
+ workerChan := make(chan test.Test) + workerWg := new(sync.WaitGroup) + resultChan := make(chan *test.Result) + resultWg := new(sync.WaitGroup) // create our result processor
- go func(result_wg *sync.WaitGroup, result_chan chan *test.Result) {
+ go func(resultWg *sync.WaitGroup, resultChan chan *test.Result) { - for result := range result_chan {
+ for result := range resultChan { - }(result_wg, result_chan)
+ }(resultWg, resultChan) - for i := 0; i < n_workers; i++ {
- go _test_worker(worker_chan, result_chan, worker_wg, url, reporter)
+ for i := 0; i < nWorkers; i++ { + go testWorker(workerChan, resultChan, workerWg, url, reporter) // add each test to the channel
for _, test := range tests {
// clean up the channel and wait for all the workers to finish
- reporter.Finish(n_tests, passed, n_tests-passed)
+ failed := nTests - passed - failed := n_tests - passed
+ reporter.Finish(nTests, passed, failed) --- a/test/request.go Sat Jul 09 13:35:45 2016 -0500
+++ b/test/request.go Sat Jul 09 14:08:24 2016 -0500
@@ -20,6 +20,7 @@
"gopkg.in/xeipuuv/gojsonschema.v0"
+// Request represents a test request @@ -29,14 +30,14 @@
FormData map[string]FormData
URLEncoded map[string]string
func (req *Request) buildBody(test *Test) (io.Reader, string) {
- content_type := "application/html"
+ contentType := "application/html" body.WriteString(req.Body)
@@ -67,7 +68,7 @@
- content_type = writer.FormDataContentType()
+ contentType = writer.FormDataContentType() } else if len(req.URLEncoded) > 0 {
@@ -76,57 +77,57 @@
body.WriteString(values.Encode())
- content_type = "application/x-www-form-urlencoded"
+ contentType = "application/x-www-form-urlencoded" } else if len(req.Binary) > 0 {
dirname := filepath.Dir(test.Filename)
filename := filepath.Join(dirname, req.Binary)
- file_type := mime.TypeByExtension(filepath.Ext(req.Binary))
+ fileType := mime.TypeByExtension(filepath.Ext(req.Binary)) - if len(file_type) > 0 {
- content_type = file_type
- content_type = "application/octet-stream"
+ contentType = "application/octet-stream" // This is gross and needs to be cleaned up too..
file, _ := os.Open(filename)
- } else if req.Json != nil {
- data, _ := json.Marshal(req.Json)
+ } else if req.JSON != nil { + data, _ := json.Marshal(req.JSON) body.WriteString(string(data))
- content_type = "application/json"
+ contentType = "application/json"
- return body, content_type
+ return body, contentType func (req *Request) buildRequest(test *Test, url *url.URL) (*http.Request, error) {
- test_url.Path = req.Path
+ testURL.Path = req.Path // build the query string
- query := test_url.Query()
+ query := testURL.Query() for qname, qvalue := range req.Query {
- test_url.RawQuery = query.Encode()
+ testURL.RawQuery = query.Encode() - body, content_type := req.buildBody(test)
+ body, contentType := req.buildBody(test) - hreq, err := http.NewRequest(req.Method, test_url.String(), body)
+ hreq, err := http.NewRequest(req.Method, testURL.String(), body) // set the Content-Type we determined when building the body
- if len(content_type) > 0 {
- hreq.Header.Add("Content-Type", content_type)
+ if len(contentType) > 0 { + hreq.Header.Add("Content-Type", contentType) for name, values := range req.Headers {
@@ -166,21 +167,21 @@
// read the body into a byte array
- body_byte, err := ioutil.ReadAll(hresp.Body)
+ bodyByte, err := ioutil.ReadAll(hresp.Body) // check if we have a file block and check it
if len(req.Response.File) > 0 {
- if sha256_digest, ok := req.Response.File["sha256"]; ok {
- sum := sha256.Sum256(body_byte)
+ if sha256Digest, ok := req.Response.File["sha256"]; ok { + sum := sha256.Sum256(bodyByte) actual := fmt.Sprintf("%x", sum)
- if actual != sha256_digest {
+ if actual != sha256Digest { "Expected file to have a SHA256 of '%s' but received '%s'",
@@ -188,14 +189,14 @@
- if md5_digest, ok := req.Response.File["md5"]; ok {
- sum := md5.Sum(body_byte)
+ if md5Digest, ok := req.Response.File["md5"]; ok { + sum := md5.Sum(bodyByte) actual := fmt.Sprintf("%x", sum)
- if actual != md5_digest {
+ if actual != md5Digest { "Expected file to have a MD5 of '%s' but received '%s'",
@@ -209,31 +210,31 @@
- _, err = file.Write(body_byte)
+ _, err = file.Write(bodyByte) - body := string(body_byte[:])
+ body := string(bodyByte[:]) // check if we have a json schema to validate
if len(req.Response.JSONSchema) != 0 {
- schema_loader := gojsonschema.NewGoLoader(req.Response.JSONSchema)
- body_loader := gojsonschema.NewStringLoader(body)
+ schemaLoader := gojsonschema.NewGoLoader(req.Response.JSONSchema) + bodyLoader := gojsonschema.NewStringLoader(body) - schema_result, err := gojsonschema.Validate(schema_loader, body_loader)
+ schemaResult, err := gojsonschema.Validate(schemaLoader, bodyLoader) - if schema_result.Valid() != true {
+ if schemaResult.Valid() != true { - for _, err := range schema_result.Errors() {
+ for _, err := range schemaResult.Errors() { errors = append(errors, err.Description())
- err_msg := strings.Join(errors, "\n")
- err := fmt.Errorf("Schema validation failed:\n%s", err_msg)
+ errMsg := strings.Join(errors, "\n") + err := fmt.Errorf("Schema validation failed:\n%s", errMsg) --- a/test/request_test.go Sat Jul 09 13:35:45 2016 -0500
+++ b/test/request_test.go Sat Jul 09 14:08:24 2016 -0500
@@ -7,13 +7,13 @@
-func buildBody(t *testing.T, r *Request, body string, content_type string) {
+func buildBody(t *testing.T, r *Request, body string, contentType string) { b, ct := r.buildBody(test)
- if ct != content_type {
- t.Errorf("got content-type '%s' expected '%s'", ct, content_type)
+ t.Errorf("got content-type '%s' expected '%s'", ct, contentType) @@ -46,7 +46,7 @@
--- a/test/response.go Sat Jul 09 13:35:45 2016 -0500
+++ b/test/response.go Sat Jul 09 14:08:24 2016 -0500
@@ -1,5 +1,6 @@
+// Response represents an expected response Headers map[string][]string
--- a/test/result.go Sat Jul 09 13:35:45 2016 -0500
+++ b/test/result.go Sat Jul 09 14:08:24 2016 -0500
@@ -4,14 +4,16 @@
+// Result is the result of running a Test - HttpResponse *http.Response
+ HTTPResponse *http.Response +// NewResult creates a new instance of Result func NewResult(test *Test) *Result {
--- a/test/test.go Sat Jul 09 13:35:45 2016 -0500
+++ b/test/test.go Sat Jul 09 14:08:24 2016 -0500
@@ -6,6 +6,7 @@
+// Test is the run time version of the test @@ -15,26 +16,27 @@
+// Run runs the given test func (test *Test) Run(url *url.URL) *Result {
for _, request := range test.Requests {
- http_request, err := request.buildRequest(test, url)
+ httpRequest, err := request.buildRequest(test, url) - resp, err := client.Do(http_request)
+ resp, err := client.Do(httpRequest) - res.HttpResponse = resp
+ res.HTTPResponse = resp res.Passed, res.Error = request.compareResponse(resp)