grim/resticide

The rest of the linting
develop
2016-07-09, Gary Kramlich
3cf5b06c8a56
Parents cae66556bb62
Children 1c5d999e33ac
The rest of the linting
--- a/loader/json.go Sat Jul 09 14:18:50 2016 -0500
+++ b/loader/json.go Sat Jul 09 14:26:54 2016 -0500
@@ -24,15 +24,15 @@
}
func loadSchema() (*gojsonschema.Schema, error) {
- schema_bytes, err := Asset("schema.json")
+ schemaBytes, err := Asset("schema.json")
if err != nil {
return nil, err
}
- schema_string := string(schema_bytes[:])
- schema_loader := gojsonschema.NewStringLoader(schema_string)
+ schemaString := string(schemaBytes[:])
+ schemaLoader := gojsonschema.NewStringLoader(schemaString)
- return gojsonschema.NewSchema(schema_loader)
+ return gojsonschema.NewSchema(schemaLoader)
}
func parseHeaders(h map[string]interface{}) map[string][]string {
@@ -74,7 +74,7 @@
}
if json, found := fields["json"]; found {
- formDataValue.Json = json.(map[string]interface{})
+ formDataValue.JSON = json.(map[string]interface{})
}
if filename, found := fields["filename"]; found {
@@ -87,7 +87,7 @@
return formData
}
-func parseUrlEncoded(encoded map[string]interface{}) map[string]string {
+func parseURLEncoded(encoded map[string]interface{}) map[string]string {
urlEncoded := map[string]string{}
for name, ival := range encoded {
@@ -158,7 +158,7 @@
}
if urlEncoded, found := req["x-www-form-urlencoded"]; found {
- tr.URLEncoded = parseUrlEncoded(urlEncoded.(map[string]interface{}))
+ tr.URLEncoded = parseURLEncoded(urlEncoded.(map[string]interface{}))
}
if json, found := req["json"]; found {
@@ -171,7 +171,7 @@
return tr
}
-func JSONLoader(data []byte) (string, []test.Request, error) {
+func jsonLoader(data []byte) (string, []test.Request, error) {
var t map[string]interface{}
// unmarshal the data
--- a/loader/loader.go Sat Jul 09 14:18:50 2016 -0500
+++ b/loader/loader.go Sat Jul 09 14:26:54 2016 -0500
@@ -9,12 +9,15 @@
"bitbucket.org/rw_grim/resticide/test"
)
+// Loader is a function that can load a file
type Loader func([]byte) (string, []test.Request, error)
var loaders = map[string]Loader{
- ".json": JSONLoader,
+ ".json": jsonLoader,
}
+// LoadTests will walk the file system attempting to load tests from the files
+// it can read.
func LoadTests(path string, reporter *reporter.Reporter) ([]test.Test, error) {
tests := []test.Test{}
--- a/reporter/console_reporter.go Sat Jul 09 14:18:50 2016 -0500
+++ b/reporter/console_reporter.go Sat Jul 09 14:26:54 2016 -0500
@@ -10,22 +10,27 @@
"bitbucket.org/rw_grim/resticide/test"
)
+// ConsoleReporter is a report that outputs to the console
type ConsoleReporter struct {
verbose bool
lock *sync.Mutex
}
+// Init is called to initialize the reporter
func (reporter *ConsoleReporter) Init(verbose bool) {
reporter.verbose = verbose
reporter.lock = new(sync.Mutex)
}
+// Start is called when testing is started
func (reporter *ConsoleReporter) Start(tests int) {
}
+// TestStart is called when a test starts running
func (reporter *ConsoleReporter) TestStart(test test.Test) {
}
+// TestFinish is called when a test finishes running
func (reporter *ConsoleReporter) TestFinish(test test.Test, res test.Result) {
// This sucks, but yes we need to lock stdout so our results make sense..
reporter.lock.Lock()
@@ -56,14 +61,17 @@
}
}
+// Finish is called when testing has completed.
func (reporter *ConsoleReporter) Finish(tests int, passed int, failed int) {
fmt.Printf("\n%s\n", strings.Repeat("-", 40))
fmt.Printf("%d tests, %d passed, %d failed\n", tests, passed, failed)
}
-func (report *ConsoleReporter) LoadTestsFailed(err error) {
+// LoadTestsFailed is called when multiple tests fail to load
+func (reporter *ConsoleReporter) LoadTestsFailed(err error) {
}
-func (report *ConsoleReporter) LoadTestFailed(path string, err error) {
+// LoadTestFailed is called when a test fails to load
+func (reporter *ConsoleReporter) LoadTestFailed(path string, err error) {
fmt.Printf("failed to load test '%s': %s\n", path, err.Error())
}
--- a/reporter/reporter.go Sat Jul 09 14:18:50 2016 -0500
+++ b/reporter/reporter.go Sat Jul 09 14:26:54 2016 -0500
@@ -4,6 +4,8 @@
"bitbucket.org/rw_grim/resticide/test"
)
+// ReportHandler is an interface that can be used to handle the reporting of
+// tests.
type ReportHandler interface {
Init(verbose bool)
Start(tests int)
@@ -14,13 +16,15 @@
LoadTestFailed(path string, err error)
}
+// Reporter is the highlevel reporting object
type Reporter struct {
handlers []ReportHandler
verbose bool
}
-type HandlerFunc func(handler ReportHandler)
+type handlerFunc func(handler ReportHandler)
+// NewReporter creates a new reporter
func NewReporter(verbose bool) *Reporter {
reporter := new(Reporter)
@@ -29,47 +33,57 @@
return reporter
}
-func (reporter *Reporter) report(function HandlerFunc) {
+func (reporter *Reporter) report(function handlerFunc) {
for _, handler := range reporter.handlers {
function(handler)
}
}
+// AddHandler ads the given ReportHandler to the reporter
func (reporter *Reporter) AddHandler(handler ReportHandler) {
handler.Init(reporter.verbose)
reporter.handlers = append(reporter.handlers, handler)
}
+// Start is called after program initialization has completed, but before any
+// tests are run
func (reporter *Reporter) Start(tests int) {
reporter.report(func(handler ReportHandler) {
handler.Start(tests)
})
}
+// Finish is called when all tests have completed and the program is about to
+// exit
func (reporter *Reporter) Finish(tests int, passed int, failed int) {
reporter.report(func(handler ReportHandler) {
handler.Finish(tests, passed, failed)
})
}
+// TestStart is called just before a test starts running
func (reporter *Reporter) TestStart(test test.Test) {
reporter.report(func(handler ReportHandler) {
handler.TestStart(test)
})
}
+// TestFinish is called when a test has finished running
func (reporter *Reporter) TestFinish(test test.Test, res test.Result) {
reporter.report(func(handler ReportHandler) {
handler.TestFinish(test, res)
})
}
+// LoadTestsFailed should be called when there was a problem loading multiple
+// tests
func (reporter *Reporter) LoadTestsFailed(err error) {
reporter.report(func(handler ReportHandler) {
handler.LoadTestsFailed(err)
})
}
+// LoadTestFailed should be called when there was a problem loading a test
func (reporter *Reporter) LoadTestFailed(path string, err error) {
reporter.report(func(handler ReportHandler) {
handler.LoadTestFailed(path, err)
--- a/test/form_data.go Sat Jul 09 14:18:50 2016 -0500
+++ b/test/form_data.go Sat Jul 09 14:26:54 2016 -0500
@@ -1,7 +1,8 @@
package test
+// FormData represents a form data value.
type FormData struct {
Value string
- Json map[string]interface{}
+ JSON map[string]interface{}
Filename string
}
--- a/test/request.go Sat Jul 09 14:18:50 2016 -0500
+++ b/test/request.go Sat Jul 09 14:26:54 2016 -0500
@@ -49,8 +49,8 @@
for name, data := range req.FormData {
if len(data.Value) > 0 {
writer.WriteField(name, data.Value)
- } else if len(data.Json) > 0 {
- s, err := json.Marshal(data.Json)
+ } else if len(data.JSON) > 0 {
+ s, err := json.Marshal(data.JSON)
if err != nil {
// do something better here
continue