forked from fnproject/fn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock.go
52 lines (42 loc) · 1.05 KB
/
mock.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
package logs
import (
"bytes"
"context"
"io"
"github.com/fnproject/fn/api/models"
"github.com/pkg/errors"
)
type mock struct {
Logs map[string]*models.CallLog
ds models.Datastore
}
func NewMock() models.LogStore {
return NewMockInit(nil)
}
func NewMockInit(logs map[string]*models.CallLog) models.LogStore {
if logs == nil {
logs = map[string]*models.CallLog{}
}
fnl := &mock{logs, nil}
return fnl
}
func (m *mock) SetDatastore(ctx context.Context, ds models.Datastore) {
m.ds = ds
}
func (m *mock) InsertLog(ctx context.Context, appName, callID string, callLog io.Reader) error {
var b bytes.Buffer
io.Copy(&b, callLog)
m.Logs[callID] = &models.CallLog{CallID: callID, Log: b.String()}
return nil
}
func (m *mock) GetLog(ctx context.Context, appName, callID string) (*models.CallLog, error) {
logEntry := m.Logs[callID]
if logEntry == nil {
return nil, errors.New("Call log not found")
}
return m.Logs[callID], nil
}
func (m *mock) DeleteLog(ctx context.Context, appName, callID string) error {
delete(m.Logs, callID)
return nil
}