1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
//go:build linux && cgo && !agent
package db_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/lxc/incus/v6/internal/server/db"
)
// Node-local configuration values are initially empty.
func TestTx_Config(t *testing.T) {
tx, cleanup := db.NewTestNodeTx(t)
defer cleanup()
values, err := tx.Config(context.Background())
require.NoError(t, err)
assert.Equal(t, map[string]string{}, values)
assert.NoError(t, err)
}
// Node-local configuration values can be updated with UpdateConfig.
func TestTx_UpdateConfig(t *testing.T) {
tx, cleanup := db.NewTestNodeTx(t)
defer cleanup()
err := tx.UpdateConfig(map[string]string{"foo": "x", "bar": "y"})
require.NoError(t, err)
values, err := tx.Config(context.Background())
require.NoError(t, err)
assert.Equal(t, map[string]string{"foo": "x", "bar": "y"}, values)
}
// Keys that are associated with empty strings are deleted.
func TestTx_UpdateConfigUnsetKeys(t *testing.T) {
tx, cleanup := db.NewTestNodeTx(t)
defer cleanup()
err := tx.UpdateConfig(map[string]string{"foo": "x", "bar": "y"})
require.NoError(t, err)
err = tx.UpdateConfig(map[string]string{"foo": "x", "bar": ""})
require.NoError(t, err)
values, err := tx.Config(context.Background())
require.NoError(t, err)
assert.Equal(t, map[string]string{"foo": "x"}, values)
}
|