2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-10-24 17:39:42 +00:00
|
|
|
//go:build !consulent
|
|
|
|
// +build !consulent
|
|
|
|
|
2017-11-30 01:33:57 +00:00
|
|
|
package fsm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
2021-02-03 23:10:38 +00:00
|
|
|
|
2022-10-24 17:39:42 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-04-05 21:10:06 +00:00
|
|
|
|
2023-04-04 16:30:06 +00:00
|
|
|
"github.com/hashicorp/consul-net-rpc/go-msgpack/codec"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/consul/state"
|
2017-11-30 01:33:57 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2020-01-28 23:50:41 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
2017-11-30 01:33:57 +00:00
|
|
|
)
|
|
|
|
|
2022-10-24 17:39:42 +00:00
|
|
|
func TestRestoreFromEnterprise(t *testing.T) {
|
2020-01-28 23:50:41 +00:00
|
|
|
logger := testutil.Logger(t)
|
2023-04-04 16:30:06 +00:00
|
|
|
|
|
|
|
handle := &testRaftHandle{}
|
|
|
|
storageBackend := newStorageBackend(t, handle)
|
|
|
|
handle.apply = func(buf []byte) (any, error) { return storageBackend.Apply(buf, 123), nil }
|
|
|
|
|
|
|
|
fsm := NewFromDeps(Deps{
|
|
|
|
Logger: logger,
|
|
|
|
NewStateStore: func() *state.Store {
|
|
|
|
return state.NewStateStore(nil)
|
|
|
|
},
|
|
|
|
StorageBackend: storageBackend,
|
|
|
|
})
|
|
|
|
|
2022-10-24 15:40:26 +00:00
|
|
|
// To verify if a proper message is displayed when Consul OSS tries to
|
|
|
|
// unsuccessfully restore entries from a Consul Ent snapshot.
|
2022-10-24 17:39:42 +00:00
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
sink := &MockSink{buf, false}
|
2022-10-24 15:40:26 +00:00
|
|
|
|
|
|
|
type EntMock struct {
|
|
|
|
ID int
|
|
|
|
Type string
|
|
|
|
}
|
|
|
|
|
|
|
|
entMockEntry := EntMock{
|
|
|
|
ID: 65,
|
|
|
|
Type: "A Consul Ent Log Type",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the header
|
|
|
|
header := SnapshotHeader{
|
|
|
|
LastIndex: 0,
|
|
|
|
}
|
2022-10-24 17:39:42 +00:00
|
|
|
encoder := codec.NewEncoder(sink, structs.MsgpackHandle)
|
2022-10-24 15:40:26 +00:00
|
|
|
encoder.Encode(&header)
|
|
|
|
sink.Write([]byte{byte(structs.MessageType(entMockEntry.ID))})
|
|
|
|
encoder.Encode(entMockEntry)
|
|
|
|
|
|
|
|
require.EqualError(t, fsm.Restore(sink), "msg type <65> is a Consul Enterprise log entry. Consul OSS cannot restore it")
|
|
|
|
sink.Cancel()
|
2017-11-30 01:33:57 +00:00
|
|
|
}
|