github.com/mantzas/incata@v0.3.0/mocks/memory_reader.go (about)

     1  package mocks
     2  
     3  import (
     4  	"github.com/mantzas/incata/model"
     5  	"github.com/satori/go.uuid"
     6  )
     7  
     8  // MemoryReader for memory reading
     9  type MemoryReader struct {
    10  	Data []model.Event
    11  }
    12  
    13  // NewMemoryReader creates a new memory reader
    14  func NewMemoryReader(data []model.Event) *MemoryReader {
    15  
    16  	return &MemoryReader{
    17  		Data: data,
    18  	}
    19  }
    20  
    21  // Write writes a value to a string slice
    22  func (r *MemoryReader) Read(sourceID uuid.UUID) ([]model.Event, error) {
    23  
    24  	var events = make([]model.Event, 0)
    25  
    26  	for _, event := range r.Data {
    27  
    28  		if event.SourceID == sourceID {
    29  			events = append(events, event)
    30  		}
    31  	}
    32  
    33  	return events, nil
    34  }