Skip to content

Commit b27cc87

Browse files
committed
Add tests for check IDs
- Undefined check ID - Incorrect check ID prefix - Duplicate check ID
1 parent 72f0edd commit b27cc87

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
"github.com/arduino/arduino-lint/check/checkconfigurations"
2424
"github.com/arduino/arduino-lint/check/checklevel"
2525
"github.com/arduino/arduino-lint/configuration/checkmode"
26+
"github.com/arduino/arduino-lint/project/projecttype"
2627
"github.com/stretchr/testify/assert"
28+
"github.com/stretchr/testify/require"
2729
)
2830

2931
func TestConfigurationResolution(t *testing.T) {
@@ -65,3 +67,31 @@ func checkModeConflict(configurations ...[]checkmode.Type) (bool, checkmode.Type
6567
}
6668
return false, checkmode.Default
6769
}
70+
71+
func TestIncorrectCheckIDPrefix(t *testing.T) {
72+
for checkIndex, checkConfiguration := range checkconfigurations.Configurations() {
73+
var IDPrefix byte
74+
switch checkConfiguration.ProjectType {
75+
case projecttype.Sketch:
76+
IDPrefix = 'S'
77+
case projecttype.Library:
78+
IDPrefix = 'L'
79+
case projecttype.Platform:
80+
IDPrefix = 'P'
81+
case projecttype.PackageIndex:
82+
IDPrefix = 'I'
83+
default:
84+
panic(fmt.Errorf("No prefix configured for project type %s", checkConfiguration.ProjectType))
85+
}
86+
require.NotEmptyf(t, checkConfiguration.ID, "No check ID defined for check configuration #%v", checkIndex)
87+
assert.Equalf(t, IDPrefix, checkConfiguration.ID[0], "Check ID %s has incorrect prefix for project type %s.", checkConfiguration.ID, checkConfiguration.ProjectType)
88+
}
89+
}
90+
91+
func TestDuplicateCheckID(t *testing.T) {
92+
checkIDMap := make(map[string]bool)
93+
for checkIndex, checkConfiguration := range checkconfigurations.Configurations() {
94+
checkIDMap[checkConfiguration.ID] = true
95+
require.Equalf(t, checkIndex+1, len(checkIDMap), "ID %s of check #%v is a duplicate", checkConfiguration.ID, checkIndex)
96+
}
97+
}

0 commit comments

Comments
 (0)