Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schema-based rules for discovery dependencies data of package index #204

Merged
merged 2 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions etc/schemas/arduino-package-index-definitions-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@
},
"toolsDependencies": {
"$ref": "#/definitions/propertiesObjects/toolsDependencies/permissive/object"
},
"discoveryDependencies": {
"$ref": "#/definitions/propertiesObjects/discoveryDependencies/permissive/object"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -503,6 +506,9 @@
},
"toolsDependencies": {
"$ref": "#/definitions/propertiesObjects/toolsDependencies/specification/object"
},
"discoveryDependencies": {
"$ref": "#/definitions/propertiesObjects/discoveryDependencies/specification/object"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -555,6 +561,9 @@
},
"toolsDependencies": {
"$ref": "#/definitions/propertiesObjects/toolsDependencies/strict/object"
},
"discoveryDependencies": {
"$ref": "#/definitions/propertiesObjects/discoveryDependencies/strict/object"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -997,6 +1006,83 @@
}
}
},
"discoveryDependencies": {
"base": {
"object": {
"type": "array",
"items": {
"type": "object",
"required": ["packager", "name"]
}
}
},
"permissive": {
"object": {
"allOf": [
{
"$ref": "#/definitions/propertiesObjects/discoveryDependencies/base/object"
},
{
"items": {
"properties": {
"packager": {
"$ref": "#/definitions/propertiesObjects/packager/permissive/object"
},
"name": {
"$ref": "#/definitions/propertiesObjects/toolName/permissive/object"
}
},
"additionalProperties": false
}
}
]
}
},
"specification": {
"object": {
"allOf": [
{
"$ref": "#/definitions/propertiesObjects/discoveryDependencies/base/object"
},
{
"items": {
"properties": {
"packager": {
"$ref": "#/definitions/propertiesObjects/packager/specification/object"
},
"name": {
"$ref": "#/definitions/propertiesObjects/toolName/specification/object"
}
},
"additionalProperties": false
}
}
]
}
},
"strict": {
"object": {
"allOf": [
{
"$ref": "#/definitions/propertiesObjects/discoveryDependencies/base/object"
},
{
"items": {
"properties": {
"packager": {
"$ref": "#/definitions/propertiesObjects/packager/strict/object"
},
"name": {
"$ref": "#/definitions/propertiesObjects/toolName/strict/object"
}
},
"additionalProperties": false
}
}
]
}
}
},
"packager": {
"base": {
"object": {
Expand Down
34 changes: 34 additions & 0 deletions internal/project/packageindex/packageindexschemas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ var validIndexRaw = []byte(`
"name": "avr-gcc",
"version": "7.3.0-atmel3.6.1-arduino7"
}
],
"discoveryDependencies": [
{
"packager": "arduino",
"name": "ble-discovery"
}
]
}
],
Expand Down Expand Up @@ -137,6 +143,14 @@ func TestMinLength(t *testing.T) {
{"/packages/0/platforms/0/toolsDependencies/0/name", 1, compliancelevel.Specification},
{"/packages/0/platforms/0/toolsDependencies/0/name", 1, compliancelevel.Strict},

{"/packages/0/platforms/0/discoveryDependencies/0/packager", 1, compliancelevel.Permissive},
{"/packages/0/platforms/0/discoveryDependencies/0/packager", 1, compliancelevel.Specification},
{"/packages/0/platforms/0/discoveryDependencies/0/packager", 1, compliancelevel.Strict},

{"/packages/0/platforms/0/discoveryDependencies/0/name", 1, compliancelevel.Permissive},
{"/packages/0/platforms/0/discoveryDependencies/0/name", 1, compliancelevel.Specification},
{"/packages/0/platforms/0/discoveryDependencies/0/name", 1, compliancelevel.Strict},

{"/packages/0/tools/0/systems/0/archiveFileName", 1, compliancelevel.Permissive},
{"/packages/0/tools/0/systems/0/archiveFileName", 1, compliancelevel.Specification},
{"/packages/0/tools/0/systems/0/archiveFileName", 1, compliancelevel.Strict},
Expand Down Expand Up @@ -276,6 +290,18 @@ func TestRequired(t *testing.T) {
{"/packages/0/platforms/0/toolsDependencies/0/version", compliancelevel.Specification, assert.True},
{"/packages/0/platforms/0/toolsDependencies/0/version", compliancelevel.Strict, assert.True},

{"/packages/0/platforms/0/discoveryDependencies", compliancelevel.Permissive, assert.False},
{"/packages/0/platforms/0/discoveryDependencies", compliancelevel.Specification, assert.False},
{"/packages/0/platforms/0/discoveryDependencies", compliancelevel.Strict, assert.False},

{"/packages/0/platforms/0/discoveryDependencies/0/packager", compliancelevel.Permissive, assert.True},
{"/packages/0/platforms/0/discoveryDependencies/0/packager", compliancelevel.Specification, assert.True},
{"/packages/0/platforms/0/discoveryDependencies/0/packager", compliancelevel.Strict, assert.True},

{"/packages/0/platforms/0/discoveryDependencies/0/name", compliancelevel.Permissive, assert.True},
{"/packages/0/platforms/0/discoveryDependencies/0/name", compliancelevel.Specification, assert.True},
{"/packages/0/platforms/0/discoveryDependencies/0/name", compliancelevel.Strict, assert.True},

{"/packages/0/tools/0/name", compliancelevel.Permissive, assert.True},
{"/packages/0/tools/0/name", compliancelevel.Specification, assert.True},
{"/packages/0/tools/0/name", compliancelevel.Strict, assert.True},
Expand Down Expand Up @@ -551,6 +577,10 @@ func TestType(t *testing.T) {
{"/packages/0/platforms/0/boards/0/name", 42, assert.True},
{"/packages/0/platforms/0/toolsDependencies", 42, assert.True},
{"/packages/0/platforms/0/toolsDependencies/0/packager", 42, assert.True},
{"/packages/0/platforms/0/toolsDependencies/0/version", 42, assert.True},
{"/packages/0/platforms/0/discoveryDependencies", 42, assert.True},
{"/packages/0/platforms/0/discoveryDependencies/0/packager", 42, assert.True},
{"/packages/0/platforms/0/discoveryDependencies/0/name", 42, assert.True},
{"/packages/0/tools", 42, assert.True},
{"/packages/0/tools/0/name", 42, assert.True},
{"/packages/0/tools/0/version", 42, assert.True},
Expand Down Expand Up @@ -678,6 +708,10 @@ func TestAdditionalProperties(t *testing.T) {
{"/packages/0/platforms/0/toolsDependencies/0", compliancelevel.Specification, assert.True},
{"/packages/0/platforms/0/toolsDependencies/0", compliancelevel.Strict, assert.True},

{"/packages/0/platforms/0/discoveryDependencies/0", compliancelevel.Permissive, assert.True},
{"/packages/0/platforms/0/discoveryDependencies/0", compliancelevel.Specification, assert.True},
{"/packages/0/platforms/0/discoveryDependencies/0", compliancelevel.Strict, assert.True},

{"/packages/0/tools/0", compliancelevel.Permissive, assert.True},
{"/packages/0/tools/0", compliancelevel.Specification, assert.True},
{"/packages/0/tools/0", compliancelevel.Strict, assert.True},
Expand Down
12 changes: 12 additions & 0 deletions internal/project/projectdata/packageindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func InitializeForPackageIndex() {
packageIndexPlatforms = nil
packageIndexBoards = nil
packageIndexToolsDependencies = nil
packageIndexDiscoveryDependencies = nil
packageIndexTools = nil
packageIndexSystems = nil
packageIndexSchemaValidationResult = nil
Expand All @@ -62,6 +63,10 @@ func InitializeForPackageIndex() {
packageIndexToolsDependencies = append(packageIndexToolsDependencies, getPackageIndexData(platformData.Object, platformData.JSONPointer, "toolsDependencies", platformData.ID, " - {{index . 0}}:{{index . 1}}@{{index . 2}}", []string{"packager", "name", "version"})...)
}

for _, platformData := range PackageIndexPlatforms() {
packageIndexDiscoveryDependencies = append(packageIndexDiscoveryDependencies, getPackageIndexData(platformData.Object, platformData.JSONPointer, "discoveryDependencies", platformData.ID, " - {{index . 0}}:{{index . 1}}", []string{"packager", "name"})...)
}

for _, packageData := range PackageIndexPackages() {
packageIndexTools = append(packageIndexTools, getPackageIndexData(packageData.Object, packageData.JSONPointer, "tools", packageData.ID, ":{{index . 0}}@{{index . 1}}", []string{"name", "version"})...)
}
Expand Down Expand Up @@ -123,6 +128,13 @@ func PackageIndexToolsDependencies() []PackageIndexData {
return packageIndexToolsDependencies
}

var packageIndexDiscoveryDependencies []PackageIndexData

// PackageIndexDiscoveryDependencies returns the slice of pluggable discovery tool dependency data for the package index.
func PackageIndexDiscoveryDependencies() []PackageIndexData {
return packageIndexDiscoveryDependencies
}

var packageIndexTools []PackageIndexData

// PackageIndexTools returns the slice of tool data for the package index.
Expand Down
Loading