v1.1.3 : Travis functional testing & minor changes
This commit is contained in:
+1
-1
@@ -43,7 +43,7 @@ func (t *Tester) dropDB() bool {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println("------ Dropped CCTV Database -------")
|
||||
fmt.Println("------ Dropped Cameradar Database -------")
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (m *manager) dropDB() bool {
|
||||
dsn := m.DB.User + ":" + m.DB.Password + "@" + "tcp(" + m.DB.Host + ":" + strconv.Itoa(m.DB.Port) + ")/" + m.DB.Db_name + "?charset=utf8"
|
||||
db, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer db.Close()
|
||||
q := "DROP DATABASE cctv;"
|
||||
_, err = db.Exec(q)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println("------ Dropped CCTV Database -------")
|
||||
return true
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Launch it via goroutine
|
||||
// Start read log of service
|
||||
func getResult(test *[]Result, resultPath string) bool {
|
||||
// Load config
|
||||
resultFile, err := os.Open(resultPath)
|
||||
if err != nil {
|
||||
fmt.Printf("\nCan't open result file: %s\n", err)
|
||||
return false
|
||||
}
|
||||
dec := json.NewDecoder(resultFile)
|
||||
if err = dec.Decode(&test); err != nil {
|
||||
fmt.Printf("\nUnable to deserialize result file: %s\n", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
+3
-1
@@ -16,6 +16,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -38,7 +39,8 @@ func main() {
|
||||
fmt.Println("--- Writing results... ---")
|
||||
if !Tester.WriteResults(*(Tester.Result), Tester.Output) {
|
||||
fmt.Println("-> Write results FAILED")
|
||||
return
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("--- Writing results done ---")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type manager struct {
|
||||
Config
|
||||
|
||||
Tests []Result
|
||||
Result *TestCase
|
||||
DB mysql_db
|
||||
}
|
||||
|
||||
// Config needs refacto
|
||||
type Config struct {
|
||||
Cameradar Service `json:"Cameradar"`
|
||||
|
||||
Output string
|
||||
}
|
||||
|
||||
func (m *manager) Init() bool {
|
||||
fmt.Println("- Parsing")
|
||||
if !m.parseConfig() {
|
||||
return false
|
||||
}
|
||||
|
||||
fmt.Println("- Cleaning content")
|
||||
killService(&m.Config.Cameradar)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *manager) Run() bool {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
fmt.Println("\n- Launching all tests")
|
||||
var newTest = new(TestCase)
|
||||
newTest.expected = m.Tests
|
||||
if m.generateConfig(m.Tests, &m.DB) {
|
||||
m.dropDB()
|
||||
wg.Add(1)
|
||||
go m.invokeTestCase(newTest, &wg)
|
||||
m.Result = newTest
|
||||
}
|
||||
wg.Wait()
|
||||
fmt.Printf("All tests completed\n")
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *manager) Stop() bool {
|
||||
killService(&m.Config.Cameradar)
|
||||
return true
|
||||
}
|
||||
+1
-1
@@ -55,7 +55,7 @@ func getResult(test *[]Result, resultPath string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func isValid(e Result, r Result) bool {
|
||||
func isValid(e *Result, r Result) bool {
|
||||
if e.Username != r.Username {
|
||||
e.err = errors.New(e.Address + " had a different username than " + r.Username)
|
||||
return false
|
||||
|
||||
+15
-8
@@ -28,6 +28,13 @@ type Test struct {
|
||||
time time.Duration
|
||||
}
|
||||
|
||||
func removeResult(expected []Result, index int) []Result {
|
||||
if len(expected) > 1 {
|
||||
return append(expected[:index], expected[index+1:]...)
|
||||
}
|
||||
return []Result{}
|
||||
}
|
||||
|
||||
// Invoke the test
|
||||
// Wrap results in a TestResult object
|
||||
func (t *Tester) invokeTestCase(testCase *Test, wg *sync.WaitGroup) {
|
||||
@@ -55,14 +62,12 @@ func (t *Tester) runTestCase(test *Test) {
|
||||
for _, r := range test.result {
|
||||
r.Valid = true
|
||||
for index, e := range test.expected {
|
||||
if e.Address == r.Address && isValid(e, r) {
|
||||
if e.Address == r.Address && isValid(&e, r) {
|
||||
// _, err := os.Stat(r.Thumb)
|
||||
// if err == nil) {
|
||||
fmt.Println("The result of ", r.Address, " is valid and the thumbnails were generated by Cameradar.")
|
||||
validResults = Extend(validResults, r)
|
||||
if len(test.expected) > 1 {
|
||||
test.expected = append(test.expected[:index], test.expected[index+1:]...)
|
||||
}
|
||||
test.expected = removeResult(test.expected, index)
|
||||
break
|
||||
// } else {
|
||||
// e.err = error{"The result of " + e.Address + " seemed valid, but the thumbnails could not be generated by Cameradar : " + err.Error()}
|
||||
@@ -70,15 +75,17 @@ func (t *Tester) runTestCase(test *Test) {
|
||||
}
|
||||
}
|
||||
}
|
||||
for index, e := range test.expected {
|
||||
// This is in order to avoid checking the same values twice
|
||||
copy := test.expected
|
||||
for index, e := range copy {
|
||||
if !e.Valid {
|
||||
fmt.Println("The result of", e.Address, "successfully failed.")
|
||||
validResults = Extend(validResults, e)
|
||||
if len(test.expected) > 1 {
|
||||
test.expected = append(test.expected[:index], test.expected[index+1:]...)
|
||||
}
|
||||
test.expected = removeResult(test.expected, index)
|
||||
} else {
|
||||
e.err = errors.New("The camera with the address " + e.Address + " was not found by cameradar")
|
||||
test.expected = removeResult(test.expected, index)
|
||||
test.expected = Extend(test.expected, e)
|
||||
fmt.Println("Should have been valid but was not found : ", e.Address)
|
||||
}
|
||||
}
|
||||
|
||||
+25
-20
@@ -17,6 +17,7 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -60,9 +61,6 @@ type JUnitFailure struct {
|
||||
|
||||
// WriteResults will output the results in the standard output as well as concatenate them in an XML JUnit report
|
||||
func (t *Tester) WriteResults(result Test, output string) bool {
|
||||
fmt.Printf("Displaying results...\n")
|
||||
t.writeConsoleReport(result)
|
||||
|
||||
file, err := os.OpenFile(output, os.O_RDONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error opening XML: %s\n", err)
|
||||
@@ -72,7 +70,7 @@ func (t *Tester) WriteResults(result Test, output string) bool {
|
||||
|
||||
err = t.writeJUnitReportXML(result, file, output)
|
||||
if err != nil {
|
||||
fmt.Printf("Error writing XML: %s\n", err)
|
||||
fmt.Printf("The tests were unsuccessful: %s\n", err)
|
||||
return false
|
||||
}
|
||||
fmt.Printf("-> JUnit XML report written: %s\n", output)
|
||||
@@ -93,7 +91,7 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
|
||||
|
||||
ts := JUnitTestSuite{
|
||||
Tests: len(result.result) + len(result.expected),
|
||||
Failures: 0,
|
||||
Failures: len(result.expected),
|
||||
Time: fmt.Sprintf("%.6f", result.time.Seconds()),
|
||||
TestCases: []JUnitTestCase{},
|
||||
}
|
||||
@@ -103,7 +101,7 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
|
||||
Time: fmt.Sprintf("%.6f", result.time.Seconds()),
|
||||
Failure: nil,
|
||||
}
|
||||
testCase.Message = "The stream " + r.Address + " could be accessed and its thumbnail was properly generated"
|
||||
testCase.Message = "The stream " + r.Address + " had the expected result"
|
||||
ts.TestCases = append(ts.TestCases, testCase)
|
||||
}
|
||||
|
||||
@@ -118,6 +116,24 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
|
||||
Type: "",
|
||||
}
|
||||
}
|
||||
ts.TestCases = append(ts.TestCases, testCase)
|
||||
}
|
||||
|
||||
successCount := 0
|
||||
failureCount := 0
|
||||
for _, test := range ts.TestCases {
|
||||
if test.Failure != nil {
|
||||
failureCount++
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
fmt.Println("--- Test summary ---")
|
||||
if successCount > 0 {
|
||||
fmt.Printf("Results: %d/%d (%d%%)\n", successCount, successCount+failureCount, successCount*100/(successCount+failureCount))
|
||||
fmt.Printf("Time: %.6fs\n", result.time.Seconds())
|
||||
} else {
|
||||
fmt.Printf("No test in success\n")
|
||||
}
|
||||
|
||||
suites.TestSuites = append(suites.TestSuites, ts)
|
||||
@@ -134,19 +150,8 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
|
||||
}
|
||||
writer := io.Writer(w)
|
||||
writer.Write(bytes)
|
||||
if failureCount > 0 {
|
||||
return errors.New("Some cameras were not successfully accessed.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Tester) writeConsoleReport(result Test) bool {
|
||||
successCount := len(result.result)
|
||||
failureCount := len(result.expected)
|
||||
fmt.Println("--- Test summary ---")
|
||||
if successCount > 0 {
|
||||
fmt.Printf("Results: %d/%d (%d%%)\n", successCount, successCount+failureCount, successCount*100/(successCount+failureCount))
|
||||
fmt.Printf("Time: %.6fs\n", result.time.Seconds())
|
||||
} else {
|
||||
fmt.Printf("No test in success\n")
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user