mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
48 lines
1007 B
Go
48 lines
1007 B
Go
package logs
|
|
|
|
import (
|
|
"context"
|
|
"gitlab-odx.oracle.com/odx/functions/api/models"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type mock struct {
|
|
Logs map[string]*models.FnCallLog
|
|
ds models.Datastore
|
|
}
|
|
|
|
func NewMock() models.FnLog {
|
|
return NewMockInit(nil)
|
|
}
|
|
|
|
func NewMockInit(logs map[string]*models.FnCallLog) models.FnLog {
|
|
if logs == nil {
|
|
logs = map[string]*models.FnCallLog{}
|
|
}
|
|
fnl := NewValidator(&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, callID string, callLog string) error {
|
|
m.Logs[callID] = &models.FnCallLog{CallID: callID, Log:callLog}
|
|
return nil
|
|
}
|
|
|
|
func (m *mock) GetLog(ctx context.Context, callID string) (*models.FnCallLog, 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, callID string) error {
|
|
delete(m.Logs, callID)
|
|
return nil
|
|
}
|