Skip to content

Commit 7ef6702

Browse files
committed
Add check for invalid package index format
1 parent b592a1f commit 7ef6702

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

check/checkconfigurations/checkconfigurations.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,4 +1166,19 @@ var configurations = []Type{
11661166
ErrorModes: []checkmode.Type{checkmode.Default},
11671167
CheckFunction: checkfunctions.PackageIndexJSONFormat,
11681168
},
1169+
{
1170+
ProjectType: projecttype.PackageIndex,
1171+
Category: "data",
1172+
Subcategory: "",
1173+
ID: "",
1174+
Brief: "Invalid format",
1175+
Description: "",
1176+
MessageTemplate: "Invalid package index format: {{.}}",
1177+
DisableModes: nil,
1178+
EnableModes: []checkmode.Type{checkmode.Default},
1179+
InfoModes: nil,
1180+
WarningModes: nil,
1181+
ErrorModes: []checkmode.Type{checkmode.Default},
1182+
CheckFunction: checkfunctions.PackageIndexFormat,
1183+
},
11691184
}

check/checkfunctions/packageindex.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ func PackageIndexJSONFormat() (result checkresult.Type, output string) {
3131
return checkresult.Fail, ""
3232
}
3333

34+
// PackageIndexFormat checks for invalid package index data format.
35+
func PackageIndexFormat() (result checkresult.Type, output string) {
36+
if checkdata.PackageIndexLoadError() != nil {
37+
return checkresult.Fail, checkdata.PackageIndexLoadError().Error()
38+
}
39+
40+
return checkresult.Pass, ""
41+
}

check/checkfunctions/packageindex_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,12 @@ func TestPackageIndexJSONFormat(t *testing.T) {
6969
checkPackageIndexCheckFunction(PackageIndexJSONFormat, testTables, t)
7070
}
7171

72+
func TestPackageIndexFormat(t *testing.T) {
73+
testTables := []packageIndexCheckFunctionTestTable{
74+
{"Invalid JSON", "invalid-JSON", checkresult.Fail, ""},
75+
{"Not valid package index", "invalid-package-index", checkresult.Fail, ""},
76+
{"Valid package index", "valid-package-index", checkresult.Pass, ""},
77+
}
78+
79+
checkPackageIndexCheckFunction(PackageIndexFormat, testTables, t)
80+
}

0 commit comments

Comments
 (0)