func TestRaftNodeFirst(t *testing.T) {
	tx, cleanup := libtesting.NewTestNodeTx(t)
	defer cleanup()
	err := tx.RaftNodeFirst("1.2.3.4:666")
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	err = tx.RaftNodeDelete(1)
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	err = tx.RaftNodeFirst("5.6.7.8:666")
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	address, err := tx.RaftNodeAddress(1)
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	if expected, actual := "5.6.7.8:666", address; expected != actual {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
}
Add the first raft node.
package db_test
import (
	"reflect"
	"testing"
	"github.com/spoke-d/thermionic/internal/db"
	libtesting "github.com/spoke-d/thermionic/internal/testing"
)
func TestTx_Config(t *testing.T) {
	tx, cleanup := libtesting.NewTestNodeTx(t)
	defer cleanup()
	values, err := tx.Config()
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	if expected, actual := map[string]string{}, values; !reflect.DeepEqual(expected, actual) {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
}
func TestTx_UpdateConfig(t *testing.T) {
	tx, cleanup := libtesting.NewTestNodeTx(t)
	defer cleanup()
	err := tx.UpdateConfig(map[string]string{
		"foo": "x",
		"bar": "y",
	})
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	values, err := tx.Config()
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	want := map[string]string{
		"foo": "x",
		"bar": "y",
	}
	if expected, actual := want, values; !reflect.DeepEqual(expected, actual) {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
}
func TestTx_UpdateConfigUnsetKeys(t *testing.T) {
	tx, cleanup := libtesting.NewTestNodeTx(t)
	defer cleanup()
	err := tx.UpdateConfig(map[string]string{"foo": "x", "bar": "y"})
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	err = tx.UpdateConfig(map[string]string{"foo": "x", "bar": ""})
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	values, err := tx.Config()
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	want := map[string]string{
		"foo": "x",
	}
	if expected, actual := want, values; !reflect.DeepEqual(expected, actual) {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
}
func TestRaftNodes(t *testing.T) {
	tx, cleanup := libtesting.NewTestNodeTx(t)
	defer cleanup()
	id1, err := tx.RaftNodeAdd("1.2.3.4:666")
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	id2, err := tx.RaftNodeAdd("5.6.7.8:666")
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	nodes, err := tx.RaftNodes()
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	if expected, actual := id1, nodes[0].ID; expected != actual {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
	if expected, actual := id2, nodes[1].ID; expected != actual {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
	if expected, actual := "1.2.3.4:666", nodes[0].Address; expected != actual {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
	if expected, actual := "5.6.7.8:666", nodes[1].Address; expected != actual {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
}
func TestRaftNodeAddresses(t *testing.T) {
	tx, cleanup := libtesting.NewTestNodeTx(t)
	defer cleanup()
	_, err := tx.RaftNodeAdd("1.2.3.4:666")
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	_, err = tx.RaftNodeAdd("5.6.7.8:666")
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	addresses, err := tx.RaftNodeAddresses()
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	if expected, actual := []string{"1.2.3.4:666", "5.6.7.8:666"}, addresses; !reflect.DeepEqual(expected, actual) {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
}
func TestRaftNodeAddress(t *testing.T) {
	tx, cleanup := libtesting.NewTestNodeTx(t)
	defer cleanup()
	_, err := tx.RaftNodeAdd("1.2.3.4:666")
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	id, err := tx.RaftNodeAdd("5.6.7.8:666")
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	address, err := tx.RaftNodeAddress(id)
	if err != nil {
		t.Errorf("expected err to be nil: %v", err)
	}
	if expected, actual := "5.6.7.8:666", address; expected != actual {
		t.Errorf("expected: %v, actual: %v", expected, actual)
	}
}