Files
fn-serverless/api/logs/mock.go
Tolga Ceylan 820baf36dc fn: clean api tests: removed multi log (#801)
fn-test-utils covers this, with sleep in between.
2018-02-27 21:03:03 -08:00

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
}