Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1741)

Unified Diff: go/src/infra/appengine/test-results/model/common.go

Issue 2234353002: test-results: package model: Add full_result.go and tests (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Improve coverage Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: go/src/infra/appengine/test-results/model/common.go
diff --git a/go/src/infra/appengine/test-results/model/common.go b/go/src/infra/appengine/test-results/model/common.go
index 3e2040bfc2d19ede29216a191297ebe333cc8d24..e8635da9d8b1b1f801ebe56e8fad0d030df580a7 100644
--- a/go/src/infra/appengine/test-results/model/common.go
+++ b/go/src/infra/appengine/test-results/model/common.go
@@ -2,39 +2,37 @@ package model
import (
"bytes"
- "math"
"strconv"
)
-func round(f float64) int {
- if math.Abs(f) < 0.5 {
- return 0
- }
- return int(f + math.Copysign(0.5, f))
-}
-
-// TestNode is a node in a Tests tree.
-type TestNode interface {
- // Children returns a map of a TestNode's children.
- Children() map[string]TestNode
-
- testnode()
+// Node is a node in a Tests tree.
+//
+// In reality, it as almost as weak as empty interface,
+// but the unexported method allow the package to achieve
+// type safety internally.
+type Node interface {
+ node()
}
-// number is an integer that supports JSON unmarshaling from a string
+// Number is an integer that supports JSON unmarshaling from a string
// and marshaling back to a string.
-type number int
+type Number int
-func (n *number) UnmarshalJSON(data []byte) error {
+// UnmarshalJSON unmarshals data into n.
+// data is expected to be a JSON string. If the string
+// fails to parse to an integer, UnmarshalJSON returns
+// an error.
+func (n *Number) UnmarshalJSON(data []byte) error {
data = bytes.Trim(data, `"`)
num, err := strconv.Atoi(string(data))
if err != nil {
return err
}
- *n = number(num)
+ *n = Number(num)
return nil
}
-func (n *number) MarshalJSON() ([]byte, error) {
+// MarshalJSON marshals n into JSON string.
+func (n *Number) MarshalJSON() ([]byte, error) {
return []byte(strconv.Itoa(int(*n))), nil
}

Powered by Google App Engine
This is Rietveld 408576698