Index: service/datastore/index_test.go |
diff --git a/service/datastore/index_test.go b/service/datastore/index_test.go |
index 6ec9d0953a369a19083f4b131fdf2969cc7624de..44bd359b8de26f3e621bc1dc8390245ca17e4e03 100644 |
--- a/service/datastore/index_test.go |
+++ b/service/datastore/index_test.go |
@@ -7,18 +7,21 @@ |
package datastore |
import ( |
+ "fmt" |
"strings" |
"testing" |
. "github.com/smartystreets/goconvey/convey" |
+ "gopkg.in/yaml.v2" |
) |
var indexDefinitionTests = []struct { |
- id *IndexDefinition |
- builtin bool |
- compound bool |
- str string |
- yaml []string |
+ id *IndexDefinition |
+ builtin bool |
+ compound bool |
+ str string |
+ yaml []string |
+ serialized []string // without the leading hyphen, for instance |
iannucci
2016/01/13 19:12:20
I don't understand this comment
nishanths (utexas)
2016/01/14 21:12:56
My bad. Meant: not inside an array (YAML arrays ha
|
}{ |
{ |
id: &IndexDefinition{Kind: "kind"}, |
@@ -63,6 +66,14 @@ var indexDefinitionTests = []struct { |
" - name: other", |
" direction: desc", |
}, |
+ serialized: []string{ |
+ " kind: Kind", |
dnj
2016/01/13 16:16:40
You should be able to avoid repeating "yaml" by Ma
nishanths (utexas)
2016/01/14 21:12:56
Thanks! Much cleaner. :)
|
+ " ancestor: yes", |
+ " properties:", |
+ " - name: prop", |
+ " - name: other", |
+ " direction: desc", |
+ }, |
}, |
} |
@@ -80,4 +91,21 @@ func TestIndexDefinition(t *testing.T) { |
}) |
} |
}) |
+ |
+ Convey("Test MarshalYAML/UnmarshalYAML", t, func() { |
+ for _, tc := range indexDefinitionTests { |
+ Convey(fmt.Sprintf("serializable index definition `%s` is marshaled and unmarshaled correctly", tc.str), func() { |
+ if tc.serialized != nil { |
+ // marshal |
+ _, err := yaml.Marshal(tc.id) |
+ So(err, ShouldBeNil) |
+ |
+ // unmarshal |
+ var id IndexDefinition |
+ yaml.Unmarshal([]byte(strings.Join(tc.serialized, "\n")), &id) |
+ So(&id, ShouldResemble, tc.id) |
+ } |
+ }) |
+ } |
+ }) |
} |