mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-13 14:05:42 +08:00
39 lines
894 B
Go
39 lines
894 B
Go
package mock
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/micromdm/mdm"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
type Command struct {
|
|
NewCommandInvoked bool
|
|
NewCommandFunc NewCommandFunc
|
|
}
|
|
|
|
type NewCommandFunc func(context.Context, *mdm.CommandRequest) (*mdm.Payload, error)
|
|
|
|
func (svc *Command) NewCommand(ctx context.Context, request *mdm.CommandRequest) (*mdm.Payload, error) {
|
|
svc.NewCommandInvoked = true
|
|
return svc.NewCommandFunc(ctx, request)
|
|
}
|
|
|
|
var MockPayload = &mdm.Payload{
|
|
CommandUUID: "1234",
|
|
}
|
|
|
|
func FailNewCommand(context.Context, *mdm.CommandRequest) (*mdm.Payload, error) {
|
|
return nil, errors.New("command creation failed")
|
|
}
|
|
|
|
func ReturnMockPayload(context.Context, *mdm.CommandRequest) (*mdm.Payload, error) {
|
|
return MockPayload, nil
|
|
}
|
|
|
|
func ReturnPayload(p *mdm.Payload) NewCommandFunc {
|
|
return func(context.Context, *mdm.CommandRequest) (*mdm.Payload, error) {
|
|
return p, nil
|
|
}
|
|
}
|