Skip to content

Commit 591e38f

Browse files
author
Steve Ramage
committed
Checkpoint #290 - All tests passing
1 parent 58562c2 commit 591e38f

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/annotators/InvalidSectionHeaderNameAnnotatorTest.kt

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,92 @@ class InvalidSectionHeaderNameAnnotatorTest : AbstractUnitFileTest() {
380380
}
381381

382382

383+
fun testNSpawnSectionsInNSpawnFileHasNoWarnings() {
384+
/*
385+
* Fixture Setup
386+
*/
387+
//language=unit file (systemd)
388+
val file = """
389+
[Exec]
390+
391+
[Files]
392+
393+
[Network]
394+
""".trimIndent()
395+
396+
/*
397+
* Exercise SUT
398+
*/
399+
setupFileInEditor("file.nspawn", file)
400+
val highlights = myFixture.doHighlighting()
401+
402+
/*
403+
* Verification
404+
*/
405+
assertSize(0, highlights)
406+
}
407+
408+
fun testNSpawnSectionsInServiceFileHasWarnings() {
409+
/*
410+
* Fixture Setup
411+
*/
412+
//language=unit file (systemd)
413+
val file = """
414+
[Exec]
415+
416+
[Files]
417+
418+
[Network]
419+
""".trimIndent()
420+
421+
/*
422+
* Exercise SUT
423+
*/
424+
setupFileInEditor("file.service", file)
425+
val highlights = myFixture.doHighlighting()
426+
427+
/*
428+
* Verification
429+
*/
430+
assertSize(3, highlights)
431+
432+
val highlightTexts = highlights.map { it.description }
433+
434+
assertContainsElements(highlightTexts, "The section Exec is not allowed in Service files, only the following are allowed: [Unit, Install, Service]")
435+
assertContainsElements(highlightTexts, "The section Files is not allowed in Service files, only the following are allowed: [Unit, Install, Service]")
436+
assertContainsElements(highlightTexts, "The section Network is not allowed in Service files, only the following are allowed: [Unit, Install, Service]")
437+
}
438+
439+
fun testServiceSectionsInNSpawnFileHasWarnings() {
440+
/*
441+
* Fixture Setup
442+
*/
443+
//language=unit file (systemd)
444+
val file = """
445+
[Unit]
446+
447+
[Install]
448+
449+
[Service]
450+
""".trimIndent()
451+
452+
/*
453+
* Exercise SUT
454+
*/
455+
setupFileInEditor("file.nspawn", file)
456+
val highlights = myFixture.doHighlighting()
457+
458+
/*
459+
* Verification
460+
*/
461+
assertSize(3, highlights)
462+
463+
val highlightTexts = highlights.map { it.description }
464+
465+
assertContainsElements(highlightTexts, "The section Unit is not allowed in Nspawn files, only the following are allowed: [Exec, Files, Network]")
466+
assertContainsElements(highlightTexts, "The section Install is not allowed in Nspawn files, only the following are allowed: [Exec, Files, Network]")
467+
assertContainsElements(highlightTexts, "The section Service is not allowed in Nspawn files, only the following are allowed: [Exec, Files, Network]")
468+
}
469+
383470
}
471+

src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/completion/UnitFileKeyCompletionContributorTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,21 @@ class UnitFileKeyCompletionContributorTest : AbstractUnitFileTest() {
145145
// Verification
146146
assertContainsElements(completions, "DirectoryMode", "DirectoryNotEmpty", "MakeDirectory", "PathModified")
147147
}
148+
149+
fun testCompletionForNSpawnFileInFilesSectionReturnsExpectedValues() {
150+
// Fixture Setup
151+
val file = """
152+
[Files]
153+
Bi$COMPLETION_POSITION
154+
Inaccessible=True
155+
""".trimIndent()
156+
myFixture.configureByText("file.nspawn", file)
157+
158+
// Exercise SUT
159+
val completions = basicCompletionResultStrings
160+
161+
// Verification
162+
assertContainsElements(completions, "Bind", "BindReadOnly", "BindUser")
163+
}
164+
148165
}

src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/completion/UnitFileSectionCompletionContributorTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ class UnitFileSectionCompletionContributorTest : AbstractUnitFileTest() {
121121
assertContainsElements(completions, "Install", "Unit", "Timer")
122122
}
123123

124+
fun testCompletionOfNewSectionHeaderReturnsExpectedValuesInNSpawn() {
125+
// Fixture Setup
126+
val file = """
127+
[Files]
128+
Whatevs=Foo
129+
130+
[$COMPLETION_POSITION
131+
""".trimIndent()
132+
myFixture.configureByText("file.nspawn", file)
133+
val completions = basicCompletionResultStrings
134+
assertContainsElements(completions, "Exec", "Files", "Network")
135+
}
136+
124137
fun testCompletionOfNewSectionInUnknownFileTypeIsEmpty() {
125138
// Fixture Setup
126139
val file = """

src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/completion/UnitFileValueCompletionContributorTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,20 @@ class UnitFileValueCompletionContributorTest : AbstractUnitFileTest() {
126126
// Verification
127127
assertContainsElements(completions, "NetworkManager.service")
128128
}
129+
130+
fun testCompletionOfBooleanOptionReturnsValuesInNspawnFile() {
131+
// Fixture Setup
132+
val file = """
133+
[Network]
134+
Private=$COMPLETION_POSITION
135+
136+
""".trimIndent()
137+
myFixture.configureByText("file.nspawn", file)
138+
139+
// Execute SUT
140+
val completions = basicCompletionResultStrings
141+
142+
// Verification
143+
assertContainsElements(completions, "on", "off", "true", "false", "yes", "no")
144+
}
129145
}

0 commit comments

Comments
 (0)