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-04-05 21:10:06 +00:00
|
|
|
"github.com/hashicorp/consul-net-rpc/go-msgpack/codec"
|
2022-10-24 17:39:42 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-04-05 21:10:06 +00:00
|
|
|
|
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) {
|
2018-03-06 18:35:20 +00:00
|
|
|
|
2020-01-28 23:50:41 +00:00
|
|
|
logger := testutil.Logger(t)
|
|
|
|
fsm, err := New(nil, logger)
|
2020-06-08 19:44:06 +00:00
|
|
|
require.NoError(t, err)
|
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
|
|
|
}
|