chore: migrate fixtures to testdata (#4651)

* migrate fixtures to testdata

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix: correct broken symlinks after testdata migration

The migration from test-fixtures to testdata broke several symlinks:
- elf-test-fixtures symlinks pointed to old test-fixtures paths
- elf-test-fixtures needed to be renamed to elf-testdata
- image-pkg-coverage symlink pointed to test-fixtures instead of testdata

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix: handle missing classifiers/bin directory in Makefile

The clean-fingerprint target was failing when classifiers/bin doesn't
exist (e.g., on fresh clone without downloaded binaries).

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix: add gitignore negation for jar/zip fixtures in test/cli

The jar and zip files in test/cli/testdata/image-unknowns were being
gitignored by the root .gitignore patterns. This caused them to be
untracked and not included when building docker images in CI, resulting
in Test_Unknowns failures since the test expects errors from corrupt
archive files that weren't present.

Add a .gitignore in test/cli/testdata to negate the exclusions for
these specific test fixture files.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* switch fixture cache to v2

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* test: update expected versions for rebuilt fixtures

Update test expectations for packages that have been updated in
upstream repositories when docker images are rebuilt:
- glibc: 2.42-r4 → 2.43-r1 (wolfi)
- php: 8.2.29 → 8.2.30 (ubuntu/apache)

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* upgrade go

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix: add go-shlex dependency for testdata manager tool

The manager tool in syft/pkg/cataloger/binary/testdata/ imports
go-shlex, but since it's in a testdata directory, Go doesn't track
its dependencies. This caused CI failures when go.mod didn't
explicitly list the dependency.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor: move binary classifier manager to internal/

Move the manager tool from testdata/manager to internal/manager so
that Go properly tracks its dependencies. Code in testdata directories
is ignored by Go for dependency tracking, which caused CI failures
when go.mod didn't explicitly list transitive dependencies.

This is a cleaner solution than manually adding dependencies to go.mod
for code that happens to live in testdata.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix: add gitignore negations for test fixtures blocked by root patterns

Multiple test fixtures were being blocked by root-level gitignore patterns
like bin/, *.jar, *.tar, and *.exe. This adds targeted .gitignore files with
negation patterns to allow these specific test fixtures to be tracked:

- syft/linux/testdata/os/busybox/bin/busybox (blocked by bin/)
- syft/pkg/cataloger/java/testdata/corrupt/example.{jar,tar} (blocked by *.jar, *.tar)
- syft/pkg/cataloger/binary/testdata/classifiers/snippets/go-version-hint/**/bin/go (blocked by bin/)
- syft/pkg/cataloger/bitnami/testdata/no-rel/.../bin/redis-server (blocked by bin/)

Also updates the bitnami test expectation to include the newly required
.gitignore files in the test fixture.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* test: update glibc version expectation (2.43-r1 -> 2.43-r2)

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* add capability drift check as unit step

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* dont clear test observations before drift detection

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* bump stereoscope commit to main

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman
2026-03-06 19:42:04 +00:00
committed by GitHub
parent 35278f3d3d
commit b5e85c3ea5
1589 changed files with 1184 additions and 1058 deletions
+9 -9
View File
@@ -48,7 +48,7 @@ graph LR
end
subgraph "Test Inputs"
B1[test-fixtures/<br/>test-observations.json]
B1[testdata/<br/>test-observations.json]
end
subgraph "Discovery Processes"
@@ -400,7 +400,7 @@ func NewGoModuleBinaryCataloger(cfg golang.CatalogerConfig) pkg.Cataloger
**What it finds:** metadata types and package types each parser produces
**Process:**
1. Find all `test-fixtures/test-observations.json` files
1. Find all `testdata/test-observations.json` files
2. Parse JSON which contains:
```json
{
@@ -503,7 +503,7 @@ func (c golangConfig) DescribeFields(opts ...options.DescribeFieldsOption) []opt
#### test-observations.json Files
**Location:** `syft/pkg/cataloger/*/test-fixtures/test-observations.json`
**Location:** `syft/pkg/cataloger/*/testdata/test-observations.json`
**Purpose:** records what metadata and package types each parser produces during test execution
@@ -515,7 +515,7 @@ func TestGoModuleCataloger(t *testing.T) {
tester := NewGoModuleBinaryCataloger()
pkgtest.NewCatalogTester().
FromDirectory(t, "test-fixtures/go-module-fixture").
FromDirectory(t, "testdata/go-module-fixture").
TestCataloger(t, tester) // Auto-writes observations on first run
}
```
@@ -832,7 +832,7 @@ capabilities:
**Fix:** update tests to use `pkgtest.CatalogTester`:
```go
pkgtest.NewCatalogTester().
FromDirectory(t, "test-fixtures/my-fixture").
FromDirectory(t, "testdata/my-fixture").
TestCataloger(t, myCataloger)
```
@@ -1071,7 +1071,7 @@ SYFT_ENABLE_COMPLETENESS_TESTS=true go test ./internal/capabilities/...
# 7. Commit
git add syft/pkg/cataloger/mynew/capabilities.yaml
git add syft/pkg/cataloger/mynew/test-fixtures/test-observations.json
git add syft/pkg/cataloger/mynew/testdata/test-observations.json
git commit
```
@@ -1129,7 +1129,7 @@ go generate ./internal/capabilities
# 5. Commit
git add syft/pkg/cataloger/*/capabilities.yaml
git add syft/pkg/cataloger/something/test-fixtures/test-observations.json
git add syft/pkg/cataloger/something/testdata/test-observations.json
git commit
```
@@ -1261,7 +1261,7 @@ go generate ./internal/capabilities
```go
// Update test to use pkgtest
pkgtest.NewCatalogTester().
FromDirectory(t, "test-fixtures/my-fixture").
FromDirectory(t, "testdata/my-fixture").
TestCataloger(t, myCataloger)
// Run tests
@@ -1294,7 +1294,7 @@ func TestMyParser(t *testing.T) {
func TestMyParser(t *testing.T) {
cataloger := NewMyCataloger()
pkgtest.NewCatalogTester().
FromDirectory(t, "test-fixtures/my-fixture").
FromDirectory(t, "testdata/my-fixture").
TestCataloger(t, cataloger)
}
```
@@ -83,7 +83,7 @@ func (idx *TestObservationIndex) extractCustomCatalogerData() (map[string][]stri
// discoverMetadataTypes searches for test-observations.json files and merges metadata type information
// into the discovered catalogers. Returns maps of custom cataloger metadata types and package types.
func discoverMetadataTypes(repoRoot string, discovered map[string]DiscoveredCataloger) (map[string][]string, map[string][]string, error) {
testFixtureDirs, err := internal.FindTestFixtureDirs(repoRoot)
testDataDirs, err := internal.FindTestDataDirs(repoRoot)
if err != nil {
return nil, nil, err
}
@@ -92,7 +92,7 @@ func discoverMetadataTypes(repoRoot string, discovered map[string]DiscoveredCata
index := newTestObservationIndex()
// read all test-observations files and merge into index
for _, dir := range testFixtureDirs {
for _, dir := range testDataDirs {
observationsFile := filepath.Join(dir, "test-observations.json")
if observations, err := internal.ReadTestObservations(observationsFile); err == nil {
mergeTestObservations(observations, index)
+6 -6
View File
@@ -9,17 +9,17 @@ import (
"github.com/anchore/syft/internal/capabilities/pkgtestobservation"
)
// FindTestFixtureDirs walks the cataloger directory tree and returns all test-fixtures directories
func FindTestFixtureDirs(repoRoot string) ([]string, error) {
// FindTestDataDirs walks the cataloger directory tree and returns all testdata directories
func FindTestDataDirs(repoRoot string) ([]string, error) {
catalogerRoot := filepath.Join(repoRoot, "syft", "pkg", "cataloger")
var testFixtureDirs []string
var testDataDirs []string
err := filepath.Walk(catalogerRoot, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() && info.Name() == "test-fixtures" {
testFixtureDirs = append(testFixtureDirs, path)
if info.IsDir() && info.Name() == "testdata" {
testDataDirs = append(testDataDirs, path)
}
return nil
})
@@ -27,7 +27,7 @@ func FindTestFixtureDirs(repoRoot string) ([]string, error) {
return nil, fmt.Errorf("failed to walk cataloger directory: %w", err)
}
return testFixtureDirs, nil
return testDataDirs, nil
}
// ReadTestObservations reads and parses a test-observations.json file
@@ -1233,7 +1233,7 @@ func TestCatalogerDataQuality(t *testing.T) {
}
// TestCatalogersHaveTestObservations ensures that all custom catalogers (and optionally parsers) have
// test observations recorded in test-fixtures/test-observations.json, which proves they are using the
// test observations recorded in testdata/test-observations.json, which proves they are using the
// pkgtest.CatalogTester helpers and have test coverage.
func TestCatalogersHaveTestObservations(t *testing.T) {
checkCompletenessTestsEnabled(t)
@@ -1249,11 +1249,11 @@ func TestCatalogersHaveTestObservations(t *testing.T) {
observedCatalogers := strset.New()
observedParsers := make(map[string]*strset.Set) // package -> parser set
// walk test-fixtures directories to find test-observations.json files
testFixtureDirs, err := FindTestFixtureDirs(repoRoot)
// walk testdata directories to find test-observations.json files
testDataDirs, err := FindTestDataDirs(repoRoot)
require.NoError(t, err)
for _, dir := range testFixtureDirs {
for _, dir := range testDataDirs {
observationsFile := filepath.Join(dir, "test-observations.json")
if _, err := os.Stat(observationsFile); os.IsNotExist(err) {
continue