//go:build perf

package perfsuite_test

import (
	"os"
	"testing"

	"gitea.dockr.co/kev/go-jdenticon/internal/perfsuite"
)

// TestPerformanceRegressionSuite can be called from a regular Go test
func TestPerformanceRegressionSuite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping performance regression tests in short mode")
	}

	suite := perfsuite.NewPerformanceSuite()
	suite.FailOnRegress = false // Don't fail tests, just report

	// Check if we should establish baselines
	if os.Getenv("ESTABLISH_BASELINES") == "true" {
		if err := suite.EstablishBaselines(); err != nil {
			t.Fatalf("Failed to establish baselines: %v", err)
		}
		return
	}

	// Run regression check
	if err := suite.CheckForRegressions(); err != nil {
		t.Logf("Performance regression check completed with issues: %v", err)
		// Don't fail the test, just log the results
	}
}

// BenchmarkPerformanceSuite runs all performance benchmarks for standard Go bench testing
func BenchmarkPerformanceSuite(b *testing.B) {
	suite := perfsuite.NewPerformanceSuite()

	for _, bench := range suite.Benchmarks {
		b.Run(bench.Name, bench.BenchmarkFunc)
	}
}
