open-consul/agent/consul/fsm/fsm_test.go

59 lines
996 B
Go
Raw Normal View History

package fsm
2013-12-11 22:38:18 +00:00
import (
"bytes"
2014-02-03 23:21:56 +00:00
"os"
2013-12-11 22:38:18 +00:00
"testing"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/raft"
"github.com/stretchr/testify/assert"
2013-12-11 22:38:18 +00:00
)
type MockSink struct {
*bytes.Buffer
cancel bool
}
func (m *MockSink) ID() string {
return "Mock"
}
func (m *MockSink) Cancel() error {
m.cancel = true
return nil
}
func (m *MockSink) Close() error {
return nil
}
func makeLog(buf []byte) *raft.Log {
return &raft.Log{
Index: 1,
Term: 1,
Type: raft.LogCommand,
Data: buf,
}
}
func TestFSM_IgnoreUnknown(t *testing.T) {
2017-05-22 22:14:27 +00:00
t.Parallel()
fsm, err := New(nil, os.Stderr)
assert.Nil(t, err)
// Create a new reap request
type UnknownRequest struct {
Foo string
}
req := UnknownRequest{Foo: "bar"}
msgType := structs.IgnoreUnknownTypeFlag | 64
buf, err := structs.Encode(msgType, req)
assert.Nil(t, err)
// Apply should work, even though not supported
resp := fsm.Apply(makeLog(buf))
err, ok := resp.(error)
assert.False(t, ok, "response: %s", err)
}