Files
poimen-workflows/internal/audit/immutable_log_test.go
T

48 lines
1.1 KiB
Go
Raw Normal View History

package audit
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAppendEntry(t *testing.T) {
log := NewImmutableLog("", "workflow-1")
entry, err := log.Append("Decision: approved", map[string]interface{}{})
assert.NoError(t, err)
assert.NotNil(t, entry)
assert.Equal(t, int64(1), entry.Sequence)
}
func TestVerifyIntegrity(t *testing.T) {
log := NewImmutableLog("", "workflow-1")
log.Append("Entry 1", map[string]interface{}{})
log.Append("Entry 2", map[string]interface{}{})
valid, err := log.Verify()
assert.NoError(t, err)
assert.True(t, valid)
}
func TestGetEntries(t *testing.T) {
log := NewImmutableLog("", "workflow-1")
log.Append("Entry 1", map[string]interface{}{})
log.Append("Entry 2", map[string]interface{}{})
entries := log.GetEntries()
assert.Equal(t, 2, len(entries))
}
func TestChainHashes(t *testing.T) {
log := NewImmutableLog("", "workflow-1")
entry1, _ := log.Append("Entry 1", map[string]interface{}{})
entry2, _ := log.Append("Entry 2", map[string]interface{}{})
assert.Equal(t, "genesis", entry1.PrevHash)
assert.Equal(t, entry1.Hash, entry2.PrevHash)
}