organize essential APIs into platform, workflow and pkg folders (#337)

Add more logic to the way code is organized.

	/pkg -- library code not directly connected to micromdm
	/mdm -- packages meant for the services devices interract with. The MDM protocol.
	/dep -- DEP API and related packages.
	/platform -- Core APIs the server provides. Commands API, Devices API, queue, pubsub etc.
	/workflow -- Packages/API that build on top of platform. Today that's the webhook package.
		     Depending on what ends up here, the workflow folder might become its own repository.
This commit is contained in:
Victor Vrantchan
2017-11-23 22:07:57 -05:00
committed by GitHub
parent bc34ace413
commit 91c236c8c3
112 changed files with 165 additions and 233 deletions

View File

@@ -0,0 +1,83 @@
package command_test
import (
"encoding/json"
"io/ioutil"
"reflect"
"testing"
"github.com/groob/plist"
"github.com/micromdm/mdm"
"github.com/micromdm/micromdm/platform/command"
)
var marshalTests = []string{
"DeviceInformation",
"DeviceInformation_empty_queries",
"InstallProfile",
"Settings_hostname_devicename",
}
func TestMarshalEvent(t *testing.T) {
for _, tt := range marshalTests {
name := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
v := command.NewEvent(mustLoadPayload(t, name), name)
var other command.Event
if buf, err := command.MarshalEvent(v); err != nil {
t.Fatal(err)
} else if err := command.UnmarshalEvent(buf, &other); err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual(v, &other) {
t.Logf("\nwant: %#v\n, \nhave: %#v\n", v.Payload.Command, other.Payload.Command)
t.Fatalf("\nwant: %#v\n \nhave: %#v\n", v, other)
}
})
}
}
func BenchmarkMarshalProto(b *testing.B) {
for _, tt := range marshalTests {
v := command.NewEvent(mustLoadPayload(&testing.T{}, tt), tt)
for n := 0; n < b.N; n++ {
var other command.Event
if buf, err := command.MarshalEvent(v); err != nil {
b.Fatal(err)
} else if err := command.UnmarshalEvent(buf, &other); err != nil {
b.Fatal(err)
} else if !reflect.DeepEqual(v, &other) {
b.Fatalf("\nwant: %#v\n \nhave: %#v\n", v, other)
}
}
}
}
func BenchmarkMarshalJSON(b *testing.B) {
for _, tt := range marshalTests {
v := command.NewEvent(mustLoadPayload(&testing.T{}, tt), tt)
for n := 0; n < b.N; n++ {
var other command.Event
if buf, err := json.Marshal(&v); err != nil {
b.Fatal(err)
} else if err := json.Unmarshal(buf, &other); err != nil {
b.Fatal(err)
} else if !reflect.DeepEqual(v, &other) {
b.Fatalf("\nwant: %#v\n \nhave: %#v\n", v, other)
}
}
}
}
func mustLoadPayload(t *testing.T, name string) mdm.Payload {
var payload mdm.Payload
data, err := ioutil.ReadFile("testdata/" + name + ".plist")
if err != nil {
t.Fatalf("failed to open test file %q.plist, err: %s", name, err)
}
if err := plist.Unmarshal(data, &payload); err != nil {
t.Fatalf("failed to unmarshal plist %q, err: %s", name, err)
}
return payload
}