package runtimeproduction

import (
	"os"
	"strings"
	"testing"
)

func TestProductionServingSecurityRenewalKeepsIndependentBoundedDBOwnership(t *testing.T) {
	source, err := os.ReadFile("assemble.go")
	if err != nil {
		t.Fatal(err)
	}
	body := string(source)
	for _, required := range []string{
		"connection.OpenIndependentDB(database.PoolOptions{",
		"MaxOpenConns: 1, MaxIdleConns: 1",
		"securityRenewalRepository := persistence.NewRuntimeSecurityRepository(securityRenewalDB)",
		"ctx, securityRenewalRepository, securityRepository,",
	} {
		if !strings.Contains(body, required) {
			t.Fatalf("production Runtime lost independent security-renewal ownership %q", required)
		}
	}
	if strings.Contains(body, "ctx, securityRepository, securityRepository,") {
		t.Fatal("production Runtime routed lease renewal back through the business database pool")
	}
}
