Skip to content

Commit 61a0d92

Browse files
Steve RamageSJrX
authored andcommitted
feat: add support for LogsDirectoryQuota=,StateDirectoryQuota=,CacheDirectoryQuota=
1 parent dc889ca commit 61a0d92

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/SimpleGrammarOptionValues.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ class SimpleGrammarOptionValues(validatorName: String, grammar: Combinator) : Gr
7474
FlexibleLiteralChoiceTerminal("~"),
7575
),
7676
EOF())),
77+
78+
Validator("config_parse_exec_quota", "0") to SimpleGrammarOptionValues("config_parse_exec_quota",
79+
SequenceCombinator(
80+
AlternativeCombinator(
81+
OptionalWhitespacePrefix(
82+
SequenceCombinator(IntegerTerminal(0, 4_294_967_296), OptionalWhitespacePrefix(FlexibleLiteralChoiceTerminal("K","M","G", "T"))
83+
)),
84+
SequenceCombinator(IntegerTerminal(0, 101), FlexibleLiteralChoiceTerminal("%")),
85+
OptionalWhitespacePrefix(IntegerTerminal(0, 4_294_967_296)),
86+
FlexibleLiteralChoiceTerminal("off"),
87+
),
88+
EOF()
89+
))
90+
7791
)
7892

7993
}

src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/inspections/InvalidValueInspectionForSimpleGrammarOptionValue.kt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,54 @@ class InvalidValueInspectionForSimpleGrammarOptionValue : AbstractUnitFileTest()
129129
assertSize(4, highlights)
130130
}
131131

132+
133+
fun testNoWarningWhenValidQuotasAreSet() {
134+
// Fixture Setup
135+
// language="unit file (systemd)"
136+
val file="""
137+
[Service]
138+
StateDirectoryQuota=1K
139+
StateDirectoryQuota=1 M
140+
StateDirectoryQuota=1T
141+
StateDirectoryQuota=1 G
142+
StateDirectoryQuota=0
143+
StateDirectoryQuota=4294967295
144+
StateDirecotryQuota=1%
145+
StateDirecotryQuota=off
146+
StateDirecotryQuota=100%
147+
StateDirecotryQuota=0%
148+
""".trimIndent()
149+
150+
// Execute SUT
151+
setupFileInEditor("file.service", file)
152+
enableInspection(InvalidValueInspection::class.java)
153+
val highlights = myFixture.doHighlighting()
154+
155+
// Verification
156+
assertSize(0, highlights)
157+
}
158+
159+
fun testWarningWhenInvalidQuotasAreSet() {
160+
// Fixture Setup
161+
// language="unit file (systemd)"
162+
val file="""
163+
[Service]
164+
StateDirectoryQuota=1P
165+
StateDirectoryQuota=-1
166+
StateDirectoryQuota=on
167+
StateDirectoryQuota=allo
168+
StateDirectoryQuota=4294967296
169+
StateDirectoryQuota=500%
170+
StateDirectoryQuota=5.52%
171+
""".trimIndent()
172+
173+
// Execute SUT
174+
setupFileInEditor("file.service", file)
175+
enableInspection(InvalidValueInspection::class.java)
176+
val highlights = myFixture.doHighlighting()
177+
178+
// Verification
179+
assertSize(7, highlights)
180+
}
181+
132182
}

src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/OptionValueTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class OptionValueTest : AbstractUnitFileTest() {
1616
val missingValidators = hashMapOf<Validator, Int>()
1717
var totalMissingValidators = 0
1818
var totalFoundValidators = 0
19+
val foundValidators = mutableSetOf<Validator>()
1920
for (fileClass in FileClass.entries) {
2021
for (sectionName in SemanticDataRepository.instance.getSectionNamesForFile(fileClass.fileClass)) {
2122
for (key in SemanticDataRepository.instance.getAllowedKeywordsInSectionFromValidators(fileClass, sectionName)) {
@@ -26,6 +27,7 @@ class OptionValueTest : AbstractUnitFileTest() {
2627
missingValidators[validator] = (missingValidators[validator] ?: 0) + 1
2728
totalMissingValidators++
2829
} else {
30+
foundValidators.add(validator)
2931
totalFoundValidators++
3032
}
3133
}
@@ -36,17 +38,18 @@ class OptionValueTest : AbstractUnitFileTest() {
3638
val sortedList = missingValidatorList.sortedDescending().joinToString("\n")
3739

3840
println("Missing:$totalMissingValidators")
41+
println("Missing Functions:${missingValidators.size}")
3942
println("Found:$totalFoundValidators")
4043

41-
val startDate = LocalDate.of(2025, 7, 12) // Today's date
42-
val startingCount = 1183 // Your current undocumented options count
44+
val startDate = LocalDate.of(2025, 7, 27) // Today's date
45+
val startingCount = 612 // Your current undocumented options count
4346
val currentDate = LocalDate.now()
4447
val daysSinceStart = ChronoUnit.DAYS.between(startDate, currentDate)
45-
val reductionPerDay = 4
48+
val reductionPerDay = 1
4649
val allowed = maxOf(0, startingCount - (daysSinceStart * reductionPerDay))
4750

48-
if (totalMissingValidators >= allowed) {
49-
assertEquals("Number of missing validators is too high at ${totalMissingValidators} > $allowed vs. found ${totalFoundValidators}", sortedList, "")
51+
if (missingValidators.size >= allowed) {
52+
assertEquals("Number of missing functions is too high at ${missingValidators.size} > $allowed vs. found ${foundValidators.size} ${totalFoundValidators}", sortedList, "")
5053
}
5154

5255
if (totalFoundValidators == 0) {

0 commit comments

Comments
 (0)