compose/server/proxy/streams/logs_test.go

59 lines
979 B
Go
Raw Normal View History

2020-06-06 22:46:35 +02:00
package streams
2020-05-18 23:55:17 +02:00
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/metadata"
v1 "github.com/docker/api/protos/containers/v1"
2020-05-18 23:55:17 +02:00
)
type logServer struct {
logs interface{}
2020-05-18 23:55:17 +02:00
}
func (ls *logServer) Send(response *v1.LogsResponse) error {
return nil
}
func (ls *logServer) SetHeader(metadata.MD) error {
return nil
}
func (ls *logServer) SendHeader(metadata.MD) error {
return nil
}
func (ls *logServer) SetTrailer(metadata.MD) {
}
func (ls *logServer) Context() context.Context {
return nil
}
func (ls *logServer) SendMsg(m interface{}) error {
ls.logs = m
2020-05-18 23:55:17 +02:00
return nil
}
func (ls *logServer) RecvMsg(m interface{}) error {
return nil
}
func TestLogStreamWriter(t *testing.T) {
2020-05-18 23:55:17 +02:00
ls := &logServer{}
sw := newStreamWriter(ls)
in := []byte{104, 101, 108, 108, 111}
expected := &v1.LogsResponse{
Value: in,
}
2020-05-18 23:55:17 +02:00
l, err := sw.Write(in)
assert.Nil(t, err)
assert.Equal(t, len(in), l)
assert.Equal(t, expected, ls.logs)
2020-05-18 23:55:17 +02:00
}