package loader

import (
	"crypto/sha256"
	"testing"

	"github.com/stretchr/testify/require"
)

// TestSumSHA256 verifies that SumSHA256 returns the same digest
// as the standard library implementation for a non-empty payload.
func TestSumSHA256(t *testing.T) {
	t.Parallel()

	data := []byte("hello world")
	expected := sha256.Sum256(data)

	actual := SumSHA256(data)

	require.Equal(t, expected, actual)
}

// TestSumSHA256Empty verifies that SumSHA256 correctly handles
// an empty byte slice.
func TestSumSHA256Empty(t *testing.T) {
	t.Parallel()

	data := []byte{}
	expected := sha256.Sum256(data)

	actual := SumSHA256(data)

	require.Equal(t, expected, actual)
}

// TestEqualSHA256Same verifies that two identical digests
// are considered equal.
func TestEqualSHA256Same(t *testing.T) {
	t.Parallel()

	data := []byte("hello")
	digest := sha256.Sum256(data)

	require.True(t, EqualSHA256(digest, digest))
}

// TestEqualSHA256Different verifies that different digests
// are considered not equal.
func TestEqualSHA256Different(t *testing.T) {
	t.Parallel()

	digestA := sha256.Sum256([]byte("hello"))
	digestB := sha256.Sum256([]byte("world"))

	require.False(t, EqualSHA256(digestA, digestB))
}
