[fxtesting] Add common testing library
This is useful for avoiding large amounts of `if err != nil`
boilerplate in tests, since we often don't need to return the
error and can instead treat it as fatal during testing.
IN-699 #comment
Change-Id: Iffbd2280c7ae232442b8602fde862455502bb996
diff --git a/fxtesting/testing.go b/fxtesting/testing.go
new file mode 100644
index 0000000..7cc3aae
--- /dev/null
+++ b/fxtesting/testing.go
@@ -0,0 +1,22 @@
+package fxtesting
+
+import (
+ "testing"
+)
+
+// T wraps a testing.T to add Fuchsia-specific test functionality.
+// Example Usage:
+// t.Run("a_test", func(t *testing.T) {
+// fxt := T{t}
+// fxt.AssertNil(MaybeError())
+// })
+type T struct {
+ *testing.T
+}
+
+// AssertNil raises a fatal error if the error is not nil.
+func (t *T) AssertNil(err error) {
+ if err != nil {
+ t.Fatal(err)
+ }
+}