From a52c1b921db93b1e47b9e477e34a088970cdd9b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=ABl=20Stemmer?= <stemmertech@gmail.com>
Date: Tue, 8 Oct 2019 00:38:10 +0100
Subject: [PATCH] gtr: Fix naming of Result constants

---
 pkg/gtr/builder.go |  8 ++++----
 pkg/gtr/event.go   | 36 +++++++++++++++++++++++++++++++-----
 pkg/gtr/gtr.go     | 31 +++----------------------------
 3 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/pkg/gtr/builder.go b/pkg/gtr/builder.go
index b0645b6..49e8cec 100644
--- a/pkg/gtr/builder.go
+++ b/pkg/gtr/builder.go
@@ -96,13 +96,13 @@ func (b *ReportBuilder) findTest(name string) int {
 func parseResult(r string) Result {
 	switch r {
 	case "PASS":
-		return PASS
+		return Pass
 	case "FAIL":
-		return FAIL
+		return Fail
 	case "SKIP":
-		return SKIP
+		return Skip
 	default:
 		fmt.Printf("unknown result: %q\n", r)
-		return UNKNOWN
+		return Unknown
 	}
 }
diff --git a/pkg/gtr/event.go b/pkg/gtr/event.go
index dd90cf6..ce9d3ac 100644
--- a/pkg/gtr/event.go
+++ b/pkg/gtr/event.go
@@ -2,6 +2,30 @@ package gtr
 
 import "time"
 
+type Result int
+
+const (
+	Unknown Result = iota
+	Pass
+	Fail
+	Skip
+)
+
+func (r Result) String() string {
+	switch r {
+	case Unknown:
+		return "UNKNOWN"
+	case Pass:
+		return "PASS"
+	case Fail:
+		return "FAIL"
+	case Skip:
+		return "SKIP"
+	default:
+		panic("invalid Result")
+	}
+}
+
 // TODO: provide some common types, or have a custom type (e.g.
 // identifier:type, where identifier is a unique identifier for a particular
 // parser.)
@@ -10,11 +34,13 @@ import "time"
 type Event struct {
 	Type string
 
-	Name        string
-	Result      string
-	Duration    time.Duration
-	Data        string
-	Indent      int
+	Name     string
+	Result   string
+	Duration time.Duration
+	Data     string
+	Indent   int
+
+	// Code coverage
 	CovPct      float64
 	CovPackages []string
 }
diff --git a/pkg/gtr/gtr.go b/pkg/gtr/gtr.go
index 9fe474f..ade5645 100644
--- a/pkg/gtr/gtr.go
+++ b/pkg/gtr/gtr.go
@@ -10,31 +10,6 @@ import (
 	"github.com/jstemmer/go-junit-report/v2/pkg/junit"
 )
 
-type Result int
-
-const (
-	// TODO: move these to event and don't make the all-caps
-	UNKNOWN Result = iota
-	PASS
-	FAIL
-	SKIP
-)
-
-func (r Result) String() string {
-	switch r {
-	case UNKNOWN:
-		return "UNKNOWN"
-	case PASS:
-		return "PASS"
-	case FAIL:
-		return "FAIL"
-	case SKIP:
-		return "SKIP"
-	default:
-		panic("invalid result")
-	}
-}
-
 type Report struct {
 	Packages []Package
 }
@@ -42,7 +17,7 @@ type Report struct {
 func (r *Report) HasFailures() bool {
 	for _, pkg := range r.Packages {
 		for _, t := range pkg.Tests {
-			if t.Result == FAIL {
+			if t.Result == Fail {
 				return true
 			}
 		}
@@ -103,12 +78,12 @@ func JUnit(report Report) junit.Testsuites {
 				Name:      test.Name,
 				Time:      junit.FormatDuration(test.Duration),
 			}
-			if test.Result == FAIL {
+			if test.Result == Fail {
 				tc.Failure = &junit.Result{
 					Message: "Failed",
 					Data:    strings.Join(test.Output, "\n"),
 				}
-			} else if test.Result == SKIP {
+			} else if test.Result == Skip {
 				tc.Skipped = &junit.Result{
 					Data: strings.Join(test.Output, "\n"),
 				}