From 7c3f19af98dd559c052ceaed9ceef370922d8873 Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Tue, 19 Feb 2019 11:22:41 +0100 Subject: [PATCH] Added test for JSONGetItemByType --- unmarshall_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 unmarshall_test.go diff --git a/unmarshall_test.go b/unmarshall_test.go new file mode 100644 index 0000000..6c22d1c --- /dev/null +++ b/unmarshall_test.go @@ -0,0 +1,41 @@ +package activitypub + +import ( + as "github.com/go-ap/activitystreams" + "reflect" + "testing" +) + +type testPairs map[as.ActivityVocabularyType]reflect.Type + +var objectPtrType = reflect.TypeOf(new(*Object)).Elem() +var actorPtrType = reflect.TypeOf(new(*actor)).Elem() +var applicationPtrType = reflect.TypeOf(new(*Application)).Elem() +var servicePtrType = reflect.TypeOf(new(*Service)).Elem() +var personPtrType = reflect.TypeOf(new(*Person)).Elem() +var groupPtrType = reflect.TypeOf(new(*Group)).Elem() +var organizationPtrType = reflect.TypeOf(new(*Organization)).Elem() + +var tests = testPairs{ + as.ObjectType: objectPtrType, + as.ActorType: objectPtrType, + as.ApplicationType: applicationPtrType, + as.ServiceType: servicePtrType, + as.PersonType: personPtrType, + as.GroupType: groupPtrType, + as.OrganizationType: organizationPtrType, +} + +func TestJSONGetItemByType(t *testing.T) { + for typ, test := range tests { + t.Run(string(typ), func(t *testing.T) { + v, err := JSONGetItemByType(typ) + if err != nil { + t.Error(err) + } + if reflect.TypeOf(v) != test { + t.Errorf("Invalid type returned %T, expected %s", v, test.String()) + } + }) + } +}