1
0
mirror of https://github.com/arduino/library-registry.git synced 2025-05-19 08:13:41 +03:00

Add library type check to registry data file validator

There was previously no validation of this field.
This commit is contained in:
per1234 2021-07-23 14:12:14 -07:00
parent 42d55ca0d8
commit fd85f873f3
4 changed files with 29 additions and 0 deletions

View File

@ -43,8 +43,29 @@ func main() {
os.Exit(1)
}
validTypes := map[string]bool{
"Arduino": true,
"Contributed": true,
"Partner": true,
"Recommended": true,
"Retired": true,
}
nameMap := make(map[string]bool)
for _, entry := range rawRepos {
// Check entry types
if len(entry.Types) == 0 {
fmt.Fprintf(os.Stderr, "error: Type not specified for library \"%s\"\n", entry.LibraryName)
os.Exit(1)
}
for _, entryType := range entry.Types {
if _, valid := validTypes[entryType]; !valid {
fmt.Fprintf(os.Stderr, "error: Invalid type \"%s\" used by library \"%s\"\n", entryType, entry.LibraryName)
os.Exit(1)
}
}
// Check library name of the entry
if _, found := nameMap[entry.LibraryName]; found {
fmt.Fprintf(os.Stderr, "error: Registry data file contains duplicates of name %s\n", entry.LibraryName)
os.Exit(1)

View File

@ -30,6 +30,8 @@ test_data_path = pathlib.Path(__file__).resolve().parent.joinpath("testdata")
("nonexistent.txt", False),
("invalid-data-format.txt", False),
("invalid-url-format.txt", False),
("no-type.txt", False),
("invalid-type.txt", False),
("duplicate-url.txt", False),
("duplicate-name.txt", False),
("valid.txt", True),

View File

@ -0,0 +1,3 @@
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler
https://github.com/arduino-libraries/SD.git|foo|SD
https://github.com/arduino-libraries/Servo.git|Recommended|Servo

View File

@ -0,0 +1,3 @@
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler
https://github.com/arduino-libraries/SD.git||SD
https://github.com/arduino-libraries/Servo.git|Recommended|Servo