forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmockcommand.go
More file actions
45 lines (38 loc) · 1 KB
/
mockcommand.go
File metadata and controls
45 lines (38 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* Package testdata holds ancillary data needed by
the tests. The go tool ignores this directory.
https://golang.org/pkg/cmd/go/internal/test/ */
package testdata
import (
"context"
)
// MockCommand represents a mock of os/exec.Cmd for testing
type MockCommand struct {
done chan error
ctx context.Context
}
// NewMockCommand returns a MockCommand that satisfies
// the command interface
func NewMockCommand(ctx context.Context) MockCommand {
done := make(chan error)
return MockCommand{done, ctx}
}
// Start represents a successful cmd.Start() without
// errors
func (c MockCommand) Start() error {
return nil
}
// Wait represents a cancelable call to cmd.Wait()
func (c MockCommand) Wait() error {
select {
case <-c.done:
return nil
case <-c.ctx.Done():
return c.ctx.Err()
}
}
// ForceExit tells goroutine blocking on Wait() to exit
func (c MockCommand) ForceExit() {
c.done <- nil
}