-
Notifications
You must be signed in to change notification settings - Fork 403
/
mocker.go
88 lines (68 loc) · 1.63 KB
/
mocker.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
// Package mock provides a fake Driver implementation that is only used for testing.
package mock
import (
"context"
"fmt"
"time"
"github.com/fnproject/fn/api/agent/drivers"
)
func New() drivers.Driver {
return &Mocker{}
}
type Mocker struct {
count int
}
func (m *Mocker) CreateCookie(context.Context, drivers.ContainerTask) (drivers.Cookie, error) {
return &cookie{m}, nil
}
func (m *Mocker) PrepareCookie(context.Context, drivers.Cookie) error {
return nil
}
func (m *Mocker) Close() error {
return nil
}
var _ drivers.Driver = &Mocker{}
type cookie struct {
m *Mocker
}
func (c *cookie) Freeze(context.Context) error {
return nil
}
func (c *cookie) Unfreeze(context.Context) error {
return nil
}
func (c *cookie) ValidateImage(context.Context) (bool, error) {
return false, nil
}
func (c *cookie) PullImage(context.Context) error {
return nil
}
func (c *cookie) CreateContainer(context.Context) error {
return nil
}
func (c *cookie) Close(context.Context) error {
return nil
}
func (c *cookie) ContainerOptions() interface{} {
return nil
}
func (c *cookie) Run(ctx context.Context) (drivers.WaitResult, error) {
c.m.count++
if c.m.count%100 == 0 {
return nil, fmt.Errorf("Mocker error! Bad.")
}
return &runResult{
err: nil,
status: "success",
start: time.Now(),
}, nil
}
var _ drivers.Cookie = &cookie{}
type runResult struct {
err error
status string
start time.Time
}
func (r *runResult) Wait(context.Context) drivers.RunResult { return r }
func (r *runResult) Status() string { return r.status }
func (r *runResult) Error() error { return r.err }