Skip to content

Commit

Permalink
journalbeat: tests for config (#17114)
Browse files Browse the repository at this point in the history
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
  • Loading branch information
greut authored Mar 21, 2020
1 parent 668dd35 commit daf9099
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion journalbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package cmd
import (
"github.com/elastic/beats/v7/journalbeat/beater"

cmd "github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cmd/instance"

// Import processors.
Expand Down
74 changes: 74 additions & 0 deletions journalbeat/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,77 @@
// +build !integration

package config

import (
"testing"
)

func TestUnpack(t *testing.T) {

tests := []struct {
mode SeekMode
modeStr string
}{
{
mode: SeekHead,
modeStr: seekHeadStr,
},
{
mode: SeekTail,
modeStr: seekTailStr,
},
{
mode: SeekCursor,
modeStr: seekCursorStr,
},
}

for _, tc := range tests {
tc := tc

t.Run(tc.modeStr, func(t *testing.T) {
t.Parallel()

m := SeekInvalid
err := m.Unpack(tc.modeStr)
if err != nil {
t.Fatal(err)
}

if m != tc.mode {
t.Errorf("wrong mode, expected %v, got %v", tc.mode, m)
}
})
}
}

func TestUnpackFailure(t *testing.T) {

tests := []struct {
modeStr string
}{
{
modeStr: "invalid",
},
{
modeStr: "",
},
{
modeStr: "unknown",
},
}

for _, tc := range tests {
tc := tc

t.Run(tc.modeStr, func(t *testing.T) {
t.Parallel()

m := SeekInvalid
err := m.Unpack(tc.modeStr)
if err == nil {
t.Errorf("an error was expected, got %v", m)
}
})
}
}

0 comments on commit daf9099

Please sign in to comment.