package catalogpublication

import (
	"strings"
	"testing"
)

func TestNamespaceAuthoritySchemaIsProvisionedExactlyOnce(t *testing.T) {
	joined := strings.Join(SchemaStatementsForTest(), "\n")
	create := "CREATE TABLE IF NOT EXISTS _System_CatalogNamespaceAuthority "
	if count := strings.Count(joined, create); count != 1 {
		t.Fatalf(
			"Catalog publication schema provisions namespace authority %d times, want exactly once",
			count,
		)
	}
	seed := "INSERT IGNORE INTO _System_CatalogNamespaceAuthority"
	if count := strings.Count(joined, seed); count != 1 {
		t.Fatalf(
			"Catalog publication schema seeds system namespace %d times, want exactly once",
			count,
		)
	}
}
