package persistence

import (
	"strings"
	"testing"
)

const runtimePlatformCommandPreparePublicationTestSQL = `UPDATE _System_RuntimePlatformCommand
	SET State = 'PUBLISHING', ResultPayload = ?, PublicationIdentity = ?,
	    PublishAttempt = 0, RecoveryState = NULL,
    AvailableAt = UTC_TIMESTAMP(6), LeaseToken = NULL, LeaseExpiresAt = NULL,
    OwnershipEpoch = NULL, LastError = NULL,
    DependencyKind = NULL, DependencyObjectAPIName = NULL, DependencyRecordId = NULL,
    DependencyKeyHash = NULL, DependencyConnectorOwnerKey = NULL,
    DependencyConnectorNamespace = NULL, DependencyConnectorSourceObject = NULL,
    DependencyDestinationSlotId = NULL, DependencyConnectorRemoteId = NULL,
    DependencyBlockedAt = NULL, LastModifiedDate = UTC_TIMESTAMP(6)
WHERE Id = ? AND OrgId = ? AND AppInstallationId = ? AND RuntimeCapabilityId = ?
  AND State = 'PROCESSING' AND LeaseToken = ? AND Attempt = ? AND OwnershipEpoch = ?`

func TestRuntimePlatformCommandPublicationIdentityIsDelimitedAndStable(t *testing.T) {
	first, err := runtimePlatformCommandPublicationIdentity(strings.Repeat("a", 64), "ab", "c")
	if err != nil {
		t.Fatal(err)
	}
	second, err := runtimePlatformCommandPublicationIdentity(strings.Repeat("a", 64), "a", "bc")
	if err != nil {
		t.Fatal(err)
	}
	replay, err := runtimePlatformCommandPublicationIdentity(strings.Repeat("a", 64), "ab", "c")
	if err != nil {
		t.Fatal(err)
	}
	if first == second || first != replay || len(first) != 71 {
		t.Fatalf("publication identities = first %q second %q replay %q", first, second, replay)
	}
}
