fix: ignore segments without writer

This commit is contained in:
Jan De Dobbeleer 2020-09-17 16:51:29 +02:00 committed by Jan De Dobbeleer
parent a639240f9c
commit db212d513f
3 changed files with 13 additions and 8 deletions

View file

@ -90,8 +90,8 @@ func (e *engine) renderBlockSegments(block *Block) string {
defer e.reset()
e.activeBlock = block
for _, segment := range block.Segments {
props := segment.mapSegmentWithWriter(e.env)
if !segment.enabled() {
props, err := segment.mapSegmentWithWriter(e.env)
if err != nil || !segment.enabled() {
continue
}
e.activeSegment = segment

View file

@ -1,5 +1,7 @@
package main
import "errors"
//Segment represent a single segment and it's configuration
type Segment struct {
Type SegmentType `json:"type"`
@ -68,7 +70,7 @@ func (segment *Segment) enabled() bool {
return segment.writer.enabled()
}
func (segment *Segment) mapSegmentWithWriter(env environmentInfo) *properties {
func (segment *Segment) mapSegmentWithWriter(env environmentInfo) (*properties, error) {
functions := map[SegmentType]SegmentWriter{
Session: &session{},
Path: &path{},
@ -92,7 +94,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) *properties {
}
writer.init(props, env)
segment.writer = writer
return props
return props, nil
}
return nil
return nil, errors.New("Unable to map writer")
}

View file

@ -11,7 +11,9 @@ func TestMapSegmentWriterCanMap(t *testing.T) {
Type: Session,
}
env := new(MockedEnvironment)
sc.mapSegmentWithWriter(env)
props, err := sc.mapSegmentWithWriter(env)
assert.NotNil(t, props)
assert.NoError(t, err)
assert.NotNil(t, sc.writer)
}
@ -20,6 +22,7 @@ func TestMapSegmentWriterCannotMap(t *testing.T) {
Type: "nilwriter",
}
env := new(MockedEnvironment)
sc.mapSegmentWithWriter(env)
assert.Nil(t, sc.writer)
props, err := sc.mapSegmentWithWriter(env)
assert.Nil(t, props)
assert.Error(t, err)
}