Implement ToReader for ExchangeData (#161)
This commit is contained in:
parent
33e8e978ba
commit
13ca33fae0
@ -1,6 +1,9 @@
|
|||||||
package connector
|
package connector
|
||||||
|
|
||||||
import "io"
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
// A DataCollection represents a collection of data of the
|
// A DataCollection represents a collection of data of the
|
||||||
// same type (e.g. mail)
|
// same type (e.g. mail)
|
||||||
@ -13,7 +16,8 @@ type DataCollection interface {
|
|||||||
// DataStream represents a single item within a DataCollection
|
// DataStream represents a single item within a DataCollection
|
||||||
// that can be consumed as a stream (it embeds io.Reader)
|
// that can be consumed as a stream (it embeds io.Reader)
|
||||||
type DataStream interface {
|
type DataStream interface {
|
||||||
io.Reader
|
// Returns an io.Reader for the DataStream
|
||||||
|
ToReader() io.Reader
|
||||||
// Provides a unique identifier for this data
|
// Provides a unique identifier for this data
|
||||||
UUID() string
|
UUID() string
|
||||||
}
|
}
|
||||||
@ -72,7 +76,6 @@ func (ed *ExchangeData) UUID() string {
|
|||||||
return ed.id
|
return ed.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ed *ExchangeData) Read(bytes []byte) (int, error) {
|
func (ed *ExchangeData) ToReader() io.Reader {
|
||||||
// TODO: Copy ed.message into []bytes. Will need to take care of partial reads
|
return bytes.NewReader(ed.message)
|
||||||
return 0, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/internal/connector/exchange_data_collection_test.go
Normal file
27
src/internal/connector/exchange_data_collection_test.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package connector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ExchangeDataCollectionSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExchangeDataCollectionSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(ExchangeDataCollectionSuite))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *ExchangeDataCollectionSuite) TestExchangeDataReader() {
|
||||||
|
m := []byte("test message")
|
||||||
|
ed := &ExchangeData{message: m}
|
||||||
|
|
||||||
|
// Read the message using the `ExchangeData` reader and validate it matches what we set
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
buf.ReadFrom(ed.ToReader())
|
||||||
|
assert.Equal(suite.T(), buf.Bytes(), m)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user