mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
49 lines
848 B
Go
49 lines
848 B
Go
package mock
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"gitlab-odx.oracle.com/odx/functions/api/runner/drivers"
|
|
)
|
|
|
|
func New() drivers.Driver {
|
|
return &Mocker{}
|
|
}
|
|
|
|
type Mocker struct {
|
|
count int
|
|
}
|
|
|
|
func (m *Mocker) Prepare(context.Context, drivers.ContainerTask) (drivers.Cookie, error) {
|
|
return &cookie{m}, nil
|
|
}
|
|
|
|
type cookie struct {
|
|
m *Mocker
|
|
}
|
|
|
|
func (c *cookie) Close(context.Context) error { return nil }
|
|
|
|
func (c *cookie) Run(ctx context.Context) (drivers.RunResult, error) {
|
|
c.m.count++
|
|
if c.m.count%100 == 0 {
|
|
return nil, fmt.Errorf("Mocker error! Bad.")
|
|
}
|
|
return &runResult{
|
|
error: nil,
|
|
status: "success",
|
|
start: time.Now(),
|
|
}, nil
|
|
}
|
|
|
|
type runResult struct {
|
|
error
|
|
status string
|
|
start time.Time
|
|
}
|
|
|
|
func (r *runResult) Status() string { return r.status }
|
|
func (r *runResult) StartTime() time.Time { return r.start }
|