mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
33 lines
614 B
Go
33 lines
614 B
Go
package logs
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"io/ioutil"
|
|
|
|
"github.com/fnproject/fn/api/models"
|
|
)
|
|
|
|
type mock struct {
|
|
Logs map[string][]byte
|
|
}
|
|
|
|
func NewMock() models.LogStore {
|
|
return &mock{make(map[string][]byte)}
|
|
}
|
|
|
|
func (m *mock) InsertLog(ctx context.Context, appName, callID string, callLog io.Reader) error {
|
|
bytes, err := ioutil.ReadAll(callLog)
|
|
m.Logs[callID] = bytes
|
|
return err
|
|
}
|
|
|
|
func (m *mock) GetLog(ctx context.Context, appName, callID string) (io.Reader, error) {
|
|
logEntry, ok := m.Logs[callID]
|
|
if !ok {
|
|
return nil, models.ErrCallLogNotFound
|
|
}
|
|
return bytes.NewReader(logEntry), nil
|
|
}
|