github.com/grafana/synthetic-monitoring-agent@v0.64.2/internal/scraper/catalogue_integration_test.go (about)

     1  package scraper
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  const runtimeCatalogueIntegrationEnv = "SM_RUNTIME_CATALOGUE_INTEGRATION"
     9  
    10  // TestValidateMetricCatalogueIntegration validates the runtime-only catalogue
    11  // for k6-backed checks when they execute with a real sm-k6 binary and
    12  // browser-capable environment. It is intentionally distinct from the fixture
    13  // catalogue test, which protects the deterministic local fixture/replay path.
    14  func TestValidateMetricCatalogueIntegration(t *testing.T) {
    15  	if os.Getenv(runtimeCatalogueIntegrationEnv) == "" {
    16  		t.Skipf("set %s=1 to run runtime catalogue integration tests", runtimeCatalogueIntegrationEnv)
    17  	}
    18  
    19  	k6Path := os.Getenv("K6_PATH")
    20  	if k6Path == "" {
    21  		t.Fatalf("K6_PATH must be set when %s is enabled", runtimeCatalogueIntegrationEnv)
    22  	}
    23  
    24  	if _, err := os.Stat(k6Path); err != nil {
    25  		t.Fatalf("K6_PATH %q is not usable: %v", k6Path, err)
    26  	}
    27  
    28  	expectedCatalogues := loadMetricLabelCatalogues(t, "expected_runtime_metric_catalogue.json")
    29  
    30  	for class, spec := range runtimeCatalogueSpecs() {
    31  		t.Run(class, func(t *testing.T) {
    32  			t.Setenv("K6_PATH", k6Path)
    33  
    34  			expected, ok := expectedCatalogues[class]
    35  			if !ok {
    36  				t.Fatalf("missing expected catalogue for %s", class)
    37  			}
    38  
    39  			observed := collectFixtureCatalogue(t, class, spec)
    40  
    41  			result := CompareMetricCatalogue(expected, observed)
    42  			if !result.Success() {
    43  				t.Fatalf("catalogue mismatch for %s: %s", class, result.Summary())
    44  			}
    45  		})
    46  	}
    47  }