package extension

import (
	"testing"

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

func TestRuntimeConnectionGenerationBindsEveryPreflightInput(t *testing.T) {
	t.Parallel()

	base := RuntimeConnectionGeneration(
		"appconn_one",
		"email:h1:subject",
		"sha256:credential",
		[]byte(`{"schemaVersion":1}`),
	)
	require.Regexp(t, `^sha256:[0-9a-f]{64}$`, base)
	require.Equal(t, base, RuntimeConnectionGeneration(
		"appconn_one",
		"email:h1:subject",
		"sha256:credential",
		[]byte(`{"schemaVersion":1}`),
	))
	require.NotEqual(t, base, RuntimeConnectionGeneration(
		"appconn_two",
		"email:h1:subject",
		"sha256:credential",
		[]byte(`{"schemaVersion":1}`),
	))
	require.NotEqual(t, base, RuntimeConnectionGeneration(
		"appconn_one",
		"email:h1:other",
		"sha256:credential",
		[]byte(`{"schemaVersion":1}`),
	))
	require.NotEqual(t, base, RuntimeConnectionGeneration(
		"appconn_one",
		"email:h1:subject",
		"sha256:other",
		[]byte(`{"schemaVersion":1}`),
	))
	require.NotEqual(t, base, RuntimeConnectionGeneration(
		"appconn_one",
		"email:h1:subject",
		"sha256:credential",
		[]byte(`{"schemaVersion":2}`),
	))
}
