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:
parent
42d55ca0d8
commit
fd85f873f3
@ -43,8 +43,29 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validTypes := map[string]bool{
|
||||||
|
"Arduino": true,
|
||||||
|
"Contributed": true,
|
||||||
|
"Partner": true,
|
||||||
|
"Recommended": true,
|
||||||
|
"Retired": true,
|
||||||
|
}
|
||||||
|
|
||||||
nameMap := make(map[string]bool)
|
nameMap := make(map[string]bool)
|
||||||
for _, entry := range rawRepos {
|
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 {
|
if _, found := nameMap[entry.LibraryName]; found {
|
||||||
fmt.Fprintf(os.Stderr, "error: Registry data file contains duplicates of name %s\n", entry.LibraryName)
|
fmt.Fprintf(os.Stderr, "error: Registry data file contains duplicates of name %s\n", entry.LibraryName)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -30,6 +30,8 @@ test_data_path = pathlib.Path(__file__).resolve().parent.joinpath("testdata")
|
|||||||
("nonexistent.txt", False),
|
("nonexistent.txt", False),
|
||||||
("invalid-data-format.txt", False),
|
("invalid-data-format.txt", False),
|
||||||
("invalid-url-format.txt", False),
|
("invalid-url-format.txt", False),
|
||||||
|
("no-type.txt", False),
|
||||||
|
("invalid-type.txt", False),
|
||||||
("duplicate-url.txt", False),
|
("duplicate-url.txt", False),
|
||||||
("duplicate-name.txt", False),
|
("duplicate-name.txt", False),
|
||||||
("valid.txt", True),
|
("valid.txt", True),
|
||||||
|
3
.github/workflows/assets/validate-registry/tests/testdata/invalid-type.txt
vendored
Normal file
3
.github/workflows/assets/validate-registry/tests/testdata/invalid-type.txt
vendored
Normal 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
|
3
.github/workflows/assets/validate-registry/tests/testdata/no-type.txt
vendored
Normal file
3
.github/workflows/assets/validate-registry/tests/testdata/no-type.txt
vendored
Normal 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
|
Loading…
x
Reference in New Issue
Block a user