Index: go/src/infra/appengine/test-results/model/common_test.go |
diff --git a/go/src/infra/appengine/test-results/model/common_test.go b/go/src/infra/appengine/test-results/model/common_test.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6f15cc437a127610dcd60e48f9ec54daf503168c |
--- /dev/null |
+++ b/go/src/infra/appengine/test-results/model/common_test.go |
@@ -0,0 +1,46 @@ |
+package model |
+ |
+import ( |
+ "encoding/json" |
+ "testing" |
+ |
+ . "github.com/smartystreets/goconvey/convey" |
+) |
+ |
+func TestCommon(t *testing.T) { |
+ t.Parallel() |
+ |
+ Convey("Number", t, func() { |
+ Convey("UnmarshalJSON", func() { |
+ Convey("fails on non integers", func() { |
+ Convey("string", func() { |
+ input := []byte("foo") |
+ var num Number |
+ So(json.Unmarshal(input, &num), ShouldNotBeNil) |
+ }) |
+ |
+ Convey("float", func() { |
+ input := []byte("2.0") |
+ var num Number |
+ So(json.Unmarshal(input, &num), ShouldNotBeNil) |
+ }) |
+ }) |
+ |
+ Convey("succeeds for integer", func() { |
+ input := []byte("-400") |
+ var num Number |
+ So(json.Unmarshal(input, &num), ShouldBeNil) |
+ So(num, ShouldEqual, -400) |
+ }) |
+ }) |
+ |
+ Convey("MarshalJSON", func() { |
+ Convey("basic", func() { |
+ num := Number(-400) |
+ b, err := json.Marshal(&num) |
+ So(err, ShouldBeNil) |
+ So(string(b), ShouldEqual, "-400") |
+ }) |
+ }) |
+ }) |
+} |