registry/internal/validators/registries/oci_test.go
adam jones 694a4d8879
Add registry validators (#350)
Fixes #96

## Motivation and Context

See #96

## How Has This Been Tested?

Has some unit and integration tests, still needs proper testing of the
different registry types

## Breaking Changes

Yes, new package uploads will need extra verification

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
2025-09-04 22:45:59 +01:00

84 lines
2.2 KiB
Go

package registries_test
import (
"context"
"testing"
"github.com/modelcontextprotocol/registry/internal/validators/registries"
"github.com/modelcontextprotocol/registry/pkg/model"
"github.com/stretchr/testify/assert"
)
func TestValidateOCI_RealPackages(t *testing.T) {
ctx := context.Background()
tests := []struct {
name string
packageName string
version string
serverName string
expectError bool
errorMessage string
}{
{
name: "non-existent image should fail",
packageName: generateRandomImageName(),
version: "latest",
serverName: "com.example/test",
expectError: true,
errorMessage: "not found",
},
{
name: "real image without MCP annotation should fail",
packageName: "nginx", // Popular image without MCP annotation
version: "latest",
serverName: "com.example/test",
expectError: true,
errorMessage: "missing required annotation",
},
{
name: "real image with specific tag without MCP annotation should fail",
packageName: "redis",
version: "7-alpine", // Specific tag
serverName: "com.example/test",
expectError: true,
errorMessage: "missing required annotation",
},
{
name: "namespaced image without MCP annotation should fail",
packageName: "hello-world", // Simple image for testing
version: "latest",
serverName: "com.example/test",
expectError: true,
errorMessage: "missing required annotation",
},
{
name: "real image with correct MCP annotation should pass",
packageName: "domdomegg/airtable-mcp-server",
version: "1.7.2",
serverName: "io.github.domdomegg/airtable-mcp-server", // This should match the annotation
expectError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Skip("Skipping OCI registry tests because we keep hitting DockerHub rate limits")
pkg := model.Package{
RegistryType: model.RegistryTypeOCI,
Identifier: tt.packageName,
Version: tt.version,
}
err := registries.ValidateOCI(ctx, pkg, tt.serverName)
if tt.expectError {
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.errorMessage)
} else {
assert.NoError(t, err)
}
})
}
}