Skip to content

Commit

Permalink
Merge pull request #5 from shrutir25/error_reports
Browse files Browse the repository at this point in the history
Error reports
  • Loading branch information
shrutir25 authored Aug 8, 2017
2 parents 86dcfc3 + f845765 commit 5afd113
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions test/acs-engine-test/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ type Manager struct {
Duration string `json:"duration"`
// Failure map: key=error, value=locations
Failures map[string]*ErrorStat `json:"failures"`
LogErrors []logError `json:"Errors"`
LogErrors logErrors `json:"-"`
}

type logErrors struct {
LogErrors []logError `json:"Errors"`
}

type logError struct {
Expand Down Expand Up @@ -74,19 +78,18 @@ func New(jobName string, buildNum int, nDeploys int, fileName string) *Manager {
return h
}

func makeErrorList(fileName string) []logError {
func makeErrorList(fileName string) logErrors {
dummy := logErrors{}

if fileName != "" {
file, e := ioutil.ReadFile(fileName)
if e != nil {
fmt.Printf("File error: %v\n", e)
os.Exit(1)
}

var dummyMgr Manager
json.Unmarshal(file, &dummyMgr)
return dummyMgr.LogErrors
json.Unmarshal(file, &dummy)
}
return nil
return dummy
}

// Copy TBD needs definition [ToDo]
Expand All @@ -106,7 +109,7 @@ func (h *Manager) Copy() *Manager {

// Process TBD needs definition
func (h *Manager) Process(txt, testName, location string) *ErrorInfo {
for _, logErr := range h.LogErrors {
for _, logErr := range h.LogErrors.LogErrors {
if match, _ := regexp.MatchString(logErr.Regex, txt); match {
h.addFailure(logErr.Name, map[string]int{location: 1})
return NewErrorInfo(testName, logErr.Name, logErr.Class, location)
Expand Down Expand Up @@ -142,23 +145,10 @@ func (h *Manager) addFailure(key string, locations map[string]int) {
h.Errors += cnt
}

//MarshalJSON gives back customized fields
func (h *Manager) MarshalJSON() ([]byte, error) {
return json.MarshalIndent(struct {
JobName string `json:"job"`
BuildNum int `json:"build"`
Deployments int `json:"deployments"`
Errors int `json:"errors"`
StartTime time.Time `json:"startTime"`
Duration string `json:"duration"`
Failures map[string]*ErrorStat `json:"failures"`
}{h.JobName, h.BuildNum, h.Deployments, h.Errors, h.StartTime, h.Duration, h.Failures}, "", " ")
}

// CreateTestReport TBD needs definition
func (h *Manager) CreateTestReport(filepath string) error {
h.Duration = time.Now().UTC().Sub(h.StartTime).String()
data, err := h.MarshalJSON()
data, err := json.MarshalIndent(h, "", " ")
if err != nil {
return err
}
Expand Down

0 comments on commit 5afd113

Please sign in to comment.