grim/resticide

Add golint as part of our build
develop
2016-07-09, Gary Kramlich
cae66556bb62
Add golint as part of our build
package main
import (
"net/url"
"sync"
"bitbucket.org/rw_grim/resticide/reporter"
"bitbucket.org/rw_grim/resticide/test"
)
func testWorker(workerChan chan test.Test, resultChan chan *test.Result, waitGroup *sync.WaitGroup, url *url.URL, reporter *reporter.Reporter) {
defer waitGroup.Done()
for test := range workerChan {
reporter.TestStart(test)
res := test.Run(url)
reporter.TestFinish(test, *res)
resultChan <- res
}
}
// 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 {
nTests := len(tests)
passed := 0
reporter.Start(nTests)
workerChan := make(chan test.Test)
workerWg := new(sync.WaitGroup)
resultChan := make(chan *test.Result)
resultWg := new(sync.WaitGroup)
// create our result processor
resultWg.Add(1)
go func(resultWg *sync.WaitGroup, resultChan chan *test.Result) {
defer resultWg.Done()
for result := range resultChan {
if result.Passed {
passed++
}
}
}(resultWg, resultChan)
// create our workers
for i := 0; i < nWorkers; i++ {
workerWg.Add(1)
go testWorker(workerChan, resultChan, workerWg, url, reporter)
}
// add each test to the channel
for _, test := range tests {
workerChan <- test
}
// clean up the channel and wait for all the workers to finish
close(workerChan)
workerWg.Wait()
close(resultChan)
resultWg.Wait()
failed := nTests - passed
reporter.Finish(nTests, passed, failed)
return failed
}