forked from moby/swarmkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.go
94 lines (78 loc) · 1.96 KB
/
exec.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package integration
import (
"sync"
"github.com/docker/swarmkit/agent/exec"
"github.com/docker/swarmkit/api"
"golang.org/x/net/context"
)
// TestExecutor is executor for integration tests
type TestExecutor struct {
}
// Describe just returns empty NodeDescription.
func (e *TestExecutor) Describe(ctx context.Context) (*api.NodeDescription, error) {
return &api.NodeDescription{}, nil
}
// Configure does nothing.
func (e *TestExecutor) Configure(ctx context.Context, node *api.Node) error {
return nil
}
// SetNetworkBootstrapKeys does nothing.
func (e *TestExecutor) SetNetworkBootstrapKeys([]*api.EncryptionKey) error {
return nil
}
// Controller returns TestController.
func (e *TestExecutor) Controller(t *api.Task) (exec.Controller, error) {
return &TestController{
ch: make(chan struct{}),
}, nil
}
// TestController is dummy channel based controller for tests.
type TestController struct {
ch chan struct{}
closeOnce sync.Once
}
// Update does nothing.
func (t *TestController) Update(ctx context.Context, task *api.Task) error {
return nil
}
// Prepare does nothing.
func (t *TestController) Prepare(ctx context.Context) error {
return nil
}
// Start does nothing.
func (t *TestController) Start(ctx context.Context) error {
return nil
}
// Wait waits on internal channel.
func (t *TestController) Wait(ctx context.Context) error {
select {
case <-t.ch:
case <-ctx.Done():
}
return nil
}
// Shutdown closes internal channel
func (t *TestController) Shutdown(ctx context.Context) error {
t.closeOnce.Do(func() {
close(t.ch)
})
return nil
}
// Terminate closes internal channel if it wasn't closed before.
func (t *TestController) Terminate(ctx context.Context) error {
t.closeOnce.Do(func() {
close(t.ch)
})
return nil
}
// Remove does nothing.
func (t *TestController) Remove(ctx context.Context) error {
return nil
}
// Close does nothing.
func (t *TestController) Close() error {
t.closeOnce.Do(func() {
close(t.ch)
})
return nil
}