You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chantools/cmd/chantools/compactdb_test.go

47 lines
1021 B
Go

package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCompactDBAndDumpChannels(t *testing.T) {
h := newHarness(t)
// Compact the test DB.
compact := &compactDBCommand{
SourceDB: h.testdataFile("channel.db"),
DestDB: h.tempFile("compacted.db"),
}
err := compact.Execute(nil, nil)
require.NoError(t, err)
require.FileExists(t, compact.DestDB)
// Compacting small DBs actually increases the size slightly. But we
// just want to make sure the contents match.
require.GreaterOrEqual(
t, h.fileSize(compact.DestDB), h.fileSize(compact.SourceDB),
)
// Compare the content of the source and destination DB by looking at
// the logged dump.
dump := &dumpChannelsCommand{
ChannelDB: compact.SourceDB,
}
h.clearLog()
err = dump.Execute(nil, nil)
require.NoError(t, err)
sourceDump := h.getLog()
h.clearLog()
dump.ChannelDB = compact.DestDB
err = dump.Execute(nil, nil)
require.NoError(t, err)
destDump := h.getLog()
h.assertLogEqual(sourceDump, destDump)
}